kongchen / swagger-maven-plugin

JAX-RS & SpringMVC supported maven build plugin, helps you generate Swagger JSON and API document in build phase.
http://kongchen.github.io/swagger-maven-plugin/
Apache License 2.0
759 stars 448 forks source link

Upgrading from 3.1.5 to 3.1.8 (without changing annotations in any way) results in addition of some java core classes to the models section #832

Open stoyo opened 3 years ago

stoyo commented 3 years ago

Bump of swagger-maven-plugin from 3.1.5 to 3.1.8 is not backward compatible.

All annotations in my web service look like this:

@POST
@Path("/")
@Produces({ PRODUCES_JSON_1, PRODUCES_JSON_2 })
@ApiOperation(nickname = "createFoo",
        value = "Create foo",
        notes = "Create foo",
        response = FooTracker.class,
        code = 202)
@ApiResponses(
        value = {
                @ApiResponse(code = 400, message = "Invalid Request - bad data"),
                @ApiResponse(code = 403, message = "Forbidden")
        })
@ApiImplicitParams({
        @ApiImplicitParam(name = Constants.Versions.VERSION_PARAM,
            value = Constants.Documentation.API_VERSION_PARAM_DESCRIPTION,
            dataType = "string",
            paramType = "query")
        })
@SupportedSince(Constants.Versions.TANGO_IA_VERSION)

None of the provided response classes (i.g. FooTracker in the example above) include in any way CompletableFuture or Thread class, however, in swagger models section, after bump, I started seeing:

CompletableFutureObject
CompletableFutureOperation
CompletableFuture
Thread
ThreadGroup
etc...
<plugin>
    <groupId>com.github.kongchen</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    <version>3.1.8</version>
    <configuration>
        <apiSources>
            <apiSource>
                <springmvc>false</springmvc>
                <schemes>https</schemes>
                <locations>org.fmi.service.multicloud</locations>
                <schemes>https</schemes>
                <host></host>
                <basePath>/</basePath>
                <info>
                    <title>FMI API</title>
                    <version>06-2020</version>
                </info>
                <swaggerDirectory>${project.build.outputDirectory}</swaggerDirectory>
                <swaggerFileName>swagger-multicloud</swaggerFileName>
                <templatePath>${basedir}/src/main/resources/templates/strapdown.html.hbs</templatePath>
                <outputPath>${project.build.directory}/swagger/FMI-API.html</outputPath>
                <outputFormats>json,yaml</outputFormats>
            </apiSource>
        </apiSources>
    </configuration>
    <executions>
        <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I saw that this issue: https://github.com/kongchen/swagger-maven-plugin/issues/782 mentions the exact same problem, however, it has been closed without any explanation or comment from anyone.

gdimitrov7 commented 3 years ago

The issue is with classes that have extra methods (in same or in parent class), that will be excluded from the swagger - because they do not have @Path, @Api nor @PostMapping. Even if they are ignored from the operations, their model is added to the definitions.

In the next example the produced swagger contains #/definitions/SQLException even if it is not used from the operations or from other definition:

    // this static method and return type should not be included in the swagger as there is no Path nor Api
    public static SQLException getCauseSQLException(Throwable e) {
        return null;
    }

The change happened between 3.1.5 and 3.1.6 as part of some fix for JAX-RS. Previously the extra definitions were not included in the resulting swagger.

I prepared a fix that returns the previously behaviour - hope it gets merged soon as it prevents upgrading to newer version of swagger-maven-plugin in our project.