Forum Discussion

maryabl's avatar
maryabl
New Contributor
4 years ago

anyOf in OpenAPI 3.0

Hi experts,

I am facing issue on defining the AnyOf in YAML Open API 3.0 version.

 

sample:

        weight:

                description: >-

                  Please enter the weight information for line item. Either a

                  netValue or grossValue must be provided for the line item.

                type: object

                properties:

                  netValue:

                    description: Please enter the net weight value

                    type: number

                    minimum: 0

                    maximum: 999999999999

                    multipleOf: 0.001

                    example: 10

                  grossValue:

                    description: Please enter the gross weight value

                    type: number

                    minimum: 0

                    maximum: 999999999999

                    multipleOf: 0.001

                    example: 10

                additionalProperties: false

                anyOf:

                  - netValue

                  - grossValue

 

I am facing issue on anyOf which keep mentioned need to be an object for the netValue and grossValue.

What is the best way for me to proceed?

Appreciate inputs.

Thanks.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Try this:

    anyOf:
      - required: [netValue]
      - required: [grossValue]

     Note that "anyOf" means either or both properties should be present. If just one of these properties should be present (i.e. they are musually exclusive), use "oneOf" instead.