我有以下json,我一直在尝试使用openapi3规范来创建一个招摇。
其中数字键(即“ 1111”)是动态唯一ID。
{
"11111": {
"cat1": {
"catId": "abcd",
"value": 700
},
"cat2": {}
},
"11112": {
"cat1": {
"catId": "xyz",
"value": 40
},
"cat2": {
"catId": "fghj",
"value": 40
}
},
"45677": {
"cat1": {
"catId": "abcd",
"value": 50
},
"cat2": {
"catId": "xyz",
"value": 50
}
},
"date": "2019-05-29"
}
我尝试了一种基于示例json http://apistudio.io/生成规范的工具,但它确实没有提供我想要的东西。
这是我得到的最接近的东西,但这并不是我想要的:
responses:
200:
description: category response
content:
application/json:
schema:
properties:
date:
type: string
format: date
categories:
properties:
key:
type: string
cat1:
items:
$ref: '#/components/schemas/cat1'
cat2:
items:
$ref: '#/components/schemas/cat2'
404:
description: error
application/json:
schema:
$ref: '#/components/schemas/error'
components:
schemas:
cat1:
required:
- cadId
- value
properties:
cadId:
description: Category id
type: string
enum: [
abcd
xyz
]
value:
type: number
format: int64
cat2:
required:
- cadId
- value
properties:
cadId:
description: Category id
type: string
enum: [
fghj
]
value:
type: number
format: int64
error:
type: object
required:
- statusCode
- code
- message
- description
properties:
statusCode:
type: integer
format: int32
code:
type: string
message:
type: string
description:
type: string
这是我的代码生成的示例,如您所见,它与我需要的不匹配:
{
"date": "2019-05-29",
"categories": {
"key": "string",
"cat1": [
{
"cadId": "abcd xyz",
"value": 0
}
],
"cat2": [
{
"cadId": "fghj",
"value": 0
}
]
}
}
预先感谢