swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.08k stars 6.03k forks source link

Add JAVA_OPTS to swagger-generator scripts #10139

Open Pe-te opened 4 years ago

Pe-te commented 4 years ago

We would like to pass some options to the java executor to reduce logging output:

export JAVA_OPTS="${JAVA_OPTS} -Dlog.level=warn --illegal-access=warn"

In the OpenApi generator for example this is done by setting JAVA_OPTS and then calling the script:

> cat $(which openapi-generator)
#!/bin/bash
exec "/usr/local/opt/openjdk/bin/java" $JAVA_OPTS -jar "/usr/local/Cellar/openapi-generator/4.2.3_1/libexec/openapi-generator-cli.jar" "$@"

In swagger-codegen those JAVA_OPTS are ignored:

> cat $(which swagger-codegen)
#!/bin/bash
exec java -jar /usr/local/Cellar/swagger-codegen/3.0.18/libexec/swagger-codegen-cli.jar "$@"

Seems to work when I modify the script and add the options:

/> cat $(which swagger-codegen)
#!/bin/bash
exec java $JAVA_OPTS -jar /usr/local/Cellar/swagger-codegen/3.0.18/libexec/swagger-codegen-cli.jar "$@"

macOS, homebrew, swagger-codegen version 3.0.18

I don't see any discussion about the issue, would it be okay to just add the parameter?

DanielKalmann commented 4 years ago

The amount of logging which is currently generated is absurd. Any update on this?

Pe-te commented 4 years ago

@DanielKalmann Does it work for you when you hack the JAVA_OPTS into the shell script? I tried finding the corresponding file in this repo to add a pull request, but no luck. If someone knows where to find it, feel free to add it.

file: swagger-codegen old line: exec java -jar /usr/local/Cellar/swagger-codegen/3.0.18/libexec/swagger-codegen-cli.jar "$@" new line: exec java $JAVA_OPTS -jar /usr/local/Cellar/swagger-codegen/3.0.18/libexec/swagger-codegen-cli.jar "$@"

DanielKalmann commented 4 years ago

Doesn't seem to work for me.

Otiel commented 4 years ago

Does it work for you when you hack the JAVA_OPTS into the shell script?

What shell script?

Pe-te commented 4 years ago

What shell script?

The one that is used when you use swagger-codegen, you can find it like this: which swagger-codegen

black-snow commented 4 years ago

Why does it even output DEBUG level by default?

PayBas commented 1 year ago

My workaround to reduce logging is this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
            <configuration>
                <properties>
                    <property>
                        <name>org.slf4j.simpleLogger.log.io.swagger.codegen.v3.AbstractGenerator</name>
                        <value>warn</value>
                    </property>
                    <property>
                        <name>org.slf4j.simpleLogger.log.io.swagger.codegen.v3.generators.DefaultCodegenConfig</name>
                        <value>error</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

The exact property names to use will depend on your situation. You can identify which classes are producing your spam by using -Dorg.slf4j.simpleLogger.showLogName and prepending them with org.slf4j.simpleLogger.log.