如何创建包含各种类型的数组的摇摇欲坠的架构

编程入门 行业动态 更新时间:2024-10-28 14:29:54
本文介绍了如何创建包含各种类型的数组的摇摇欲坠的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试为包含各种类型的对象数组的对象定义一个摇摇欲坠的架构定义.

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

更多推荐

如何创建包含各种类型的数组的摇摇欲坠的架构

本文发布于:2023-11-03 19:48:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:摇摇欲坠   数组   架构   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!