Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Aug 17, 2020 · 1 comment

Comments

@stoyo
Copy link

stoyo commented Aug 17, 2020

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: #782 mentions the exact same problem, however, it has been closed without any explanation or comment from anyone.

gdimitrov7 pushed a commit to gdimitrov7/swagger-maven-plugin that referenced this issue Mar 10, 2021
In some cases the method will be excluded from the swagger (because it
misses httpMethod or Api annotation), but the return type of the method
is added to the definitions as parseMethod() had side effect and
modified the swagger.model object.

Removed the side effect of parseMethod().
@gdimitrov7
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants