在swagger文件中将oneOf与AdditionalProperty一起使用

时间:2019-07-17 15:41:44

标签: swagger swagger-ui swagger-2.0

我正在使用遵循以下模式的API:

...项目:{    random-1:{...,键入:“产品/图片”}    random-2:{...,键入:“产品/名称”}    random-3:{...,键入:“产品/说明”} }

我想为“项目”创建一个架构,以动态选择合适的架构(图像,名称,描述)。我以为可以结合使用additionalPropertiesoneOf

items: 
  type: object
  additionalProperties:
      $ref: '#schemas/components/product/abstract/attribute'

abstract/attribute: 
   type: object
   required: 
     - type
   properties: 
     type:
        type: string
        example: product/image
     discriminator:
        propertyName: type      

product/image:
   allOf: 
     $ref: #/components/schemas/abstract/attribute
     type: object
     required:
       - src
     properties:
       src:
         type: string

.. etc for product/name and product/description ...

我不确定1)用招摇是否还可以,2)如果可以,我在哪里声明oneOf?最初,我认为我需要枚举items另外的属性中的所有架构,但这似乎是无效的。

0 个答案:

没有答案
相关问题