如何为 OpenAPI 3.0.0 运行 swagger-codegen何为、OpenAPI、swagger、codegen

2023-09-07 14:08:40 作者:悲伤怎么遮掩

看起来像官方 swagger for openapi 规范 V3 支持即将发布 https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/,并且 swagger-codegen 已经开发了 3.0.0 支持并通过了一定程度的测试 https://github.com/swagger-api/swagger-codegen

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 branch

我有一个 swagger 规范(通过 https://github.com/mermade/swagger2openapi 从我现有的 2.0 规范生成,输出看起来不错)

I have a swagger spec (generated from my existing 2.0 spec via https://github.com/mermade/swagger2openapi, output looks good)

有没有一种简单的方法来运行 swagger-codegen 而不必自己打包 jar?

Is there an easy way to run the swagger-codegen without having to package the jar myself?

这是我找到的唯一结果:https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/3.0.0-SNAPSHOT/ 但运行似乎被破坏了(来自输出,可能实际运行的是 2.0 而不是 3.0.0?): 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 - 从/input/myspec.openapi3.json 读取[主] 信息 io.swagger.codegen.ignore.CodegenIgnoreProcessor - 找不到 .swagger-codegen-ignore 文件.线程主"java.lang.RuntimeException 中的异常:缺少招摇输入或配置!在 io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:685)在 io.swagger.codegen.cmd.Generate.run(Generate.java:285)在 io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

[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)

看起来 swagger-codegen repo 有一种在某种程度上受支持的方式来运行 docker 容器在你构建之后;我只是希望/猜测有一种支持的方式来执行此操作,而无需在本地编译,因为我需要在多个地方进行设置.

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.

推荐答案

OpenAPI Generator(由Swagger Codegen) 支持 OpenAPI 规范 v2 和 v3.

OpenAPI Generator (found by top contributors of Swagger Codegen) supports both OpenAPI specification v2 and v3.

您可以使用 docker 镜像,Java JAR (SNAPSHOT),Brew 或 npm 试试看.

You can use the docker images, Java JAR (SNAPSHOT), Brew or npm to give it a try.

有关 OpenAPI Generator 的更多信息,请参阅项目的 README

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.

更新:第一个稳定版本 3.0.0 已发布:https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.0

UPDATE: 1st stable version 3.0.0 has been released: https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.0