Skip to content

Commit a49d111

Browse files
committed
Support setting vendor extensions including on JSON Schemas and carry through external dereference process
1 parent 042a54a commit a49d111

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

Sources/OpenAPIKit30/CodableVendorExtendable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public protocol VendorExtendable {
1818
/// These should be of the form:
1919
/// `[ "x-extensionKey": <anything>]`
2020
/// where the values are anything codable.
21-
var vendorExtensions: VendorExtensions { get }
21+
var vendorExtensions: VendorExtensions { get set }
2222
}
2323

2424
public enum VendorExtensionsConfiguration {

Sources/OpenAPIKit30/Example.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension OpenAPI {
2525
/// These should be of the form:
2626
/// `[ "x-extensionKey": <anything>]`
2727
/// where the values are anything codable.
28-
public let vendorExtensions: [String: AnyCodable]
28+
public var vendorExtensions: [String: AnyCodable]
2929

3030
public init(
3131
summary: String? = nil,

Sources/OpenAPIKit30/Schema Object/DereferencedJSONSchema.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ extension JSONSchema: ExternallyDereferenceable {
451451
maxProperties: object.maxProperties,
452452
minProperties: object._minProperties
453453
)
454-
)
454+
),
455+
vendorExtensions: vendorExtensions
455456
)
456457
case .array(let core, let array):
457458
let (newItems, components) = try await array.items.externallyDereferenced(with: loader)
@@ -465,37 +466,43 @@ extension JSONSchema: ExternallyDereferenceable {
465466
minItems: array._minItems,
466467
uniqueItems: array._uniqueItems
467468
)
468-
)
469+
),
470+
vendorExtensions: vendorExtensions
469471
)
470472
case .all(let schema, let core):
471473
let (newSubschemas, components) = try await schema.externallyDereferenced(with: loader)
472474
newComponents = components
473475
newSchema = .init(
474-
schema: .all(of: newSubschemas, core: core)
476+
schema: .all(of: newSubschemas, core: core),
477+
vendorExtensions: vendorExtensions
475478
)
476479
case .one(let schema, let core):
477480
let (newSubschemas, components) = try await schema.externallyDereferenced(with: loader)
478481
newComponents = components
479482
newSchema = .init(
480-
schema: .one(of: newSubschemas, core: core)
483+
schema: .one(of: newSubschemas, core: core),
484+
vendorExtensions: vendorExtensions
481485
)
482486
case .any(let schema, let core):
483487
let (newSubschemas, components) = try await schema.externallyDereferenced(with: loader)
484488
newComponents = components
485489
newSchema = .init(
486-
schema: .any(of: newSubschemas, core: core)
490+
schema: .any(of: newSubschemas, core: core),
491+
vendorExtensions: vendorExtensions
487492
)
488493
case .not(let schema, let core):
489494
let (newSubschema, components) = try await schema.externallyDereferenced(with: loader)
490495
newComponents = components
491496
newSchema = .init(
492-
schema: .not(newSubschema, core: core)
497+
schema: .not(newSubschema, core: core),
498+
vendorExtensions: vendorExtensions
493499
)
494500
case .reference(let reference, let core):
495501
let (newReference, components) = try await reference.externallyDereferenced(with: loader)
496502
newComponents = components
497503
newSchema = .init(
498-
schema: .reference(newReference, core)
504+
schema: .reference(newReference, core),
505+
vendorExtensions: vendorExtensions
499506
)
500507
case .fragment(_):
501508
newComponents = .noComponents

Sources/OpenAPIKit30/Schema Object/JSONSchema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public struct JSONSchema: JSONSchemaContext, HasWarnings, VendorExtendable {
1414
public let warnings: [OpenAPI.Warning]
1515
public let value: Schema
1616

17-
public let vendorExtensions: [String: AnyCodable]
17+
public var vendorExtensions: [String: AnyCodable]
1818

1919
internal init(warnings: [OpenAPI.Warning], schema: Schema, vendorExtensions: [String: AnyCodable]) {
2020
self.warnings = warnings

Tests/OpenAPIKit30Tests/Document/ExternalDereferencingDocumentTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ final class ExternalDereferencingDocumentTests: XCTestCase {
2525
// to keep track of where a reference was loaded from. This test makes sure
2626
// the following strategy of using vendor extensions works.
2727
if var extendable = decoded as? VendorExtendable {
28-
//TODO: revisit vendor extensions mutability
29-
#warning("revisit vendor extensions mutability")
30-
// extendable.vendorExtensions["x-source-url"] = AnyCodable(url)
28+
extendable.vendorExtensions["x-source-url"] = AnyCodable(url)
3129
finished = extendable as! T
3230
} else {
3331
finished = decoded

Tests/OpenAPIKit30Tests/VendorExtendableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private struct TestStruct: Codable, CodableVendorExtendable {
145145
}
146146
}
147147

148-
public let vendorExtensions: Self.VendorExtensions
148+
public var vendorExtensions: Self.VendorExtensions
149149

150150
init(vendorExtensions: Self.VendorExtensions) {
151151
self.vendorExtensions = vendorExtensions

0 commit comments

Comments
 (0)