Swagger 3.0.0 codegen失败java.lang.RuntimeException:缺少swagger输入或配置

问题描述 投票:2回答:1

我使用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,这也给出了相同的错误。

swagger swagger-codegen openapi
1个回答
0
投票

正如anothernode在问题中建议的那样,从3.0.0分支再次构建成功

© www.soinside.com 2019 - 2024. All rights reserved.