Skip to content

JSONSchemaContext

mattpolzin edited this page Jun 11, 2021 · 6 revisions

JSONSchemaContext

A schema context stores information about a schema. All schemas can have the contextual information in this protocol.

public protocol JSONSchemaContext 

Requirements

formatString

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.

required

true if values for this schema are required, false if they are optional (and can therefore be omitted from request/response data).

var required: Bool 

nullable

true if values for this schema can be null.

var nullable: Bool 

title

Get the title, if specified. If unspecified, returns nil.

var title: String? 

description

Get the description, if specified. If unspecified, returns nil.

var description: String? 

discriminator

An object used to discriminate upon the options for a child object's schema in a polymorphic context.

var discriminator: OpenAPI.Discriminator? 

Discriminators are only applicable when used in conjunction with allOf, anyOf, or oneOf.

Still, they need to be supported on the JSONSchema.Context (which is not used with those three special schema types) because the specification states that a discriminator can be placed on a parent object (one level up from an allOf, anyOf, or oneOf) as a way to reduce redundancy.

See OpenAPI Discriminator Object.

externalDocs

Get the external docs, if specified. If unspecified, returns nil.

var externalDocs: OpenAPI.ExternalDocumentation? 

allowedValues

The OpenAPI spec calls this "enum"

var allowedValues: [AnyCodable]? 

If not specified, it is assumed that any value of the given format is allowed. NOTE: I would like the array of allowed values to have the type Format.SwiftType but this is not tractable because I also want to be able to automatically turn any Swift type that will get encoded as something compatible with Format.SwiftType into an allowed value.

defaultValue

The OpenAPI spec calls this "default"

var defaultValue: AnyCodable? 

If specified, this value indicates the value the property will take on if no value is explicitly given by the client. NOTE: I would like the default value to have the type Format.SwiftType but this is not tractable because I also want to be able to automatically turn any Swift type that will get encoded as something compatible with Format.SwiftType into a default.

example

Get an example, if specified. If unspecified, returns nil.

var example: AnyCodable? 

readOnly

true if this schema can only be read from and is therefore unsupported for request data.

var readOnly: Bool 

writeOnly

true if this schema can only be written to and is therefore unavailable in response data.

var writeOnly: Bool 

deprecated

true if this schema is deprecated, false otherwise.

var deprecated: Bool 
Types
Protocols
Global Functions
Extensions
Clone this wiki locally