1
                        <xs:element name="EarningsData" minOccurs="0">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element type="xs:float" name="A"
                                        nillable="true" />
                                    <xs:element type="xs:float" name="B"
                                        nillable="true" />
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>

In the above XSD file, there are minOccurs and nillable. How can this be converted to OpenAPI?

Helen
  • 87,344
  • 17
  • 243
  • 314

1 Answers1

1

The maxOccurs and minOccurs indicate if it's an array element or not. The above XSD complex type definition is converted into the following OAS 3 model definition:

    EarningsData:
      type: array
      minItems: 0
      items:
        type: object
        properties:
          A:
            type: integer
            format: float
            nullable: true
          B:
            type: integer
            format: float
            nullable: true

If the XSD has the maxOccurs attribute, it can be mapped to the maxItems property in OpenAPI. But if maxOccurs="unbounded", it means there is no restriction on the number of elements, so you do not need to specify maxItems explicitly in OpenAPI.

Helen
  • 87,344
  • 17
  • 243
  • 314
Vithursa Mahendrarajah
  • 1,194
  • 2
  • 15
  • 28
  • If there maxOccurs is unbounded like maxOccurs="unbounded" then how we write it ? –  Sep 10 '21 at 05:30
  • 1
    According to the [spec](https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#section-5.3.2), an array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword. Since with `unbounded` there is no restriction on the number of elements, you do not need to specify it explicitly in the swagger. – Vithursa Mahendrarajah Sep 10 '21 at 05:55