Skip to content

OpenAPI_Components

mattpolzin edited this page Sep 28, 2020 · 11 revisions

OpenAPI.Components

OpenAPI Spec "Components Object".

public struct Components: Equatable, CodableVendorExtendable

See OpenAPI Components Object.

This is a place to put reusable components to be referenced from other parts of the spec.

Inheritance

CodableVendorExtendable, Decodable, Encodable, Equatable

Initializers

init(schemas:responses:parameters:examples:requestBodies:headers:securitySchemes:vendorExtensions:)

public init(schemas: ComponentDictionary<JSONSchema> = [:], responses: ComponentDictionary<Response> = [:], parameters: ComponentDictionary<Parameter> = [:], examples: ComponentDictionary<Example> = [:], requestBodies: ComponentDictionary<Request> = [:], headers: ComponentDictionary<Header> = [:], securitySchemes: ComponentDictionary<SecurityScheme> = [:], vendorExtensions: [String: AnyCodable] = [:])

init(from:)

public init(from decoder: Decoder) throws

Properties

schemas

var schemas: ComponentDictionary<JSONSchema>

responses

var responses: ComponentDictionary<Response>

parameters

var parameters: ComponentDictionary<Parameter>

examples

var examples: ComponentDictionary<Example>

requestBodies

var requestBodies: ComponentDictionary<Request>

headers

var headers: ComponentDictionary<Header>

securitySchemes

var securitySchemes: ComponentDictionary<SecurityScheme>

vendorExtensions

Dictionary of vendor extensions.

var vendorExtensions: [String: AnyCodable]

These should be of the form: [ "x-extensionKey": <anything>] where the values are anything codable.

noComponents

An empty OpenAPI Components Object.

let noComponents: Components

isEmpty

var isEmpty: Bool

Methods

contains(_:)

Check if the Components contains the given reference or not.

public func contains<ReferenceType: Equatable & ComponentDictionaryLocatable>(_ reference: JSONReference<ReferenceType>) throws -> Bool

Look up a reference in this components dictionary. If you want a non-throwing alternative, you can pull a JSONReference.InternalReference out of your JSONReference and pass that to contains instead.

Throws

If the given reference cannot be checked against Components then this method will throw ReferenceError. This will occur when the given reference is a remote file reference.

contains(_:)

Check if the Components contains the given internal reference or not.

public func contains<ReferenceType: Equatable & ComponentDictionaryLocatable>(_ reference: JSONReference<ReferenceType>.InternalReference) -> Bool

lookup(_:)

Pass a reference to a component. lookup() will return the component value if it is found in the Components Object.

public func lookup<ReferenceType: ComponentDictionaryLocatable>(_ reference: JSONReference<ReferenceType>) throws -> ReferenceType

If you want to look something up without throwing, you might want to use the subscript operator on the Components.

If you also want to fully dereference the value in question instead of just looking it up see the various dereference functions on this type for more information.

Important: Looking up an external reference (i.e. one that points to another file) is not currently supported by OpenAPIKit and will therefore always throw an error.

Throws

ReferenceError.cannotLookupRemoteReference or MissingReferenceError.referenceMissingOnLookup(name:) depending on whether the reference points to another file or just points to a component in the same file that cannot be found in the Components Object.

lookup(_:)

Pass an Either with a reference or a component. lookup() will return the component value if it is found in the Components Object.

public func lookup<ReferenceType: ComponentDictionaryLocatable>(_ maybeReference: Either<JSONReference<ReferenceType>, ReferenceType>) throws -> ReferenceType

If you want to look something up without throwing, you might want to use the subscript operator on the Components.

If you also want to fully dereference the value in question instead of just looking it up see the various dereference functions on this type for more information.

Important: Looking up an external reference (i.e. one that points to another file) is not currently supported by OpenAPIKit and will therefore always throw an error.

Throws

ReferenceError.cannotLookupRemoteReference or MissingReferenceError.referenceMissingOnLookup(name:) depending on whether the reference points to another file or just points to a component in the same file that cannot be found in the Components Object.

reference(named:ofType:)

Create a JSONReference.

public func reference<ReferenceType: ComponentDictionaryLocatable & Equatable>(named name: String, ofType: ReferenceType.Type) throws -> JSONReference<ReferenceType>

Throws

If the given name does not refer to an existing component of the given type.

encode(to:)

public func encode(to encoder: Encoder) throws
Types
Protocols
Global Functions
Extensions
Clone this wiki locally