Skip to content

Understanding the opinionated nature of this library #633

@JaredCE

Description

@JaredCE

Checklist

  • Validation: I believe my source definition is valid OpenAPI 3.0.x but the validator complains

Detailed Description

I'm trying to understand the opinionated nature of the validator library. It seems like it forces some things on to you like:

{
  anyOf: [
    { type: 'array', items: { type: 'string' } },
    {
      type: 'object',
      additionalProperties: { enum: [ 'commonjs', 'module' ] }
    }
  ],
  default: [ 'cjs', 'mjs', 'js' ]
}

will fail because it is missing a type field, even though the specs don't seem to suggest it's required. Equally if i try to massage an if/then/else into a valid draft-04 from:

"if": {
        "properties": {
            "country": {
                "const": "United States of America"
            }
        }
    },
    "then": {
        "properties": {
            "postal_code": {
                "pattern": "[0-9]{5}(-[0-9]{4})?"
            }
        }
    },
    "else": {
        "properties": {
            "postal_code": {
                "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"
            }
        }
    }

to

oneOf: [
  {
  allOf: [
    {
       "properties": {
            "country": {
                "const": "United States of America"
            }
        }
    },
    "properties": {
            "postal_code": {
                "pattern": "[0-9]{5}(-[0-9]{4})?"
            }
        }
  ]
  },
  {
  allOf: [
    {
      not: {
        "properties": {
            "country": {
                "const": "United States of America"
            }
        }
      }
    },
    "properties": {
            "postal_code": {
                "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"
            }
        }
  ]
  }
]

it will complain that

"properties": {
            "postal_code": {
                "pattern": "[0-9]{5}(-[0-9]{4})?"
            }
        }

needs to be in its own schema components reference.

Other stuff

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions