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

Apmoust empty swagger.json with swagger-maven-plugin-3.1.1-SNAPSHOT #9

Open
Chort409 opened this issue Jul 24, 2015 · 7 comments
Open

Comments

@Chort409
Copy link

Updated the project to use swagger-maven-plugin-3.1.1-SNAPSHOT, since 3.0.1-SNAPSHOT cannot be found and all I got under swager.json is :
{
"swagger" : "2.0",
"info" : {
"description" : "This is a sample for swagger-maven-plugin",
"version" : "v1",
"title" : "Swagger Maven Plugin Sample",
"termsOfService" : "http://www.github.com/kongchen/swagger-maven-plugin",
"contact" : {
"name" : "Kong Chen",
"url" : "http://kongch.com",
"email" : "[email protected]"
},
"license" : {
"name" : "Apache 2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host" : "petstore.swagger.wordnik.com",
"basePath" : "/api",
"schemes" : [ "http", "https" ]
}

@Chort409
Copy link
Author

It looks like the problem is not with the project but with swagger-maven-plugin. Downgraded its version to 3.0-M2-SNAPSHOT generated proper annotation

@vidhya03
Copy link

Yes same for me i tried 3.1.0 , after downgraded to 3.0-M2-SNAPSHOT it is generated. I want to use latest 3.1.0 . In that case what should i do.?

@who
Copy link

who commented Aug 21, 2015

@Vidhyadharantechdays @Chort409 I have upgraded the example project to work with swagger-maven-plugin 3.1.0.

You may view it here: https://github.com/swagger-maven-plugin/swagger-maven-example

@vidhya03
Copy link

Verified it is working THanks @who Andrew

@trim09
Copy link

trim09 commented Jun 5, 2017

This seems to be a fixed here: #14
I faced the same issue which was solved by applying the fix from mentioned pull request

@trungdoviet
Copy link

trungdoviet commented Sep 2, 2017

Thanks @who
With your link, it work (https://github.com/swagger-maven-plugin/swagger-maven-example)

I can summarize what have you changed on this new project.

1. update pom file:

  • use plugin swagger-maven-plugin with release version (you use 3.1.1 and i even can use 3.1.5).
  • In dependency section, change groupId of swagger-core from com.wordnik to io.swagger (use the original one)
  • Define security definition in apiSource like this:
<securityDefinitions>
                                <securityDefinition>
                                    <json>/securityDefinitions.json</json>
                                </securityDefinition>
                            </securityDefinitions> 

put file securityDefinitions.json to main/resources folder

2. Change import in source code: Scan all classes and change import from

com.wordnik.swagger.annotations.*; to io.swagger.annotations.*; AND com.wordnik.swagger.annotations.ApiResponse; to io.swagger.annotations.ApiResponse;
I see we need to change for package xxx.resource and xxx.model
You would see some incompatibilities from new import, so just fix following what maven tell you (ex: remove type attribute from annotation of apis (it's already declared on securityDefinition.json)

Do following those steps then i can make the original example run perfectly.
it also fix this one #16

Here is my new pom.xml

<xml version="1.0" encoding="UTF-8"? >
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>swagger-maven-example</groupId>
    <artifactId>swagger-maven-example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>com.github.kongchen</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>3.1.5</version>
                <configuration>
                    <apiSources>
                      <apiSource>
                            <springmvc>false</springmvc>
                            <locations>com.github.kongchen.swagger.sample.wordnik.resource</locations>
                            <schemes>http,https</schemes>
                            <host>petstore.swagger.wordnik.com</host>
                            <basePath>/api</basePath>
                            <info>
                                <title>Swagger Maven Plugin Sample</title>
                                <version>v1</version>
                                <description>This is a sample for swagger-maven-plugin</description>
                                <termsOfService>
                                    http://www.github.com/kongchen/swagger-maven-plugin
                                </termsOfService>
                                <contact>
                                    <email>[email protected]</email>
                                    <name>Kong Chen</name>
                                    <url>http://kongch.com</url>
                                </contact>
                                <license>
                                    <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
                                    <name>Apache 2.0</name>
                                </license>
                            </info>
                            <!-- Support classpath or file absolute path here.
                            1) classpath e.g: "classpath:/markdown.hbs", "classpath:/templates/hello.html"
                            2) file e.g: "${basedir}/src/main/resources/markdown.hbs",
                                "${basedir}/src/main/resources/template/hello.html" -->
                            <templatePath>${basedir}/templates/strapdown.html.hbs</templatePath>
                            <outputPath>${basedir}/generated/document.html</outputPath>
                            <swaggerDirectory>generated/swagger-ui</swaggerDirectory>
							 <securityDefinitions>
                                <securityDefinition>
                                    <json>/securityDefinitions.json</json>
                                </securityDefinition>
                            </securityDefinitions>
                        </apiSource>
                    </apiSources>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-core</artifactId>
            <scope>compile</scope>
            <version>1.5.3</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.ws.rs</groupId>
                    <artifactId>jsr311-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback-version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback-version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey2-version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey2-version}</version>
        </dependency>
    </dependencies>
    <properties>
        <jetty-version>9.0.7.v20131107</jetty-version>
        <jersey2-version>2.4.1</jersey2-version>
        <logback-version>1.0.1</logback-version>
    </properties>
    <pluginRepositories>
        <pluginRepository>
            <id>sonatype-snapshot</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

Thanks a lot

@LuVsLu
Copy link

LuVsLu commented Oct 15, 2018

I have the same problems,my swagger-maven-plugin version is 1.3.5 , and I add the "method = RequestMethod.POST" on the annotation @RequestMapping, then it worked!

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

6 participants