From 8a3ad28b68c7fc25ad8c6347d2f26ebbcb71b131 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 19 Jul 2024 10:49:02 -0500 Subject: [PATCH 1/4] remove deprecated content encoding property --- .../OpenAPIKit/Content/ContentEncoding.swift | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/Sources/OpenAPIKit/Content/ContentEncoding.swift b/Sources/OpenAPIKit/Content/ContentEncoding.swift index 20814859a..30c40f874 100644 --- a/Sources/OpenAPIKit/Content/ContentEncoding.swift +++ b/Sources/OpenAPIKit/Content/ContentEncoding.swift @@ -14,21 +14,6 @@ extension OpenAPI.Content { public struct Encoding: Equatable { public typealias Style = OpenAPI.Parameter.SchemaContext.Style - /// If an encoding object only contains 1 content type, it will be populated here. - /// Two or more content types will result in a null value here but the `contentTypes` - /// (plural) property will contain all content types specified. - /// - /// The singular `contentType` property is only provided for backwards compatibility and - /// using the plural `contentTypes` property should be preferred. - @available(*, deprecated, message: "use contentTypes instead") - public var contentType: OpenAPI.ContentType? { - guard let contentType = contentTypes.first, - contentTypes.count == 1 else { - return nil - } - return contentType - } - public let contentTypes: [OpenAPI.ContentType] public let headers: OpenAPI.Header.Map? public let style: Style @@ -38,13 +23,12 @@ extension OpenAPI.Content { /// The singular `contentType` argument is only provided for backwards compatibility and /// using the plural `contentTypes` argument should be preferred. public init( - contentType: OpenAPI.ContentType? = nil, contentTypes: [OpenAPI.ContentType] = [], headers: OpenAPI.Header.Map? = nil, style: Style = Self.defaultStyle, allowReserved: Bool = false ) { - self.contentTypes = contentTypes + [contentType].compactMap { $0 } + self.contentTypes = contentTypes self.headers = headers self.style = style self.explode = style.defaultExplode @@ -54,14 +38,13 @@ extension OpenAPI.Content { /// The singular `contentType` argument is only provided for backwards compatibility and /// using the plural `contentTypes` argument should be preferred. public init( - contentType: OpenAPI.ContentType? = nil, contentTypes: [OpenAPI.ContentType] = [], headers: OpenAPI.Header.Map? = nil, style: Style = Self.defaultStyle, explode: Bool, allowReserved: Bool = false ) { - self.contentTypes = contentTypes + [contentType].compactMap { $0 } + self.contentTypes = contentTypes self.headers = headers self.style = style self.explode = explode @@ -104,7 +87,7 @@ extension OpenAPI.Content.Encoding: Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) let contentTypesString = try container.decodeIfPresent(String.self, forKey: .contentType) - if let contentTypesString = contentTypesString { + if let contentTypesString { contentTypes = contentTypesString .split(separator: ",") .compactMap { string in From 3d6665755246bf10aae524205a0cc5567eb6d624 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 19 Jul 2024 10:50:09 -0500 Subject: [PATCH 2/4] don't test against bionic 5.8 image --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8cf275044..9aeedd053 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,6 @@ jobs: fail-fast: false matrix: image: - - swift:5.8-bionic - swift:5.8-focal - swift:5.8-jammy - swift:5.9-focal From d11fe0c30321225cfffdd0331c7f7480dea80716 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 19 Jul 2024 23:31:24 -0500 Subject: [PATCH 3/4] remove jsonschema fallback implementations. fix code that used old content type argument to Encoding constructor --- .../Content/DereferencedContentEncoding.swift | 2 +- .../Schema Object/JSONSchemaContext.swift | 16 ---------------- Sources/OpenAPIKitCompat/Compat30To31.swift | 2 +- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/Sources/OpenAPIKit/Content/DereferencedContentEncoding.swift b/Sources/OpenAPIKit/Content/DereferencedContentEncoding.swift index aaa9a1fd5..b715e7ac7 100644 --- a/Sources/OpenAPIKit/Content/DereferencedContentEncoding.swift +++ b/Sources/OpenAPIKit/Content/DereferencedContentEncoding.swift @@ -72,7 +72,7 @@ extension OpenAPI.Content.Encoding: ExternallyDereferenceable { } let newEncoding = OpenAPI.Content.Encoding( - contentType: contentType, + contentTypes: contentTypes, headers: newHeaders, style: style, explode: explode, diff --git a/Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift b/Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift index 37be04003..e425e4ddc 100644 --- a/Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift +++ b/Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift @@ -135,22 +135,6 @@ public protocol JSONSchemaContext { var vendorExtensions: [String: AnyCodable] { get } } -extension JSONSchemaContext { - - // TODO: Remove the default implementations of the following in v4 of OpenAPIKit. - // They are only here to make their addition non-breaking. - - // Default implementation to make addition of this new property which is only - // supposed to be set internally a non-breaking addition. - public var inferred: Bool { false } - - // Default implementation to make addition non-breaking - public var anchor: String? { nil } - - // Default implementation to make addition non-breaking - public var dynamicAnchor: String? { nil } -} - extension JSONSchema { /// The context that applies to all schemas. public struct CoreContext: JSONSchemaContext, HasWarnings { diff --git a/Sources/OpenAPIKitCompat/Compat30To31.swift b/Sources/OpenAPIKitCompat/Compat30To31.swift index 444aabfea..bb128b282 100644 --- a/Sources/OpenAPIKitCompat/Compat30To31.swift +++ b/Sources/OpenAPIKitCompat/Compat30To31.swift @@ -214,7 +214,7 @@ extension OpenAPIKit30.OpenAPI.Parameter.SchemaContext: To31 { extension OpenAPIKit30.OpenAPI.Content.Encoding: To31 { fileprivate func to31() -> OpenAPIKit.OpenAPI.Content.Encoding { OpenAPIKit.OpenAPI.Content.Encoding( - contentType: contentType, + contentTypes: [contentType].compactMap { $0 }, headers: headers?.mapValues(eitherRefTo31), style: style, explode: explode, From 7ec84469c237f05a835cec67b2ae8623ca78c087 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 19 Jul 2024 23:38:39 -0500 Subject: [PATCH 4/4] update some tests --- .../DocumentConversionTests.swift | 2 +- .../OpenAPIKitTests/Content/ContentTests.swift | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift b/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift index 99617df42..fc0c42e31 100644 --- a/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift +++ b/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift @@ -1233,7 +1233,7 @@ fileprivate func assertEqualNewToOld(_ newExample: OpenAPIKit.OpenAPI.Example, _ } fileprivate func assertEqualNewToOld(_ newEncoding: OpenAPIKit.OpenAPI.Content.Encoding, _ oldEncoding: OpenAPIKit30.OpenAPI.Content.Encoding) throws { - XCTAssertEqual(newEncoding.contentType, oldEncoding.contentType) + XCTAssertEqual(newEncoding.contentTypes.first, oldEncoding.contentType) if let newEncodingHeaders = newEncoding.headers { let oldEncodingHeaders = try XCTUnwrap(oldEncoding.headers) for ((newKey, newHeader), (oldKey, oldHeader)) in zip(newEncodingHeaders, oldEncodingHeaders) { diff --git a/Tests/OpenAPIKitTests/Content/ContentTests.swift b/Tests/OpenAPIKitTests/Content/ContentTests.swift index 72afe5a15..300bf67ee 100644 --- a/Tests/OpenAPIKitTests/Content/ContentTests.swift +++ b/Tests/OpenAPIKitTests/Content/ContentTests.swift @@ -66,7 +66,7 @@ final class ContentTests: XCTestCase { example: nil, encoding: [ "hello": .init( - contentType: .json, + contentTypes: [.json], headers: [ "world": .init(OpenAPI.Header(schemaOrContent: .init(.header(.string)))) ], @@ -355,7 +355,7 @@ extension ContentTests { func test_encodingAndSchema_encode() { let content = OpenAPI.Content( schema: .init(.string), - encoding: ["json": .init(contentType: .json)] + encoding: ["json": .init(contentTypes: [.json])] ) let encodedContent = try! orderUnstableTestStringFromEncoding(of: content) @@ -397,7 +397,7 @@ extension ContentTests { content, OpenAPI.Content( schema: .init(.string), - encoding: ["json": .init(contentType: .json)] + encoding: ["json": .init(contentTypes: [.json])] ) ) } @@ -500,18 +500,18 @@ extension ContentTests { func test_encodingInit() { let _ = OpenAPI.Content.Encoding() - let _ = OpenAPI.Content.Encoding(contentType: .json) + let _ = OpenAPI.Content.Encoding(contentTypes: [.json]) let _ = OpenAPI.Content.Encoding(headers: ["special": .a(.external(URL(string: "hello.yml")!))]) let _ = OpenAPI.Content.Encoding(allowReserved: true) - let _ = OpenAPI.Content.Encoding(contentType: .form, + let _ = OpenAPI.Content.Encoding(contentTypes: [.form], headers: ["special": .a(.external(URL(string: "hello.yml")!))], allowReserved: true) - let _ = OpenAPI.Content.Encoding(contentType: .json, + let _ = OpenAPI.Content.Encoding(contentTypes: [.json], style: .form) - let _ = OpenAPI.Content.Encoding(contentType: .json, + let _ = OpenAPI.Content.Encoding(contentTypes: [.json], style: .form, explode: true) } @@ -544,7 +544,7 @@ extension ContentTests { } func test_encoding_contentType_encode() throws { - let encoding = OpenAPI.Content.Encoding(contentType: .csv) + let encoding = OpenAPI.Content.Encoding(contentTypes: [.csv]) let encodedEncoding = try! orderUnstableTestStringFromEncoding(of: encoding) @@ -567,7 +567,7 @@ extension ContentTests { """.data(using: .utf8)! let encoding = try! orderUnstableDecode(OpenAPI.Content.Encoding.self, from: encodingData) - XCTAssertEqual(encoding, OpenAPI.Content.Encoding(contentType: .csv)) + XCTAssertEqual(encoding, OpenAPI.Content.Encoding(contentTypes: [.csv])) } func test_encoding_multiple_contentTypes_encode() throws {