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 449 forks source link

Swagger Version 2.0.X annotations are not supported #655

Open choesang opened 5 years ago

choesang commented 5 years ago

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>choesang@x.com</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 commented 5 years ago

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 ?

florian-trimble commented 5 years ago

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

blackat commented 5 years ago

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 commented 5 years ago

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.

devutkarsh commented 5 years ago

@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?

nashley commented 5 years ago

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

ataraxus commented 4 years ago

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

priyansh490 commented 1 year ago

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

I hope this helps.

marcogrcr commented 3 months ago

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