简体   繁体   English

swagger-codegen不为引用的json文件中定义的模式生成类

[英]swagger-codegen not generating classes for schemas defined in referenced json files

I am unable to get swagger-codegen to generate classes for json schemas defined in files separate from the main API definition file. 我无法获得swagger-codegen为在与主API定义文件分开的文件中定义的json模式生成类。 The command I am using is: 我正在使用的命令是:

$ java -jar swagger-codegen-cli-2.2.2.jar generate -i api.json -l java -o gen -v

This is what api.json looks like: 这是api.json的样子:

{
"swagger": "2.0",
"info": {
    "version": "1.0.0",
    "title": "Simple API",
    "description": "A simple API to learn how to write OpenAPI Specification"
},
"schemes": [
    "https"
],
"host": "simple.api",
"basePath": "/openapi101",
"paths": {
    "/persons": {
        "get": {
            "summary": "Gets some persons",
            "description": "Returns a list containing all persons.",
            "responses": {
                "200": {
                    "description": "A list of Person",
                    "schema": {
                  "$ref" : "person.json#/definitions/person"                    

    }
                    }
                }
            }
        }
    }

} }

The person.json file referenced here lives alongside api.json (ie at the same level) and contains the following: 此处引用的person.json文件与api.json并存(即处于同一级别),并包含以下内容:

{"definitions": {
“person”: {
  "type": "object",
  "description": "",
  "properties": {
    "requestId": {
      "type": "string",
      "example": "1234"
    }
  }
}}}

I would expect the code generation to generate a class called Person.java - but it does not - in fact it does not generate any model classes. 我希望代码生成会生成一个名为Person.java的类,但实际上不会生成任何模型类。 Also the verbose logging logs the following right at the start which makes me think it is interpreting the reference incorrectly and for some reason prepending a #definitions to the $ref. 同样,冗长的日志记录也会在开始时记录以下正确的信息,这使我认为它在错误地解释了引用,并且由于某种原因在$ ref之前加上了#definitions。

[main] INFO io.swagger.parser.Swagger20Parser - reading from api.json [main]信息io.swagger.parser.Swagger20Parser-从api.json中读取

{
  "swagger" : "2.0",
  "info" : {
    "description" : "A simple API to learn how to write OpenAPI Specification",
    "version" : "1.0.0",
    "title" : "Simple API"
  },
  "host" : "simple.api",
  "basePath" : "/openapi101",
  "schemes" : [ "https" ],
  "paths" : {
    "/persons" : {
      "get" : {
        "summary" : "Gets some persons",
        "description" : "Returns a list containing all persons.",
        "parameters" : [ ],
        "responses" : {
          "200" : {
            "description" : "A list of Person",
            "schema" : {
              "$ref" : "#/definitions/person.json#/definitions/person"
            }
          }
        }
      }
    }
  }
}

Anybody know what is going on here and what is the correct way to reference a schema definition that lives in a local file? 有人知道这是怎么回事,以及引用存在于本地文件中的架构定义的正确方法是什么?

在$ ref中添加./使其起作用。

./person.json#/definitions/person

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM