如何使用 OpenApi/Swagger/YAML 中的保留关键字命名 属性

How to name a property using a reserved keyword in OpenApi/Swagger/YAML

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

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 消息的后端系统以重命名 属性。 谢谢

保留关键字可用作 OpenAPI 中的 property/parameter 名称。

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

components:  
  schemas:  
    element:  
      type: object 
      properties:  
        name:  
          type: string
        type:   # <----- yes, property name can be "type"
          type: string
          enum:
            - radiogroup
            - checkbox