Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 865
bob k Avatar asked Oct 16 '22 06:10

bob k


1 Answers

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

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
like image 183
Helen Avatar answered Oct 20 '22 22:10

Helen