7

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.

bob k
  • 73
  • 1
  • 5
  • ps. sample of original json data is:elements: [ { type: "radiogroup", name: "DentalQuestion2" } , { type: "checkbox", name: "DentalQuesiton3" } ] – bob k Feb 27 '19 at 14:42

1 Answers1

7

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
Helen
  • 87,344
  • 17
  • 243
  • 314