Skip to content

keep inferred when updating any other property of a core context using a helper function #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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