Skip to content

OpenAPI_Components

mattpolzin edited this page Jul 3, 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

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

dereference(_:)

Pass a value that can be either a reference to a component or the component itself. dereference() will return the component value if it is found (in the Either wrapper or in the Components Object).

public func dereference<ReferenceType: ComponentDictionaryLocatable>(_ maybeReference: Either<JSONReference<ReferenceType>, ReferenceType>) -> ReferenceType?

Important: Dereferencing an external reference (i.e. one that points to another file) is not currently supported by OpenAPIKit and will therefore always result in `nil`.

forceDereference(_:)

Pass a value that can be either a reference to a component or the component itself. forceDereference() will return the component value if it is found (in the Either wrapper or in the Components Object).

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

Important: Dereferencing 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.

dereference(_:)

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

public func dereference<ReferenceType: ComponentDictionaryLocatable>(_ reference: JSONReference<ReferenceType>) -> ReferenceType?

Important: Dereferencing an external reference (i.e. one that points to another file) is not currently supported by OpenAPIKit and will therefore always result in `nil`.

forceDereference(_:)

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

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

Important: Dereferencing 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