swagger-maven-plugin icon indicating copy to clipboard operation
swagger-maven-plugin copied to clipboard

Swagger Version 2.0.X annotations are not supported

Open choesang opened this issue 7 years ago • 9 comments

I am using the following versions of swagger and swagger-maven-plugin. You can see below my configuration and the swagger.json file. It is clearly missing many of the fields defined in the annotation.

Is it possible that the current version of the maven plugin does not support Version 2? Is there any plans to support them in the future?

swagger-maven-plugin 3.1.7 swagger-core 2.0.2

pom.xml

<dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-core</artifactId>
            <scope>compile</scope>
            <version>2.0.2</version>
 </dependency>

<profile>
            <id>apidoc</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.kongchen</groupId>
                        <artifactId>swagger-maven-plugin</artifactId>
                        <version>3.1.7</version>
                        <configuration>
                            <apiSources>
                                <apiSource>
                                    <info>
                                        <title>x API</title>
                                        <version>${project.version}</version>
                                        <description>
                                            Here you will find all the endpoints provided by the platform and
                                            how to interact with them.
                                        </description>
                                        <contact>
                                            <name>Choesang</name>
                                            <email>[email protected]</email>
                                            <url>http://www.x.com</url>
                                        </contact>
                                    </info>
                                    <schemes>
                                        <scheme>http</scheme>
                                        <scheme>https</scheme>
                                    </schemes>
                                    <locations>com.x.platform.api</locations>
                                    <host>localhost:8080</host>
                                    <basePath>/platform-web/api</basePath>
                                    <templatePath>${basedir}/src/main/resources/swagger/strapdown.html.hbs
                                    </templatePath>
                                    <outputPath>${project.build.directory}/apidocs/strapdown.html</outputPath>
                                    <swaggerDirectory>${project.build.directory}/apidocs</swaggerDirectory>
                                </apiSource>
                            </apiSources>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>install</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <activation>
                <property>
                    <name>!no-swagger</name>
                </property>
            </activation>
        </profile>

Resource class

   @POST
    @Path("/{id}/stop")
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(summary = "Stop job with given id", responses = {
        @ApiResponse(responseCode = "202", description = "Successfully stopped the job"),
        @ApiResponse(responseCode = "500", description = "Internal messaging error"),
        @ApiResponse(responseCode = "404", description = "Job could not be found,Job-Id")
    })
    public Response stopJob(@Context final UriInfo uriInfo,
     @Parameter(description = "jobId", required = true) @PathParam("id") final String jobId) {
        return Response.accepted().location(uriInfo.getRequestUri()).build();
    }

swagger.json

"/jobs/{id}/stop" : {
      "post" : {
        "operationId" : "stopJob",
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "id",
          "in" : "path",
          "required" : true,
          "type" : "string"
        } ],
        "responses" : {
          "default" : {
            "description" : "successful operation"
          }
        }
      }
    }

choesang avatar Aug 07 '18 12:08 choesang

I just saw that the current swagger-maven-plugin is built on swagger 1.5.18. Are there any plans to support the latest swagger 2.0.x ?

choesang avatar Aug 07 '18 12:08 choesang

Yeah, this would be great to have for us as well! :)

florian-trimble avatar Aug 13 '18 08:08 florian-trimble

Hello, try to have a look at swagger-maven-plugin

According to the description

provides a maven plugin to resolve an OpenAPI definition at build time (using swagger-jaxrs2).

Update: I have tried right now and it works, I can then display the json in the swagger-ui as well, I am using

<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.0.6</version>

blackat avatar Jan 08 '19 16:01 blackat

Small remark, please note that

<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.7</version>

This plugin is not the one implemented along with the swagger version 2.0.X, check please the groupId tag.

blackat avatar Jan 14 '19 09:01 blackat

@blackat I am using Spring REST(not JAX-RS) and trying to generate the OPEN API 3.0 YAML specification file. The swagger-maven-plugin under groupId io.swagger.core.v3 works well for generating the OPEN API definitions, but not reading Operations and Paths annotation as it's not JAX-RS? Is there a workaround to generate OPENAPI 3.0 spec file instead of Swagger 2.0 spec file using com.github.kongchen swagger-maven-plugin?

devutkarsh avatar Feb 28 '19 11:02 devutkarsh

@devutkarsh It doesn't look like OpenAPI 3.0 is supported yet. Check out https://github.com/kongchen/swagger-maven-plugin/issues/550.

nashley avatar May 13 '19 19:05 nashley

Is there any alternative? since we upgraded our swagger deps, the specs generated are now not working anymore. Operations missing....

ataraxus avatar May 11 '20 13:05 ataraxus

After experimenting, I found swagger-maven-plugin this plugin is useful as of now as a replacement.

I hope this helps.

priyansh490 avatar Dec 13 '22 17:12 priyansh490

If you're looking for OpenAPI 3.x support, see: https://github.com/kongchen/swagger-maven-plugin/issues/550#issuecomment-2025847025

marcogrcr avatar Mar 28 '24 18:03 marcogrcr