如何修复 java.lang.RuntimeException:缺少 swagger 输入或配置? [英] How to fix java.lang.RuntimeException: missing swagger input or config?

查看:53
本文介绍了如何修复 java.lang.RuntimeException:缺少 swagger 输入或配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 swagger-codegen-cli.jarswagger.json 生成 java 代码,但出现此异常:

线程main"中的异常java.lang.RuntimeException: 缺少 swagger 输入或配置!在 io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:763)在 io.swagger.codegen.cmd.Generate.run(Generate.java:299)在 io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

我尝试运行的命令如下:

java -jar swagger-codegen-cli.jar generate -i swagger.json -l java -c java-config.json -o api-client

解决方案

您正在使用不支持 OpenAPI 3.0 的 Swagger Codegen 2.x.

您需要改用 Swagger Codegen 3.x.您可以从 Maven Central 下载最新的 3.x CLI JAR:
https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-cli

这是 3.0.20 版 CLI(截至撰写本文时的最新版本)的直接链接:
https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.20/swagger-codegen-cli-3.0.20.jar>

或者,如果您更喜欢从源代码构建 codegen,版本 3 位于 3.0.0 分支中:
https://github.com/swagger-api/swagger-codegen/tree/3.0.0

I'm trying to generate java code from swagger.json using swagger-codegen-cli.jar but I get this exception:

Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:763)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:299)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

The command I'm trying to run is the following:

java -jar swagger-codegen-cli.jar generate -i swagger.json -l java -c java-config.json -o api-client

解决方案

You are using Swagger Codegen 2.x which does not support OpenAPI 3.0.

You need to use Swagger Codegen 3.x instead. You can download the latest 3.x CLI JAR from Maven Central:
https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-cli

Here's a direct link to v. 3.0.20 CLI (the latest version as of the time of writing):
https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.20/swagger-codegen-cli-3.0.20.jar


Or if you prefer to build the codegen from the source code, version 3 is in the 3.0.0 branch:
https://github.com/swagger-api/swagger-codegen/tree/3.0.0

这篇关于如何修复 java.lang.RuntimeException:缺少 swagger 输入或配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆