Search code examples
yamlswaggeropenapisurveyjs

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


Is there any way to name a custom property 'type', given that there already exists a special 'type' property which is a reserved keyword.

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

The back-end system which produces the JSON messages cannot be modified to rename the property. Thanks.


Solution

  • Reserved keywords can be used as property/parameter names in all OpenAPI versions.

    The only issue with your example is that YAML indentation is off, other than that your object and property definitions are perfectly valid.

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