-
Notifications
You must be signed in to change notification settings - Fork 44
JSONSchema
OpenAPI "Schema Object"
public enum JSONSchema
ComponentDictionaryLocatable
, Decodable
, Encodable
, Equatable
, JSONSchemaContext
public init(from decoder: Decoder) throws
case boolean(: Context<JSONTypeFormat.BooleanFormat>)
case object(: Context<JSONTypeFormat.ObjectFormat>, : ObjectContext)
case array(: Context<JSONTypeFormat.ArrayFormat>, : ArrayContext)
case number(: Context<JSONTypeFormat.NumberFormat>, : NumericContext)
case integer(: Context<JSONTypeFormat.IntegerFormat>, : IntegerContext)
case string(: Context<JSONTypeFormat.StringFormat>, : StringContext)
case all(of: [JSONSchemaFragment], discriminator: OpenAPI.Discriminator?)
case one(of: [JSONSchema], discriminator: OpenAPI.Discriminator?)
case any(of: [JSONSchema], discriminator: OpenAPI.Discriminator?)
case not(: JSONSchema)
case reference(: JSONReference<JSONSchema>)
This schema does not have a type
specified. This is allowed
but does not offer much in the way of documenting the schema
so it is represented here as "undefined" with an optional
description.
case undefined(description: String?)
var openAPIComponentsKey: String
var 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?
Important: "object," "array," "allOf,", "oneOf," "anyOf," "not," "reference," and "undefined" are not considered types and such schemas will return `nil` for this property.
var required: Bool
var description: String?
var discriminator: OpenAPI.Discriminator?
var nullable: Bool
var readOnly: Bool
var writeOnly: Bool
var deprecated: Bool
var title: String?
var externalDocs: OpenAPI.ExternalDocumentation?
var allowedValues: [AnyCodable]?
var example: AnyCodable?
Get the general context most JSONSchemas have.
var generalContext: JSONSchemaContext?
This is the information shared by most schemas.
Notably missing this general context are:
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: JSONSchema
A required, non-nullable string schema.
var string: JSONSchema
A required, non-nullable number schema.
var number: JSONSchema
A required, non-nullable integer schema.
var integer: JSONSchema
A required, non-nullable object schema.
var object: JSONSchema
A required, non-nullable array schema.
var array: JSONSchema
Return the optional version of this JSONSchema
public func optionalSchemaObject() -> JSONSchema
Return the required version of this JSONSchema
public func requiredSchemaObject() -> JSONSchema
Return the nullable version of this JSONSchema
public func nullableSchemaObject() -> JSONSchema
Return a version of this JSONSchema
that only allows the given
values.
public func with(allowedValues: [AnyCodable]) -> JSONSchema
Returns a version of this JSONSchema
that has the given example
attached.
public func with(example: AnyCodable) throws -> JSONSchema
Returns a dereferenced schema object if this schema object already does not contain any references.
public func dereferencedSchemaObject() -> DereferencedJSONSchema?
To create a dereferenced schema object from a schema object
that does have references, use dereferencedSchemaObject(resolvingIn:)
.
Returns a dereferenced schema object if all references in this schema object can be found in the Components Object.
public func dereferencedSchemaObject(resolvingIn components: OpenAPI.Components) throws -> DereferencedJSONSchema
Important: Local dereferencing will `throw` if any `JSONReferences` point to other files or to locations within the same file other than the Components Object. It will also fail if any components are missing from the Components Object.
ReferenceError.cannotLookupRemoteReference
or MissingReferenceError.referenceMissingOnLookup(name:)
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.
Attempts to create a String from a JSON fragment (e.g. Bool, Double, String, etc.)
internal static func fragmentString(from value: Any) -> String?
boolean(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:allowedValues:example:)
Construct a boolean schema.
public static func boolean(format: JSONTypeFormat.BooleanFormat = .unspecified, required: Bool = true, nullable: Bool = false, permissions: JSONSchema.Context<JSONTypeFormat.BooleanFormat>.Permissions = .readWrite, deprecated: Bool = false, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, allowedValues: [AnyCodable]? = nil, example: AnyCodable? = nil) -> JSONSchema
boolean(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:allowedValues: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 = false, permissions: JSONSchema.Context<JSONTypeFormat.BooleanFormat>.Permissions = .readWrite, deprecated: Bool = false, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, allowedValues: AnyCodable, example: AnyCodable? = nil) -> JSONSchema
string(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minLength:maxLength:pattern:allowedValues:example:)
Construct a string schema.
public static func string(format: JSONTypeFormat.StringFormat = .unspecified, required: Bool = true, nullable: Bool = false, permissions: JSONSchema.Context<JSONTypeFormat.StringFormat>.Permissions = .readWrite, deprecated: Bool = false, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minLength: Int = 0, maxLength: Int? = nil, pattern: String? = nil, allowedValues: [AnyCodable]? = nil, example: AnyCodable? = nil) -> JSONSchema
string(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minLength:maxLength:pattern:allowedValues: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 = false, permissions: JSONSchema.Context<JSONTypeFormat.StringFormat>.Permissions = .readWrite, deprecated: Bool = false, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minLength: Int = 0, maxLength: Int? = nil, pattern: String? = nil, allowedValues: AnyCodable, example: AnyCodable? = nil) -> JSONSchema
number(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues:example:)
Construct a number schema.
public static func number(format: JSONTypeFormat.NumberFormat = .unspecified, required: Bool = true, nullable: Bool = false, permissions: JSONSchema.Context<JSONTypeFormat.NumberFormat>.Permissions = .readWrite, deprecated: Bool = false, 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, example: AnyCodable? = nil) -> JSONSchema
number(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues: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 = false, permissions: JSONSchema.Context<JSONTypeFormat.NumberFormat>.Permissions = .readWrite, deprecated: Bool = false, 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, example: AnyCodable? = nil) -> JSONSchema
integer(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues:example:)
Construct an integer schema.
public static func integer(format: JSONTypeFormat.IntegerFormat = .unspecified, required: Bool = true, nullable: Bool = false, permissions: JSONSchema.Context<JSONTypeFormat.IntegerFormat>.Permissions = .readWrite, deprecated: Bool = false, 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, example: AnyCodable? = nil) -> JSONSchema
integer(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:multipleOf:maximum:minimum:allowedValues: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 = false, permissions: JSONSchema.Context<JSONTypeFormat.IntegerFormat>.Permissions = .readWrite, deprecated: Bool = false, 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, example: AnyCodable? = nil) -> JSONSchema
object(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minProperties:maxProperties:properties:additionalProperties:allowedValues:example:)
Construct an objecy schema.
public static func object(format: JSONTypeFormat.ObjectFormat = .unspecified, required: Bool = true, nullable: Bool = false, permissions: JSONSchema.Context<JSONTypeFormat.ObjectFormat>.Permissions = .readWrite, deprecated: Bool = false, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minProperties: Int = 0, maxProperties: Int? = nil, properties: [String: JSONSchema] = [:], additionalProperties: Either<Bool, JSONSchema>? = nil, allowedValues: [AnyCodable]? = nil, example: AnyCodable? = nil) -> JSONSchema
array(format:required:nullable:permissions:deprecated:title:description:discriminator:externalDocs:minItems:maxItems:uniqueItems:items:allowedValues:example:)
Construct an array schema.
public static func array(format: JSONTypeFormat.ArrayFormat = .unspecified, required: Bool = true, nullable: Bool = false, permissions: JSONSchema.Context<JSONTypeFormat.ArrayFormat>.Permissions = .readWrite, deprecated: Bool = false, title: String? = nil, description: String? = nil, discriminator: OpenAPI.Discriminator? = nil, externalDocs: OpenAPI.ExternalDocumentation? = nil, minItems: Int = 0, maxItems: Int? = nil, uniqueItems: Bool = false, items: JSONSchema? = nil, allowedValues: [AnyCodable]? = nil, example: AnyCodable? = nil) -> JSONSchema
Construct a schema stating all of the given fragment requirements are met.
public static func all(of schemas: [JSONSchemaFragment]) -> JSONSchema
Construct a schema stating all of the given fragment requirements are met given a discriminator.
public static func all(of schemas: JSONSchemaFragment, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchema
Construct a schema stating one of the given schema's requirements are met.
public static func one(of schemas: [JSONSchema]) -> JSONSchema
Construct a schema stating one of the given schema's requirements are met given a discriminator.
public static func one(of schemas: JSONSchema, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchema
Construct a schema stating any of the given schema's requirements are met.
public static func any(of schemas: [JSONSchema]) -> JSONSchema
Construct a schema stating any of the given schema's requirements are met given a discriminator.
public static func any(of schemas: JSONSchema, discriminator: OpenAPI.Discriminator? = nil) -> JSONSchema
public func encode(to encoder: Encoder) throws
.
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