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

bob*_*b k 5 yaml swagger openapi surveyjs

鉴于已经存在一个特殊的“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
Run Code Online (Sandbox Code Playgroud)

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

Hel*_*len 7

保留关键字可以在所有 OpenAPI 版本中用作属性/参数名称。

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

components:  
  schemas:  
    element:  
      type: object 
      properties:  
        name:  
          type: string
        type:   # <----- yes, property name can be "type"
          type: string
          enum:
            - radiogroup
            - checkbox
Run Code Online (Sandbox Code Playgroud)