Skip to content

Commit ded104d

Browse files
authored
Merge pull request #380 from mattpolzin/remove-deprecated-property
Remove deprecated contentType property
2 parents bc0cb9f + 7ec8446 commit ded104d

File tree

7 files changed

+15
-49
lines changed

7 files changed

+15
-49
lines changed

.github/workflows/tests.yml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
image:
16-
- swift:5.8-bionic
1716
- swift:5.8-focal
1817
- swift:5.8-jammy
1918
- swift:5.9-focal

Sources/OpenAPIKit/Content/ContentEncoding.swift

+3-20
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ extension OpenAPI.Content {
1414
public struct Encoding: Equatable {
1515
public typealias Style = OpenAPI.Parameter.SchemaContext.Style
1616

17-
/// If an encoding object only contains 1 content type, it will be populated here.
18-
/// Two or more content types will result in a null value here but the `contentTypes`
19-
/// (plural) property will contain all content types specified.
20-
///
21-
/// The singular `contentType` property is only provided for backwards compatibility and
22-
/// using the plural `contentTypes` property should be preferred.
23-
@available(*, deprecated, message: "use contentTypes instead")
24-
public var contentType: OpenAPI.ContentType? {
25-
guard let contentType = contentTypes.first,
26-
contentTypes.count == 1 else {
27-
return nil
28-
}
29-
return contentType
30-
}
31-
3217
public let contentTypes: [OpenAPI.ContentType]
3318
public let headers: OpenAPI.Header.Map?
3419
public let style: Style
@@ -38,13 +23,12 @@ extension OpenAPI.Content {
3823
/// The singular `contentType` argument is only provided for backwards compatibility and
3924
/// using the plural `contentTypes` argument should be preferred.
4025
public init(
41-
contentType: OpenAPI.ContentType? = nil,
4226
contentTypes: [OpenAPI.ContentType] = [],
4327
headers: OpenAPI.Header.Map? = nil,
4428
style: Style = Self.defaultStyle,
4529
allowReserved: Bool = false
4630
) {
47-
self.contentTypes = contentTypes + [contentType].compactMap { $0 }
31+
self.contentTypes = contentTypes
4832
self.headers = headers
4933
self.style = style
5034
self.explode = style.defaultExplode
@@ -54,14 +38,13 @@ extension OpenAPI.Content {
5438
/// The singular `contentType` argument is only provided for backwards compatibility and
5539
/// using the plural `contentTypes` argument should be preferred.
5640
public init(
57-
contentType: OpenAPI.ContentType? = nil,
5841
contentTypes: [OpenAPI.ContentType] = [],
5942
headers: OpenAPI.Header.Map? = nil,
6043
style: Style = Self.defaultStyle,
6144
explode: Bool,
6245
allowReserved: Bool = false
6346
) {
64-
self.contentTypes = contentTypes + [contentType].compactMap { $0 }
47+
self.contentTypes = contentTypes
6548
self.headers = headers
6649
self.style = style
6750
self.explode = explode
@@ -104,7 +87,7 @@ extension OpenAPI.Content.Encoding: Decodable {
10487
let container = try decoder.container(keyedBy: CodingKeys.self)
10588

10689
let contentTypesString = try container.decodeIfPresent(String.self, forKey: .contentType)
107-
if let contentTypesString = contentTypesString {
90+
if let contentTypesString {
10891
contentTypes = contentTypesString
10992
.split(separator: ",")
11093
.compactMap { string in

Sources/OpenAPIKit/Content/DereferencedContentEncoding.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extension OpenAPI.Content.Encoding: ExternallyDereferenceable {
7272
}
7373

7474
let newEncoding = OpenAPI.Content.Encoding(
75-
contentType: contentType,
75+
contentTypes: contentTypes,
7676
headers: newHeaders,
7777
style: style,
7878
explode: explode,

Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift

-16
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,6 @@ public protocol JSONSchemaContext {
135135
var vendorExtensions: [String: AnyCodable] { get }
136136
}
137137

138-
extension JSONSchemaContext {
139-
140-
// TODO: Remove the default implementations of the following in v4 of OpenAPIKit.
141-
// They are only here to make their addition non-breaking.
142-
143-
// Default implementation to make addition of this new property which is only
144-
// supposed to be set internally a non-breaking addition.
145-
public var inferred: Bool { false }
146-
147-
// Default implementation to make addition non-breaking
148-
public var anchor: String? { nil }
149-
150-
// Default implementation to make addition non-breaking
151-
public var dynamicAnchor: String? { nil }
152-
}
153-
154138
extension JSONSchema {
155139
/// The context that applies to all schemas.
156140
public struct CoreContext<Format: OpenAPIFormat>: JSONSchemaContext, HasWarnings {

Sources/OpenAPIKitCompat/Compat30To31.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ extension OpenAPIKit30.OpenAPI.Parameter.SchemaContext: To31 {
214214
extension OpenAPIKit30.OpenAPI.Content.Encoding: To31 {
215215
fileprivate func to31() -> OpenAPIKit.OpenAPI.Content.Encoding {
216216
OpenAPIKit.OpenAPI.Content.Encoding(
217-
contentType: contentType,
217+
contentTypes: [contentType].compactMap { $0 },
218218
headers: headers?.mapValues(eitherRefTo31),
219219
style: style,
220220
explode: explode,

Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ fileprivate func assertEqualNewToOld(_ newExample: OpenAPIKit.OpenAPI.Example, _
12331233
}
12341234

12351235
fileprivate func assertEqualNewToOld(_ newEncoding: OpenAPIKit.OpenAPI.Content.Encoding, _ oldEncoding: OpenAPIKit30.OpenAPI.Content.Encoding) throws {
1236-
XCTAssertEqual(newEncoding.contentType, oldEncoding.contentType)
1236+
XCTAssertEqual(newEncoding.contentTypes.first, oldEncoding.contentType)
12371237
if let newEncodingHeaders = newEncoding.headers {
12381238
let oldEncodingHeaders = try XCTUnwrap(oldEncoding.headers)
12391239
for ((newKey, newHeader), (oldKey, oldHeader)) in zip(newEncodingHeaders, oldEncodingHeaders) {

Tests/OpenAPIKitTests/Content/ContentTests.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ final class ContentTests: XCTestCase {
6666
example: nil,
6767
encoding: [
6868
"hello": .init(
69-
contentType: .json,
69+
contentTypes: [.json],
7070
headers: [
7171
"world": .init(OpenAPI.Header(schemaOrContent: .init(.header(.string))))
7272
],
@@ -355,7 +355,7 @@ extension ContentTests {
355355
func test_encodingAndSchema_encode() {
356356
let content = OpenAPI.Content(
357357
schema: .init(.string),
358-
encoding: ["json": .init(contentType: .json)]
358+
encoding: ["json": .init(contentTypes: [.json])]
359359
)
360360
let encodedContent = try! orderUnstableTestStringFromEncoding(of: content)
361361

@@ -397,7 +397,7 @@ extension ContentTests {
397397
content,
398398
OpenAPI.Content(
399399
schema: .init(.string),
400-
encoding: ["json": .init(contentType: .json)]
400+
encoding: ["json": .init(contentTypes: [.json])]
401401
)
402402
)
403403
}
@@ -500,18 +500,18 @@ extension ContentTests {
500500
func test_encodingInit() {
501501
let _ = OpenAPI.Content.Encoding()
502502

503-
let _ = OpenAPI.Content.Encoding(contentType: .json)
503+
let _ = OpenAPI.Content.Encoding(contentTypes: [.json])
504504

505505
let _ = OpenAPI.Content.Encoding(headers: ["special": .a(.external(URL(string: "hello.yml")!))])
506506

507507
let _ = OpenAPI.Content.Encoding(allowReserved: true)
508508

509-
let _ = OpenAPI.Content.Encoding(contentType: .form,
509+
let _ = OpenAPI.Content.Encoding(contentTypes: [.form],
510510
headers: ["special": .a(.external(URL(string: "hello.yml")!))],
511511
allowReserved: true)
512-
let _ = OpenAPI.Content.Encoding(contentType: .json,
512+
let _ = OpenAPI.Content.Encoding(contentTypes: [.json],
513513
style: .form)
514-
let _ = OpenAPI.Content.Encoding(contentType: .json,
514+
let _ = OpenAPI.Content.Encoding(contentTypes: [.json],
515515
style: .form,
516516
explode: true)
517517
}
@@ -544,7 +544,7 @@ extension ContentTests {
544544
}
545545

546546
func test_encoding_contentType_encode() throws {
547-
let encoding = OpenAPI.Content.Encoding(contentType: .csv)
547+
let encoding = OpenAPI.Content.Encoding(contentTypes: [.csv])
548548

549549
let encodedEncoding = try! orderUnstableTestStringFromEncoding(of: encoding)
550550

@@ -567,7 +567,7 @@ extension ContentTests {
567567
""".data(using: .utf8)!
568568
let encoding = try! orderUnstableDecode(OpenAPI.Content.Encoding.self, from: encodingData)
569569

570-
XCTAssertEqual(encoding, OpenAPI.Content.Encoding(contentType: .csv))
570+
XCTAssertEqual(encoding, OpenAPI.Content.Encoding(contentTypes: [.csv]))
571571
}
572572

573573
func test_encoding_multiple_contentTypes_encode() throws {

0 commit comments

Comments
 (0)