我无法获得swagger-codegen来为与主API定义文件分开的文件中定义的json模式生成类。我正在使用的命令是:
$ java -jar swagger-codegen-cli-2.2.2.jar generate -i api.json -l java -o gen -v
这就是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"
}
}
}
}
}
}
}
此处引用的person.json文件与api.json一起存在(即在同一级别)并包含以下内容:
{"definitions": {
“person”: {
"type": "object",
"description": "",
"properties": {
"requestId": {
"type": "string",
"example": "1234"
}
}
}}}
我希望代码生成生成一个名为Person.java的类 - 但它不会 - 实际上它不会生成任何模型类。同样详细的日志记录在开始时记录以下内容,这使我认为它正在错误地解释引用,并且由于某种原因将#definitions添加到$ ref。
[main] INFO 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"
}
}
}
}
}
}
}
有人知道这里发生了什么,以及引用本地文件中的模式定义的正确方法是什么?
答案 0 :(得分:0)
在$ ref中添加./使其正常工作。
./person.json#/definitions/person