Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIA2 schema for type = array #1891

Closed
anhle54 opened this issue Apr 10, 2019 · 3 comments
Closed

OIA2 schema for type = array #1891

anhle54 opened this issue Apr 10, 2019 · 3 comments

Comments

@anhle54
Copy link

anhle54 commented Apr 10, 2019

Per spec, if the type is array, then items is required. However,
I have look into the OAI2 schema, and here is the part that they define the primitiveItems:

"primitivesItems": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "string",
            "number",
            "integer",
            "boolean",
            "array"
          ]
        },
        "format": {
          "type": "string"
        },
        "items": {
          "$ref": "#/definitions/primitivesItems"
        },
        "collectionFormat": {
          "$ref": "#/definitions/collectionFormat"
        },
        "default": {
          "$ref": "#/definitions/default"
        },
        "maximum": {
          "$ref": "#/definitions/maximum"
        },
        "exclusiveMaximum": {
          "$ref": "#/definitions/exclusiveMaximum"
        },
        "minimum": {
          "$ref": "#/definitions/minimum"
        },
        "exclusiveMinimum": {
          "$ref": "#/definitions/exclusiveMinimum"
        },
        "maxLength": {
          "$ref": "#/definitions/maxLength"
        },
        "minLength": {
          "$ref": "#/definitions/minLength"
        },
        "pattern": {
          "$ref": "#/definitions/pattern"
        },
        "maxItems": {
          "$ref": "#/definitions/maxItems"
        },
        "minItems": {
          "$ref": "#/definitions/minItems"
        },
        "uniqueItems": {
          "$ref": "#/definitions/uniqueItems"
        },
        "enum": {
          "$ref": "#/definitions/enum"
        },
        "multipleOf": {
          "$ref": "#/definitions/multipleOf"
        }
},

If we run the validation based on this schema, we will have this following case, which is not correct, but it still pass the schema validation because there is no where in the schema make items required when the type: array

example:
    allOf:
      - $ref: '#/definitions/exampleDefinition'
      - type: array
        description: example definition
        properties:
          features:
            type: object
            description: example features
            items:
              $ref: '#/definitions/exampleFeature'
@handrews
Copy link
Member

@anhle54 this is standard JSON Schema behavior, as you may sometimes want an array without constraining the shape of the items. Or you may define the type as array in one schema, define items in another, and use allOf to combine them.

Furthermore, I do not believe there is any more work occurring on OAS v2.x. @webron @MikeRalphson can this be closed?

@webron
Copy link
Member

webron commented Jan 23, 2020

As we always say, schema validation is not a guarantee to a compliant definition. We're not doing active work on the OAS2 schema. While I'm ok with reviewing a PR on it, adding this restriction using the older version of JSON Schema would make the already-way-too-complex Schema significantly more complex.

@handrews
Copy link
Member

handrews commented Feb 9, 2020

@webron I'm interpreting that as saying that this is closable. 😄

@handrews handrews closed this as completed Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants