5

鉴于已经存在一个特殊的“类型”属性,它是一个保留关键字,有什么方法可以命名自定义属性“类型”。

components:  
  schemas:  
  element:  
  type: object 
  properties:  
    name:  
      type: string  #type here is the keyword
    type: #type here is the actual name of the property!
      type: string
        enum:
          - radiogroup
          - checkbox

无法修改生成 JSON 消息的后端系统以重命名属性。谢谢。

4

1 回答 1

5

保留关键字可用作 OpenAPI 中的属性/参数名称。

您的示例的唯一问题是 YAML 缩进关闭,除了您的对象和属性定义完全有效。

components:  
  schemas:  
    element:  
      type: object 
      properties:  
        name:  
          type: string
        type:   # <----- yes, property name can be "type"
          type: string
          enum:
            - radiogroup
            - checkbox
于 2019-02-27T16:43:20.357 回答