我使用swagger指定我的API我正在使用2.0现在根据我使用离线swagger编辑器指定3.0.0规范的文档有新版本3.0.0。一旦准备就绪,我下载了json文件,我将使用它来生成spring服务器代码。我下载了swagger-codegen
使用mvn clean package
构建它然后执行以下命令:
java -jar <PARENT_DIR>/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i <PARENT_DIR>/ServerCode/swagger.json -l spring -o <PARENT_DIR>/ServerCode
以上命令给我以下错误:
[main] INFO io.swagger.parser.Swagger20Parser - reading from swagger.json
[main] INFO io.swagger.parser.Swagger20Parser - reading from swagger.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:723)
at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
更新:
我的swagger.json文件如下(这是我的试用项目,因此我在这里粘贴了我的api结构):
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "User Example",
"license": {
"name": "MIT"
}
},
"servers": [
{
"url": "http://www.example.com//v1"
}
],
"paths": {
"/user": {
"post": {
"summary": "API to create a new User",
"operationId": "createUser",
"tags": [
"user"
],
"security": [
{
"bearerAuth": []
}
],
"requestBody": {
"description": "User data to be created",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"responses": {
"200": {
"description": "Newly created User data",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"404": {
"description": "Unexpected Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AuthError"
}
}
}
},
"500": {
"description": "Unexpected Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InternalServerError"
}
}
}
},
"default": {
"description": "Unexpected Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UnexpectedError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"required": [
"id",
"fname",
"email"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"fname": {
"type": "string"
},
"lname": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"phone": {
"type": "string"
}
}
},
"UnexpectedError": {
"properties": {
"message": {
"type": "string",
"example": "Something went wrong"
}
}
},
"AuthError": {
"properties": {
"message": {
"type": "string",
"example": "Authorization failed"
}
}
},
"InternalServerError": {
"properties": {
"message": {
"type": "string",
"example": "There is server side error while processing your request"
}
}
}
},
"securitySchemes": {
"bearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
}
}
我已经尝试在3.0.0分支上构建code-gen-cli,这也是同样的错误。
答案 0 :(得分:0)
根据anothernode的建议,从3.0.0分支再次构建问题注释会成功生成
答案 1 :(得分:0)
我知道现在回答这个问题太晚了,但我通过一个简单的更改就解决了这个问题。
在你的 json 文件中
改变
{
"openapi": "3.0.0",
"info": {
到这里
{
"swagger": "3.0.0",
"info": {
它会被解决。