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
761 stars 450 forks source link

Can't find swagger.json, is anything happening? #600

Closed aniketsp closed 6 years ago

aniketsp commented 6 years ago

Hi. I don't know what I am doing wrong. We had previously used swagger-core on our Jersey JAX-RS project to generate swagger.json. It impacted our performance and then we found your project which would generate the swagger.json only during compile time and not run time. So I tried to transition to your project. I hope I am understanding this correct. I left web.xml as it was during swagger-core configuration and the maven dependency as well, but added the plugin to the same build like so: pom.xml

    <profile>
        <id>daily</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <resources.directory>${basedir}/src/daily/resources
            </resources.directory>
            <resources.test.directory>${basedir}/src/test/daily/resources
            </resources.test.directory>
            <config.directory>${basedir}/src/daily/config</config.directory>
            <env.base.dir>${project.build.directory}/etc</env.base.dir>
        </properties>
        <dependencies>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-jersey-jaxrs</artifactId>
                <version>1.5.0</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>com.github.kongchen</groupId>
                        <artifactId>swagger-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <configuration>
                            <apiSources>
                                <apiSource>
                                    <springmvc>false</springmvc>
                                    <locations>
                                        <location>api.resource</location>
                                        <location>api.model.datagov</location>
                                        <location>api.model.eventitem</location>
                                        <location>api.model.item</location>
                                    </locations>
                                    <schemes><scheme>http</scheme></schemes>
                                    <basePath>/itemapi</basePath>
                                    <info>
                                        <title>ItemAPI</title>
                                        <version>0.0.1-SNAPSHOT</version>
                                    </info>
                                    <outputPath>${basedir}/src/main/webapp/output.html</outputPath>
                                    <swaggerDirectory>${basedir}/src/main/webapp/dist</swaggerDirectory>
                                    <attachSwaggerArtifact>true</attachSwaggerArtifact>
                                </apiSource>
                            </apiSources>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
            <resources>
                <resource>
                    <directory>${basedir}/src/daily/resources</directory>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                </resource>
            </resources>
            <testResources>
                <testResource>
                    <directory>${basedir}/src/test/daily/resources</directory>
                </testResource>
                <testResource>
                    <directory>${basedir}/src/test/resources</directory>
                </testResource>
            </testResources>
        </build>
    </profile>

I had to add the plugins management because the execution was giving an error. BTW I am doing all of this in eclipse.

This is the swagger configuration in web.xml in case its helpful:

    <servlet>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>
        io.swagger.jaxrs.listing;
        io.swagger.jaxrs.json;
        org.codehaus.jackson.jaxrs;
        api.resource
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/itemapi/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>Jersey2Config</servlet-name>
    <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
    <init-param>
        <param-name>api.version</param-name>
        <param-value>0.0.1-SNAPSHOT</param-value>
    </init-param>
    <init-param>
        <param-name>swagger.api.title</param-name>
        <param-value>ItemApi</param-value>
    </init-param>
    <init-param>
        <param-name>swagger.api.basepath</param-name>
        <param-value>/itemapi/</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

Now, I am right clicking on the project and selecting maven -> build -> clean install and it builds successfully but under the 'webapp' folder I don't see any output.html or in the 'dist' folder no swagger.json. I even tried through cmd going to the git project and then running mvn compile. Same. Build success but really nothing happens. What am I doing wrong?

AnEmortalKid commented 6 years ago

Can you try:

I don’t think the plugin management section actually makes plugins run, it only defines common configuration. So you’d need to have the execution block in a plugin section outside of plugin management.

aniketsp commented 6 years ago

Hi thanks for your reply. I solved the issue. You are right. It was the tag. Without it Eclipse would show some error on the execution tag. The way to go was to go into preferences and turn off the error rather than add this tag. Thank you so much for your help.

AnEmortalKid commented 6 years ago

@aniketsp mind closing this issue if it for sure was resolved?

samarthpatil619 commented 2 years ago

hii aniketsp
I am still getting this error what have u done to solve this one . Error. Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.0:generate (default) : null: MojoExecutionException: NullPointerException -> [Help 1]

Please help.