Skip to content

Commit

Permalink
Merge pull request #352 from mattpolzin/fix-inferred-bug
Browse files Browse the repository at this point in the history
keep inferred when updating any other property of a core context using a helper function
  • Loading branch information
mattpolzin authored Dec 7, 2023
2 parents b00b08d + 4756da4 commit 2834548
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
30 changes: 20 additions & 10 deletions Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -315,7 +316,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -334,7 +336,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -353,7 +356,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -372,7 +376,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -391,7 +396,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: [example],
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -410,7 +416,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -429,7 +436,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -448,7 +456,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}

Expand All @@ -467,7 +476,8 @@ extension JSONSchema.CoreContext {
allowedValues: allowedValues,
defaultValue: defaultValue,
examples: examples,
vendorExtensions: vendorExtensions
vendorExtensions: vendorExtensions,
_inferred: inferred
)
}
}
Expand Down
21 changes: 14 additions & 7 deletions Sources/OpenAPIKit30/Schema Object/JSONSchemaContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}

Expand All @@ -291,7 +292,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}

Expand All @@ -309,7 +311,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}

Expand All @@ -327,7 +330,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}

Expand All @@ -345,7 +349,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}

Expand All @@ -363,7 +368,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}

Expand All @@ -381,7 +387,8 @@ extension JSONSchema.CoreContext {
externalDocs: externalDocs,
allowedValues: allowedValues,
defaultValue: defaultValue,
example: example
example: example,
_inferred: inferred
)
}
}
Expand Down
24 changes: 23 additions & 1 deletion Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,28 @@ final class DocumentConversionTests: XCTestCase {
}

func test_JSONSchemaFragment() throws {
// TODO: write test
let inferredFragment = OpenAPIKit30.JSONSchema.fragment(.init(_inferred: true))

let oldDoc = OpenAPIKit30.OpenAPI.Document(
info: .init(title: "Hello", version: "1.0.0"),
servers: [],
paths: [:],
components: .init(
schemas: [
"schema1": inferredFragment,
]
)
)

let newDoc = oldDoc.convert(to: .v3_1_0)

try assertEqualNewToOld(newDoc, oldDoc)

let newInferredFragment = try XCTUnwrap(newDoc.components.schemas["schema1"])

try assertEqualNewToOld(newInferredFragment, inferredFragment)

// TODO: write more tests
}

func test_Operation() throws {
Expand Down Expand Up @@ -1192,6 +1213,7 @@ fileprivate func assertEqualNewToOld(_ newCoreContext: OpenAPIKit.JSONSchemaCont
XCTAssertEqual(newCoreContext.readOnly, oldCoreContext.readOnly)
XCTAssertEqual(newCoreContext.writeOnly, oldCoreContext.writeOnly)
XCTAssertEqual(newCoreContext.deprecated, oldCoreContext.deprecated)
XCTAssertEqual(newCoreContext.inferred, oldCoreContext.inferred)
}

fileprivate func assertEqualNewToOld(_ newStringContext: OpenAPIKit.JSONSchema.StringContext, _ oldStringContext: OpenAPIKit30.JSONSchema.StringContext) {
Expand Down

0 comments on commit 2834548

Please sign in to comment.