我正在尝试创建一个如下所示的响应对象:
(例如简化)
obj1:
type: object
properties:
data1:
type: string
obj2:
type: object
properties:
data2:
type: string
我有两个定义:
Main:
type: object
allOf:
- $ref: "#/definitions/ob1"
- $ref: "#/definitions/obj2"
然后是第三个定义,如下所示:
Responses
Code Description Schema
200 Success ⇄
Main {
all of:
obj1 { }
obj2 { }
}
我不确定这是否是在主对象基础上合并Obj1和Obj 2的正确方法
Swagger UI显示以下内容
loadjsfile
我不清楚的是它是否会在根处设置这些对象,或者它是否会在响应中声明2个对象???
我假设它是正确的,希望有人可以确认。
答案 0 :(得分:1)
"query": {
"nested": {
"path":"brands ",
"query":{
"wildcard":{
"brands.items":{
"value":"*zero*"
}
}
}
}
}
根据这一点 - Swagger UI显示了两个实际上组成一个具有组合属性的对象的对象。你可以自己尝试一下:
Swagger allows combining and extending model definitions using the allOf property of JSON Schema, in effect offering model composition. allOf takes in an array of object definitions that are validated independently but together compose a single object.
如果您使用StringObj:
type: object
properties:
stringId:
type: string
IntegerObj:
type: object
properties:
integerId:
type: integer
Composed:
description: A representation of a dog
allOf:
- $ref: '#/definitions/StringObj'
- $ref: '#/definitions/IntegerObj'
- 例如 - 您的方法的主体并使用Composed
Swagger创建json:
try this operation