Extension Field Registry
x-jsonschema-if - The JSON Schema if conditional subschema, used when targeting OpenAPI versions that do not directly support it.
JSON Schema draft-07 introduced the if keyword to define a conditional subschema that controls whether then or else applies.
The x-jsonschema-if extension mirrors the JSON Schema if keyword when targeting OpenAPI versions where the keyword is not directly available. It is serialized as x-jsonschema-if so tools can preserve and process the conditional subschema.
Use this extension only with JSON Schema versions before draft-07; draft-07 and later define if 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