Extension Field Registry
x-jsonschema-then - The JSON Schema then conditional subschema, used with x-jsonschema-if when targeting OpenAPI versions that do not directly support it.
JSON Schema draft-07 introduced the then keyword to define the subschema that applies when the if subschema matches.
The x-jsonschema-then extension mirrors this JSON Schema keyword when targeting OpenAPI versions where the keyword is not directly available, serializing it as x-jsonschema-then.
Use this extension only with JSON Schema versions before draft-07; draft-07 and later define then directly.
Although OpenAPI 3.0 used JSON Schema draft-07, it prohibited this keyword, so use this extension with OpenAPI 3.0.
It can appear as a property in the following objects: ["Schema Object"].
Used by: (informational)
- Microsoft.OpenApi (.NET OpenAPI library)
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-then:
properties:
postalCode:
pattern: "^[0-9]{5}$"
required:
- postalCode