我正在尝试为包含各种类型的对象数组的对象定义一个摇摇欲坠的架构定义.
I'm attempting to define a swagger schema definition for an object that contains an array of objects of varying types.
这是模板对象(和所有相关对象类型)的json模式.我知道swagger不支持oneOf谓词,所以我只是想弄清楚如何用swagger描述这种数据结构.我已经尝试过使用这种语法的多种变体,但都没有奏效,这是我可以根据规范和此处找到的一些示例得出的最接近的变体: json-schema/example2.html
Here is the json schema for a template object (and all related object types). I'm aware that swagger does not support the oneOf predicate, so I'm just trying to figure out how to describe this data structure in swagger. I've tried many variations on this syntax, but none have worked and this was the closest I could come based on the spec and some examples found here: json-schema/example2.html
swagger: '2.0' info: version: 1.0.0 title: IDMU paths: definitions: template: type: object properties: collection: type: string name: type: string columnValue: type: string description: type: string outputFile: type: string content: type: string directives: type: array items: type: object oneOf: - $ref: '#/definitions/directiveRequire' - $ref: '#/definitions/directiveReplace' - $ref: '#/definitions/directiveReplaceRowSql' - $ref: '#/definitions/directiveReplaceRowCsv' - $ref: '#/definitions/directiveReplaceColSql' - $ref: '#/definitions/directiveReplaceColCsv' - $ref: '#/definitions/directiveInsertTag' - $ref: '#/definitions/directiveInsertCsv' - $ref: '#/definitions/directiveInsertSql' providerCsv: type: object properties: type: type: integer maximum: 3 minimum: 3 tag: type: string url: type: string staticData: type: string providerTag: type: object properties: type: type: integer maximum: 2 minimum: 2 tag: type: string condition: type: integer list: type: boolean value: type: string providerSql: type: object properties: type: type: integer maximum: 1 minimum: 1 source: type: string columns: type: string from: type: string where: type: string directive: type: object discriminator: type properties: type: type: integer softFail: type: boolean required: - type directiveRequire: type: object allOf: - $ref: '#/definitions/directive' - properties: tags: type: array items: type: string directiveReplace: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string from: type: string to: type: string directiveReplaceRowSql: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string provider: $ref: '#/definitions/providerSql' directiveReplaceRowCsv: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string provider: $ref: '#/definitions/providerCsv' directiveReplaceColCsv: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string fromColumn: type: string toColumn: type: string provider: $ref: '#/definitions/providerCsv' directiveReplaceColSql: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string fromColumn: type: string toColumn: type: string provider: $ref: '#/definitions/providerSql' directiveInsertTag: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string notLast: type: array items: type: string onlyLast: type: array items: type: string provider: $ref: '#/definitions/providerTag' directiveInsertSql: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string notLast: type: array items: type: string onlyLast: type: array items: type: string provider: $ref: '#/definitions/providerSql' directiveInsertCsv: type: object allOf: - $ref: '#/definitions/directive' - properties: description: type: string notLast: type: array items: type: string onlyLast: type: array items: type: string provider: $ref: '#/definitions/providerCsv'推荐答案
OpenAPI Specification 3.0将支持oneOf和anyOf.
OpenAPI Specification 3.0 will support oneOf and anyOf.
在2.0中,您可以将具有不同属性的对象定义为type: object(自由格式对象).对于您的情况,您可能需要执行以下操作:
In 2.0, you can define an object with varying properties as just type: object (free-form object). For your case, you may want to do this:
schema: type: array items: type: object更多推荐
如何创建包含各种类型的数组的摇摇欲坠的架构
发布评论