Forum Discussion

omar199687's avatar
omar199687
New Member
5 years ago

Variable with two types or more

Is there a way that we can use two types or more for a parameter in swagger 2 like when we use oneOf in openAPI 3

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    It depends on the parameter location (in attribute).

     

    Path, query, header, and form parameters in OpenAPI 2.0 require a specific type and cannot have multiple types.

     

    However, in schemas for body parameters and responses, if you don't specify the type a schema, property, or array items schema, it means "any type" . That's the most you can do in OpenAPI 2.0.

     

    definitions:
      MyModel:
        type: object
        properties:
          id:
            type: integer
            example: 1
          data:
            # No "type" means the value can be of any type
            example: 'custom data'
    
      ArrayOfArbitraryValues:
        type: array
        items: {}
        example: ['string', -1, false]