Extension Field Registry

x-jsonschema-else - The JSON Schema else conditional subschema, used with x-jsonschema-if when targeting OpenAPI versions that do not directly support it.

JSON Schema draft-07 introduced the else keyword to define the subschema that applies when the if subschema does not match.

The x-jsonschema-else extension mirrors this JSON Schema keyword when targeting OpenAPI versions where the keyword is not directly available, serializing it as x-jsonschema-else.

Use this extension only with JSON Schema versions before draft-07; draft-07 and later define else directly.

Like the x-jsonschema- namespace, this extension is intended for OpenAPI 3.0 and earlier. When using OpenAPI 3.1 or later, the OpenAPI jsonSchemaDialect field, or JSON Schema’s "$schema" keyword, should be used instead.

It can appear as a property in the following objects: ["Schema Object"].

Used by: (informational)

Schema

{"$ref"=>"#/$defs/schemaObject"}

Example

openapi: 3.0.4
info:
  title: My API
  version: 1.0.0
paths: {}
components:
  schemas:
    Address:
      type: object
      properties:
        country:
          type: string
        postalCode:
          type: string
      x-jsonschema-if:
        properties:
          country:
            const: US
        required:
          - country
      x-jsonschema-else:
        properties:
          postalCode:
            minLength: 1
        required:
          - postalCode