-
Notifications
You must be signed in to change notification settings - Fork 47
JSONSchema
OpenAPI "Schema Object"
public enum JSONSchemaComponentDictionaryLocatable, Decodable, Encodable, Equatable, LocallyDereferenceable, JSONSchemaContext
public init(from decoder: Decoder) throwscase boolean(: CoreContext<JSONTypeFormat.BooleanFormat>)case number(: CoreContext<JSONTypeFormat.NumberFormat>, : NumericContext)case integer(: CoreContext<JSONTypeFormat.IntegerFormat>, : IntegerContext)case string(: CoreContext<JSONTypeFormat.StringFormat>, : StringContext)case object(: CoreContext<JSONTypeFormat.ObjectFormat>, : ObjectContext)case array(: CoreContext<JSONTypeFormat.ArrayFormat>, : ArrayContext)case all(of: [JSONSchema], core: CoreContext<JSONTypeFormat.AnyFormat>)case one(of: [JSONSchema], core: CoreContext<JSONTypeFormat.AnyFormat>)case any(of: [JSONSchema], core: CoreContext<JSONTypeFormat.AnyFormat>)case not(: JSONSchema, core: CoreContext<JSONTypeFormat.AnyFormat>)case reference(: JSONReference<JSONSchema>)Schemas without a type.
case fragment(: CoreContext<JSONTypeFormat.AnyFormat>)var openAPIComponentsKey: Stringvar openAPIComponentsKeyPath: KeyPath<OpenAPI.Components, OpenAPI.ComponentDictionary<Self>>The type and format of the schema.
var jsonTypeFormat: JSONTypeFormat?The fundamental type of the schema.
var jsonType: JSONType?The format of the schema as a string value.
var formatString: String?This can be set even when a schema type has
not be specified. If a type has been specified,
a type-safe format can be used and retrieved
via the jsonTypeFormat property.
var required: Boolvar description: String?var discriminator: OpenAPI.Discriminator?var nullable: Boolvar readOnly: Boolvar writeOnly: Boolvar deprecated: Boolvar title: String?var externalDocs: OpenAPI.ExternalDocumentation?var allowedValues: [AnyCodable]?var defaultValue: AnyCodable?var example: AnyCodable?Check if this schema is an empty .fragment.
var isEmpty: BoolA special case of the .fragment schema is the "empty"
schema where no information about the schema component
is available.
This is equivalent to the following JSON Schema:
{
}
Check if this schema is a .fragment.
var isFragment: BoolCheck if a schema is a .boolean.
var isBoolean: BoolCheck if a schema is a .number.
var isNumber: BoolThis returns false if the schema is an
.integer even though Integer schemas
can be easily transformed into Number schemas.
Check if a schema is an .integer.
var isInteger: BoolCheck if a schema is a .string.
var isString: BoolCheck if a schema is an .object.
var isObject: BoolCheck if a schema is an .array.
var isArray: BoolCheck if a schema is a .reference.
var isReference: BoolGet the core context most JSONSchemas have.
var coreContext: JSONSchemaContext?This is the information shared by most schemas.
Notably, reference schemas do not have this core context.
Get the context specific to an object schema. If not an
object schema, returns nil.
var objectContext: ObjectContext?Get the context specific to an array schema. If not an
array schema, returns nil.
var arrayContext: ArrayContext?Get the context specific to a number schema. If not a
number schema, returns nil.
var numberContext: NumericContext?Although integers are numbers, an integer schema will
still return nil when asked for a numberContext.
If you wish to get a NumericContext from an integer
schema, take an IntegerContext and explicitly request
a NumericContext from it via its numericContext
accessor.
Get the context specific to an integer schema. If not an
integer schema, returns nil.
var integerContext: IntegerContext?Get the context specific to a string schema. If not a
string schema, returns nil.
var stringContext: StringContext?A required, non-nullable boolean schema.
var boolean: JSONSchemaA required, non-nullable fragment of a schema.
var fragment: JSONSchemaThis is also known as the "empty" schema because
its representation in JSON is just an empty object { }.
A required, non-nullable string schema.
var string: JSONSchemaA required, non-nullable number schema.
var number: JSONSchemaA required, non-nullable integer schema.
var integer: JSONSchemaA required, non-nullable object schema.
var object: JSONSchemaA required, non-nullable array schema.
var array: JSONSchemaReturns a dereferenced schema object if all references in this schema object can be found in the Components Object.
public func _dereferenced(in components: OpenAPI.Components, following references: Set<AnyHashable>) throws -> DereferencedJSONSchemaReferenceError.cannotLookupRemoteReference or ReferenceError.missingOnLookup(name:key:) depending on whether an unresolvable reference points to another file or just points to a component in the same file that cannot be found in the Components Object.
Returns a dereferenced schema object if this schema object already does not contain any references.
public func dereferenced() -> DereferencedJSONSchema?To create a dereferenced schema object from a schema object
that does have references, use dereferenced(in:).
Return the optional version of this JSONSchema
public func optionalSchemaObject() -> JSONSchemaReturn the required version of this JSONSchema
public func requiredSchemaObject() -> JSONSchemaReturn the nullable version of this JSONSchema
public func nullableSchemaObject() -> JSONSchemaReturn a version of this JSONSchema that only allows the given
values.
public func with(allowedValues: [AnyCodable]) -> JSONSchemaReturn a version of this JSONSchema that has the given default value.
public func with(defaultValue: AnyCodable) -> JSONSchemaReturns a version of this JSONSchema that has the given example
attached.
public func with(example: AnyCodable) throws -> JSONSchemaReturns a version of this JSONSchema that has the given discriminator.
public func with(discriminator: OpenAPI.Discriminator) -> JSONSchemaboolean(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:allowedValues:defaultValue:example:)
Construct a boolean schema.
public static func boolean(format: JSONTypeFormat.BooleanFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.BooleanFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemaboolean(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:allowedValues:defaultValue:example:)
Construct a boolean schema passing a variadic list of allowed values.
public static func boolean(format: JSONTypeFormat.BooleanFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.BooleanFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, allowedValues: AnyCodable, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemafragment(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:allowedValues:defaultValue:example:)
Construct a fragment of a schema.
public static func fragment(format: JSONTypeFormat.AnyFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.AnyFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemafragment(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:allowedValues:defaultValue:example:)
Construct a fragment of a schema passing a variadic list of allowed values.
public static func fragment(format: JSONTypeFormat.AnyFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.AnyFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, allowedValues: AnyCodable, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemastring(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minLength:maxLength:pattern:allowedValues:defaultValue:example:)
Construct a string schema.
public static func string(format: JSONTypeFormat.StringFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.StringFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minLength: Int? = nil, maxLength: Int? = nil, pattern: String? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemastring(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minLength:maxLength:pattern:allowedValues:defaultValue:example:)
Construct a string schema passing a variadic list of allowed values.
public static func string(format: JSONTypeFormat.StringFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.StringFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minLength: Int? = nil, maxLength: Int? = nil, pattern: String? = nil, allowedValues: AnyCodable, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemanumber(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues:defaultValue:example:)
Construct a number schema.
public static func number(format: JSONTypeFormat.NumberFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.NumberFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, multipleOf: Double? = nil, maximum: (Double, exclusive: Bool)? = nil, minimum: (Double, exclusive: Bool)? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemanumber(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues:defaultValue:example:)
Construct a number schema passing a variadic list of allowed values.
public static func number(format: JSONTypeFormat.NumberFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.NumberFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, multipleOf: Double? = nil, maximum: (Double, exclusive: Bool)? = nil, minimum: (Double, exclusive: Bool)? = nil, allowedValues: AnyCodable, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemainteger(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues:defaultValue:example:)
Construct an integer schema.
public static func integer(format: JSONTypeFormat.IntegerFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.IntegerFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, multipleOf: Int? = nil, maximum: (Int, exclusive: Bool)? = nil, minimum: (Int, exclusive: Bool)? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemainteger(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues:defaultValue:example:)
Construct an integer schema passing a variadic list of allowed values.
public static func integer(format: JSONTypeFormat.IntegerFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.IntegerFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, multipleOf: Int? = nil, maximum: (Int, exclusive: Bool)? = nil, minimum: (Int, exclusive: Bool)? = nil, allowedValues: AnyCodable, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemaobject(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minProperties:maxProperties:properties:additionalProperties:allowedValues:defaultValue:example:)
Construct an objecy schema.
public static func object(format: JSONTypeFormat.ObjectFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.ObjectFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minProperties: Int? = nil, maxProperties: Int? = nil, properties: [String: JSONSchema] = [:], additionalProperties: Either<Bool, JSONSchema>? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemaarray(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minItems:maxItems:uniqueItems:items:allowedValues:defaultValue:example:)
Construct an array schema.
public static func array(format: JSONTypeFormat.ArrayFormat = .unspecified, required: Bool = true, nullable: Bool? = nil, permissions: JSONSchema.CoreContext<JSONTypeFormat.ArrayFormat>.Permissions? = nil, deprecated: Bool? = nil, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minItems: Int? = nil, maxItems: Int? = nil, uniqueItems: Bool? = nil, items: JSONSchema? = nil, allowedValues: [AnyCodable]? = nil, defaultValue: AnyCodable? = nil, example: AnyCodable? = nil) -> JSONSchemaConstruct a schema stating all of the given fragment requirements are met.
public static func all(of schemas: [JSONSchema]) -> JSONSchemaConstruct a schema stating all of the given fragment requirements are met given a discriminator.
public static func all(of schemas: JSONSchema, required: Bool = true, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchemaConstruct a schema stating one of the given schema's requirements are met.
public static func one(of schemas: [JSONSchema]) -> JSONSchemaConstruct a schema stating one of the given schema's requirements are met given a discriminator.
public static func one(of schemas: JSONSchema, required: Bool = true, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchemaConstruct a schema stating any of the given schema's requirements are met.
public static func any(of schemas: [JSONSchema]) -> JSONSchemaConstruct a schema stating any of the given schema's requirements are met given a discriminator.
public static func any(of schemas: JSONSchema, required: Bool = true, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchemaConstruct a schema stating the given schema's requirements are not met.
public static func not(_ schema: JSONSchema, required: Bool = true, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchemaOnly the schema taken as the first argument is inverted by the not logic. Any other arguments are here to directly describe what this schema is as opposed to what it is not.
public func encode(to encoder: Encoder) throwsGet a simplified DereferencedJSONSchema.
public func simplified(given components: OpenAPI.Components) throws -> DereferencedJSONSchemaA fully simplified JSON Schema is both dereferenced and also reduced to a more normal form where possible.
As an example, many compound schemas can be simplified.
{
"allOf": [
{ "type": "object", "description": "Hello World" },
{
"properties": [
"name": { "type": "string" }
]
}
]
}
simplifies to ->
{
"type": "object",
"description": "Hello World",
"properties": [
"name": { "type": "string" }
]
}
You can create simplified schemas from the DereferencedJSONSchema
type with the simplified() method or you can create simplified schemas from
the JSONSchema type with the simplified(given:) method (which
combines dereferencing and resolving by taking the OpenAPI.Components as
input).
.
Types
- AnyCodable
- DereferencedContent
- DereferencedContentEncoding
- DereferencedDocument
- DereferencedDocument.Route
- DereferencedHeader
- DereferencedJSONSchema
- DereferencedJSONSchema.ArrayContext
- DereferencedJSONSchema.ObjectContext
- DereferencedOperation
- DereferencedOperation.ResponseOutcome
- DereferencedParameter
- DereferencedPathItem
- DereferencedPathItem.Endpoint
- DereferencedRequest
- DereferencedResponse
- DereferencedSchemaContext
- DereferencedSecurityRequirement
- DereferencedSecurityRequirement.ScopedScheme
- Either
- EitherDecodeNoTypesMatchedError
- EitherDecodeNoTypesMatchedError.IndividualFailure
- ErrorCategory
- ErrorCategory.KeyValue
- InconsistencyError
- JSONReference
- JSONReference.InternalReference
- JSONReference.Path
- JSONReference.PathComponent
- JSONSchema
- JSONSchema.ArrayContext
- JSONSchema.CoreContext
- JSONSchema.CoreContext.Permissions
- JSONSchema.IntegerContext
- JSONSchema.IntegerContext.Bound
- JSONSchema.NumericContext
- JSONSchema.NumericContext.Bound
- JSONSchema.ObjectContext
- JSONSchema.StringContext
- JSONSchemaResolutionError
- JSONType
- JSONTypeFormat
- JSONTypeFormat.AnyFormat
- JSONTypeFormat.ArrayFormat
- JSONTypeFormat.BooleanFormat
- JSONTypeFormat.IntegerFormat
- JSONTypeFormat.IntegerFormat.Extended
- JSONTypeFormat.NumberFormat
- JSONTypeFormat.ObjectFormat
- JSONTypeFormat.StringFormat
- JSONTypeFormat.StringFormat.Extended
- OpenAPI
- OpenAPI.CallbackURL
- OpenAPI.ComponentKey
- OpenAPI.Components
- OpenAPI.Components.ReferenceCycleError
- OpenAPI.Components.ReferenceError
- OpenAPI.Content
- OpenAPI.Content.Encoding
- OpenAPI.ContentType
- OpenAPI.Discriminator
- OpenAPI.Document
- OpenAPI.Document.Info
- OpenAPI.Document.Info.Contact
- OpenAPI.Document.Info.License
- OpenAPI.Document.Route
- OpenAPI.Document.Version
- OpenAPI.Error
- OpenAPI.Error.Decoding
- OpenAPI.Error.Decoding.Document
- OpenAPI.Error.Decoding.Document.Context
- OpenAPI.Error.Decoding.Operation
- OpenAPI.Error.Decoding.Operation.Context
- OpenAPI.Error.Decoding.Path
- OpenAPI.Error.Decoding.Path.Context
- OpenAPI.Error.Decoding.Request
- OpenAPI.Error.Decoding.Request.Context
- OpenAPI.Error.Decoding.Response
- OpenAPI.Error.Decoding.Response.Context
- OpenAPI.Example
- OpenAPI.ExternalDocumentation
- OpenAPI.Header
- OpenAPI.HttpMethod
- OpenAPI.Link
- OpenAPI.OAuthFlows
- OpenAPI.OAuthFlows.AuthorizationCode
- OpenAPI.OAuthFlows.ClientCredentials
- OpenAPI.OAuthFlows.CommonFields
- OpenAPI.OAuthFlows.Implicit
- OpenAPI.OAuthFlows.Password
- OpenAPI.Operation
- OpenAPI.Operation.ResponseOutcome
- OpenAPI.Parameter
- OpenAPI.Parameter.Context
- OpenAPI.Parameter.Context.Location
- OpenAPI.Parameter.SchemaContext
- OpenAPI.Parameter.SchemaContext.Style
- OpenAPI.Path
- OpenAPI.PathItem
- OpenAPI.PathItem.Endpoint
- OpenAPI.Request
- OpenAPI.Response
- OpenAPI.Response.StatusCode
- OpenAPI.Response.StatusCode.Range
- OpenAPI.RuntimeExpression
- OpenAPI.RuntimeExpression.Source
- OpenAPI.SecurityScheme
- OpenAPI.SecurityScheme.Location
- OpenAPI.SecurityScheme.SecurityType
- OpenAPI.SecurityScheme.SecurityType.Name
- OpenAPI.Server
- OpenAPI.Server.Variable
- OpenAPI.Tag
- OpenAPI.XML
- OrderedDictionary
- OrderedDictionary.Iterator
- ResolvedDocument
- ResolvedEndpoint
- ResolvedRoute
- URLTemplate
- URLTemplate.Component
- Validation
- ValidationContext
- ValidationError
- ValidationErrorCollection
- Validator
- Validator.CodingKey
Protocols
Global Functions
Extensions
- Array
- Bool
- Dictionary
- Double
- Float
- Int
- Int32
- Int64
- OpenAPI.Callbacks
- OpenAPI.Content.Encoding
- OpenAPI.Document.Info
- OpenAPI.Document.Info.Contact
- OpenAPI.Document.Info.License
- OpenAPI.Error.Decoding
- OpenAPI.Error.Decoding.Document
- OpenAPI.Error.Decoding.Operation
- OpenAPI.Error.Decoding.Path
- OpenAPI.Error.Decoding.Request
- OpenAPI.Error.Decoding.Response
- OpenAPI.OAuthFlows.AuthorizationCode
- OpenAPI.OAuthFlows.ClientCredentials
- OpenAPI.OAuthFlows.CommonFields
- OpenAPI.OAuthFlows.Implicit
- OpenAPI.OAuthFlows.Password
- OpenAPI.Parameter.Context
- OpenAPI.Parameter.SchemaContext
- OpenAPI.Response.StatusCode
- OpenAPI.Server.Variable
- Optional
- String
- URL
- UUID