swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

Unable to generate API definitions for spring using OpenApi 3.0 spec #8256

Open stiwari99 opened 6 years ago

stiwari99 commented 6 years ago
Description

Unable to generate API definitions for spring using OpenApi 3.0 spec

Swagger-codegen version

3.0

Swagger declaration file content or url
Command line used for generation
Steps to reproduce

Here are contents of my pom file

Pom.xml
   `<plugin>
       <groupId>io.swagger</groupId>
       <artifactId>swagger-codegen-maven-plugin</artifactId>
       <version>3.0.0-rc0</version>
       <executions>
          <execution>
             <goals>
                <goal>generate</goal>
             </goals>
             <configuration>
                <environmentVariables>
                   <models />
                </environmentVariables>
                <inputSpec>${project.basedir}/src/main/resources/user-service.yaml</inputSpec>
                <language>spring</language>
                <output>${project.build.directory}/generated-sources/openapi</output>
                <modelPackage>com.example.userservice.generated.openapi.model</modelPackage>
                <apiPackage>com.example.userservice.generated.openapi.api</apiPackage>
                <configOptions>
                   <interfaceOnly>true</interfaceOnly>
                   <skipOverwrite>true</skipOverwrite>
                </configOptions>
             </configuration>
          </execution>
       </executions>
       <dependencies>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-generators</artifactId>
                <version>1.0.0-rc1</version>
            </dependency>
        </dependencies>
    </plugin>`
Yaml file used

https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

mvn clean install

[INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.example:user-service:jar:0.0.1-SNAPSHOT [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-web:jar -> duplicate declaration of version (?) @ line 54, column 23 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] [INFO] -----------------------< com.example:user-service >----------------------- [INFO] Building user-service 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [WARNING] The POM for org.apache.httpcomponents:httpcore:jar:4.4.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details [INFO] [INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ user-service --- [INFO] Deleting /home/test/project/example/user-service/target [INFO] [INFO] --- swagger-codegen-maven-plugin:3.0.0-rc1:generate (default) @ user-service --- Downloading from central: https://repo.maven.apache.org/maven2/io/swagger/swagger-models/1.5.19/swagger-models-1.5.19.jar Downloading from central: https://repo.maven.apache.org/maven2/io/swagger/swagger-annotations/1.5.19/swagger-annotations-1.5.19.jar Downloaded from central: https://repo.maven.apache.org/maven2/io/swagger/swagger-annotations/1.5.19/swagger-annotations-1.5.19.jar (22 kB at 70 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/io/swagger/swagger-models/1.5.19/swagger-models-1.5.19.jar (151 kB at 327 kB/s) [WARNING] Output directory does not exist, or is inaccessible. No file (.swagger-codegen-ignore) will be evaluated. [INFO] Invoker Package Name, originally not set, is now dervied from api package name: com.example.userservice.generated.openapi [WARNING] String to be sanitized is null. Default to Object [WARNING] String to be sanitized is null. Default to Object [INFO] writing file /home/test/project/example/user-service/target/generated-sources/openapi/src/main/java/com/example/userservice/generated/openapi/model/Error.java [INFO] writing file /home/test/project/example/user-service/target/generated-sources/openapi/src/main/java/com/example/userservice/generated/openapi/model/Pet.java [INFO] writing file /home/test/project/example/user-service/target/generated-sources/openapi/src/main/java/com/example/userservice/generated/openapi/model/Pets.java [ERROR] java.lang.RuntimeException: Could not generate api file for 'pets' at io.swagger.codegen.DefaultGenerator.generateApis (DefaultGenerator.java:527) at io.swagger.codegen.DefaultGenerator.generate (DefaultGenerator.java:731) at io.swagger.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:534) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: com.github.jknack.handlebars.HandlebarsException: /v2/JavaSpring/api.mustache💯54: java.lang.ClassCastException: java.util.HashMap cannot be cast to io.swagger.codegen.VendorExtendable /v2/JavaSpring/api.mustache💯54 at io.swagger.codegen.handlebars.helpers.ExtensionHelper.apply (ExtensionHelper.java:11) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.helper.EachHelper.apply (EachHelper.java:72) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.Options.fn (Options.java:433) at io.swagger.codegen.handlebars.helpers.ExtensionHelper.apply (ExtensionHelper.java:29) at io.swagger.codegen.handlebars.helpers.ExtensionHelper.apply (ExtensionHelper.java:11) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.Options.fn (Options.java:433) at com.github.jknack.handlebars.helper.UnlessHelper.apply (UnlessHelper.java:50) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.helper.EachHelper.apply (EachHelper.java:72) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.Options.fn (Options.java:445) at com.github.jknack.handlebars.helper.WithHelper.apply (WithHelper.java:58) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.internal.ForwardingTemplate.apply (ForwardingTemplate.java:72) at io.swagger.codegen.DefaultGenerator.processTemplateToFile (DefaultGenerator.java:745) at io.swagger.codegen.DefaultGenerator.generateApis (DefaultGenerator.java:486) at io.swagger.codegen.DefaultGenerator.generate (DefaultGenerator.java:731) at io.swagger.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:534) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to io.swagger.codegen.VendorExtendable at io.swagger.codegen.handlebars.helpers.ExtensionHelper.apply (ExtensionHelper.java:11) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.helper.EachHelper.apply (EachHelper.java:72) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.Options.fn (Options.java:433) at io.swagger.codegen.handlebars.helpers.ExtensionHelper.apply (ExtensionHelper.java:29) at io.swagger.codegen.handlebars.helpers.ExtensionHelper.apply (ExtensionHelper.java:11) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.Options.fn (Options.java:433) at com.github.jknack.handlebars.helper.UnlessHelper.apply (UnlessHelper.java:50) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.helper.EachHelper.apply (EachHelper.java:72) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.Options.apply (Options.java:538) at com.github.jknack.handlebars.Options.fn (Options.java:445) at com.github.jknack.handlebars.helper.WithHelper.apply (WithHelper.java:58) at com.github.jknack.handlebars.internal.Block.merge (Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.TemplateList.merge (TemplateList.java:95) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:130) at com.github.jknack.handlebars.internal.BaseTemplate.apply (BaseTemplate.java:118) at com.github.jknack.handlebars.internal.ForwardingTemplate.apply (ForwardingTemplate.java:72) at io.swagger.codegen.DefaultGenerator.processTemplateToFile (DefaultGenerator.java:745) at io.swagger.codegen.DefaultGenerator.generateApis (DefaultGenerator.java:486) at io.swagger.codegen.DefaultGenerator.generate (DefaultGenerator.java:731) at io.swagger.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:534) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.145 s [INFO] Finished at: 2018-05-29T13:55:15-04:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal io.swagger:swagger-codegen-maven-plugin:3.0.0-rc1:generate (default) on project user-service: Code generation failed. See above for the full exception. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/7919

stiwari99 commented 6 years ago

Any update on this

HugoMario commented 6 years ago

hello @bigbang4u2 , spring generator was already added, can you please check and let me know how it goes?