How to run swagger-codegen for OpenAPI 3.0.0
Solution 1
OpenAPI Generator (found by top contributors of Swagger Codegen) supports both OpenAPI specification v2 and v3.
You can use the docker images, Java JAR (SNAPSHOT), Brew or npm to give it a try.
For more information about OpenAPI Generator, please refer to the project's README
If you need any help, please open an issue and we'll look into it.
UPDATE: 1st stable version 3.0.0 has been released: https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.0
Solution 2
Swagger-codegen 3.0.0 snapshots now include a limited number of targets for code generation from OpenAPI 3.0 definitions. https://github.com/swagger-api/swagger-codegen/issues/6598#issuecomment-333428808
There is an alternative experimental implementation of the codegen engine, using the original swagger-codegen 2.x templates, written in Node.js: https://github.com/mermade/openapi-codegen - if your language is not yet supported, a config file just needs to be created for it mapping the template files to outputs.
Related videos on Youtube
Comments
-
some bits flipped almost 2 years
looks like official swagger for openapi specification V3 support is near release https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/, and the swagger-codegen has 3.0.0 support developed and passing some level of testing https://github.com/swagger-api/swagger-codegen on the
3.0.0
branchI have a swagger spec (generated from my existing 2.0 spec via https://github.com/mermade/swagger2openapi, output looks good)
Is there an easy way to run the swagger-codegen without having to package the jar myself?
- this is the single result i found: https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/3.0.0-SNAPSHOT/ but running that seems to be broken (from the output, possibly actually running 2.0 not 3.0.0?):
[main] INFO io.swagger.parser.Swagger20Parser - reading from /input/myspec.openapi3.json [main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found. Exception in thread "main" java.lang.RuntimeException: missing swagger input or config! at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:685) at io.swagger.codegen.cmd.Generate.run(Generate.java:285) at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
It looks like the swagger-codegen repo has a somewhat supported way to run a docker container after you build; I'm just hoping/guessing there is a supported way to do this without needing to compile locally, as I need to set this up in several places.
-
some bits flipped over 6 yearshub.docker.com/r/bentheadset/bentheadset-swagger-codegen-3.0.0 pulls the .jar published in the link above ( oss.sonatype.org/content/repositories/snapshots/io/swagger/… )
-
William Cheng over 6 yearsOpenAPI 3.0 support is being worked on. Please refer to the branch (github.com/swagger-api/swagger-codegen/tree/3.0.0_enhancements) for progress.
-
tchrist over 5 years@WilliamCheng Your link has gone dead.
-
William Cheng over 5 years@tchrist thanks for reporting the broken link. I'm no longer involved in Swagger Codegen. Please refer to my answer below for more information.
-
chrisinmtown almost 5 yearsPlease see this slightly newer question re using the swagger codegen maven plugin on an OpenAPI 3.0 spec bcos it has working answers: stackoverflow.com/questions/49616529/…