Skip to content

Commit

Permalink
fix some tests around schema vendor extensions. also fix an actual bu…
Browse files Browse the repository at this point in the history
…g around example component name extension
  • Loading branch information
mattpolzin committed Sep 6, 2023
1 parent 8e2dad5 commit acc060f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Sources/OpenAPIKit/Parameter/DereferencedSchemaContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public struct DereferencedSchemaContext: Equatable {
following references: Set<AnyHashable>
) throws {
self.schema = try schemaContext.schema._dereferenced(in: components, following: references, dereferencedFromComponentNamed: nil)
let examples = try schemaContext.examples?.mapValues { try components.lookup($0) }
let examples = try schemaContext.examples?
.mapValues { try $0._dereferenced(in: components, following: references, dereferencedFromComponentNamed: nil) }
self.examples = examples

self.example = examples.flatMap(OpenAPI.Content.firstExample(from:))
Expand Down
15 changes: 12 additions & 3 deletions Tests/OpenAPIKitTests/Content/DereferencedContentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ final class DereferencedContentTests: XCTestCase {
let t1 = try OpenAPI.Content(
schemaReference: .component(named: "test")
).dereferenced(in: components)
XCTAssertEqual(t1.schema, .string(.init(), .init()))
XCTAssertEqual(
t1.schema,
.string(.init().with(vendorExtensions: ["x-component-name": "test"]), .init())
)
}

func test_referencedSchemaNoOverrides() throws {
Expand All @@ -90,7 +93,10 @@ final class DereferencedContentTests: XCTestCase {
let t1 = try OpenAPI.Content(
schemaReference: .component(named: "test")
).dereferenced(in: components)
XCTAssertEqual(t1.schema, .string(.init(description: "a test string"), .init()))
XCTAssertEqual(
t1.schema,
.string(.init(description: "a test string").with(vendorExtensions: ["x-component-name": "test"]), .init())
)
}

func test_referencedSchemaOverrideDescription() throws {
Expand All @@ -103,7 +109,10 @@ final class DereferencedContentTests: XCTestCase {
schemaReference: .component(named: "test", description: "overridden description")
).dereferenced(in: components)
XCTAssertEqual(t1.schema?.description, "overridden description")
XCTAssertEqual(t1.schema, .string(.init(description: "overridden description"), .init()))
XCTAssertEqual(
t1.schema,
.string(.init(description: "overridden description").with(vendorExtensions: ["x-component-name": "test"]), .init())
)
}

func test_missingSchema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ final class DereferencedSchemaContextTests: XCTestCase {
examples: ["test": .reference(.component(named: "test"))]
).dereferenced(in: components)
XCTAssertEqual(t1.example, "hello world")
XCTAssertEqual(t1.examples, ["test": .init(value: .init("hello world"))])
XCTAssertEqual(
t1.examples,
["test": .init(value: .init("hello world"), vendorExtensions: ["x-component-name": "test"])]
)
}

func test_multipleExamplesReferenced() throws {
Expand All @@ -53,8 +56,8 @@ final class DereferencedSchemaContextTests: XCTestCase {
XCTAssertEqual(
t1.examples,
[
"test1": .init(value: .init("hello world")),
"test2": .init(value: .init(URL(string: "http://website.com")!))
"test1": .init(value: .init("hello world"), vendorExtensions: ["x-component-name": "test1"]),
"test2": .init(value: .init(URL(string: "http://website.com")!), vendorExtensions: ["x-component-name": "test2"])
]
)
}
Expand All @@ -80,7 +83,10 @@ final class DereferencedSchemaContextTests: XCTestCase {
schemaReference: .component(named: "test"),
style: .default(for: .header)
).dereferenced(in: components)
XCTAssertEqual(t1.schema, .string(.init(), .init()))
XCTAssertEqual(
t1.schema,
.string(.init(), .init()).with(vendorExtensions: ["x-component-name": "test"])
)
}

func test_missingSchema() {
Expand Down

0 comments on commit acc060f

Please sign in to comment.