Skip to content

OpenAPI_Components

mattpolzin edited this page Aug 21, 2023 · 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:links:callbacks:vendorExtensions:)

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

init(from:)

public init(from decoder: Decoder) throws 

Properties

schemas

public var schemas: ComponentDictionary<JSONSchema>

responses

public var responses: ComponentDictionary<Response>

parameters

public var parameters: ComponentDictionary<Parameter>

examples

public var examples: ComponentDictionary<Example>

requestBodies

public var requestBodies: ComponentDictionary<Request>

headers

public var headers: ComponentDictionary<Header>

securitySchemes

public var securitySchemes: ComponentDictionary<SecurityScheme>

callbacks

public var callbacks: ComponentDictionary<Callbacks>

links

public var links: ComponentDictionary<Link>

vendorExtensions

Dictionary of vendor extensions.

public 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.

public static let noComponents: Components 

isEmpty

public var isEmpty: Bool 

componentNameExtension

The extension name used to store a Components Object name (the key something is stored under within the Components Object). This is used by OpenAPIKit to store the previous Component name of an OpenAPI Object that has been dereferenced (pulled out of the Components and stored inline in the OpenAPI Document).

public static let componentNameExtension: String = "x-component-name"

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.

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.

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