-
Notifications
You must be signed in to change notification settings - Fork 43
OpenAPI_Document
The root of an OpenAPI 3.0 document.
public struct Document: Equatable, CodableVendorExtendable
An OpenAPI Document can say a lot about the API it describes. A read-through of the specification is highly recommended because OpenAPIKit stays intentionally close to the naming and structure layed out by the Specification -- it goes without saying that the encoded JSON or YAML produced by OpenAPIKit conforms to the specification exactly.
CodableVendorExtendable
, Decodable
, Encodable
, Equatable
public init(openAPIVersion: Version = .v3_0_0, info: Info, servers: [Server], paths: PathItem.Map, components: Components, security: [SecurityRequirement] = [], tags: [Tag]? = nil, externalDocs: ExternalDocumentation? = nil, vendorExtensions: [String: AnyCodable] = [:])
public init(from decoder: Decoder) throws
OpenAPI Spec "openapi" field.
var openAPIVersion: Version
OpenAPIKit only explicitly supports versions that can be found in
the Version
enum. Other versions may or may not be decodable
by OpenAPIKit to a certain extent.
Information about the API described by this OpenAPI Document.
var info: Info
Licensing, Terms of Service, contact information, API version (the version of the API this document describes, not the OpenAPI Specification version), etc.
An array of Server Objects, which provide connectivity information to a target server.
var servers: [Server]
If the servers property is not provided, or is an empty array, the default value is a Server Object with a url value of "/".
All routes supported by this API. This property maps the path of each
route (OpenAPI.Path
) to the documentation for that route
(OpenAPI.PathItem
).
var paths: PathItem.Map
Storage for components that need to be referenced elsewhere in the
OpenAPI Document using JSONReferences
.
var components: Components
Storing components here can be in the interest of being explicit about
the fact that the components are always the same (such as an
"Unauthorized" Response
definition used on all endpoints) or it might
just be practical to put things here and reference them elsewhere to
cut down on the overall size of the document.
If your document is defined in Swift then this is a less beneficial way to share definitions than to just use the same Swift value multiple times, but you still might want to consider using the Components Object for its impact on the JSON/YAML structure of your document once encoded.
A declaration of which security mechanisms can be used across the API.
var security: [SecurityRequirement]
The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition.
To make security optional, an empty security requirement can be included in the array.
Important: OpenAPIKit has a type capable of representing that: The `JSONReference`. For that reason, OpenAPIKit defines keys in security requirement objects as explicit references to entries in the Components Object instead of `String` values.
A list of tags used by the specification with additional metadata.
var tags: [Tag]?
The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by Operation Objects must be declared at the document level.
Important: Each tag name in the list MUST be unique.
Additional external documentation.
var externalDocs: ExternalDocumentation?
Retrieve an array of all Operation Ids defined by this API. These Ids are guaranteed to be unique by the OpenAPI Specification.
var allOperationIds: [String]
See Operation Object in the specifcation.
Dictionary of vendor extensions.
var vendorExtensions: [String: AnyCodable]
These should be of the form:
[ "x-extensionKey": <anything>]
where the values are anything codable.
Get all routes for this document.
var routes: [Route]
An Array of Routes
with the path and the definition of the route.
public func encode(to encoder: Encoder) throws
Validate this OpenAPI.Document
.
public func validate(using validator: Validator = .init()) throws
Call without any arguments to validate some aspects of the OpenAPI
Specification not guaranteed by the Swift types in OpenAPIKit.
You can create a Validator
of your own, adding additional steps
to the validation (or starting from scratch), and then pass that
Validator
to the validate(using:)
method to use custom validation
criteria.
- validator: - validator: Validator to use. By default, a validator that just asserts requirements of the OpenAPI Specification will be used.
ValidationErrors
if any validations failed. EncodingError
if encoding failed for a structural reason.
.
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