Skip to content

Commit 63174f3

Browse files
authored
Bump to OpenAPIKit 3.0.0 (#362)
Bump to OpenAPIKit 3.0.0 ### Motivation OpenAPIKit released 3.0.0, so let's move to it. ### Modifications They (correctly) removed the `format: byte` and `format: binary` fields in the OpenAPI 3.1 mode, instead `contentEncoding: base64` and `contentEncoding: binary` should be used. For docs that load as 3.0 and get converted to 3.1 in memory, this translation happens automatically in OpenAPIKit, so we just need to be able to handle 3.1 documents here. ### Result Using the stable v3 version of OpenAPIKit, which will allow Swift OpenAPI Generator to coexist with other projects that depend on OpenAPIKit v3 (previously, locking to an exact version of OpenAPIKit meant more difficult version resolution for adopters.) ### Test Plan Adapted tests, all pass now. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (compatibility test) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #362
1 parent 893b3db commit 63174f3

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let package = Package(
5555
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"),
5656

5757
// Read OpenAPI documents
58-
.package(url: "https://github.com/mattpolzin/OpenAPIKit.git", exact: "3.0.0-rc.3"),
58+
.package(url: "https://github.com/mattpolzin/OpenAPIKit.git", from: "3.0.0"),
5959
.package(url: "https://github.com/jpsim/Yams.git", "4.0.0"..<"6.0.0"),
6060

6161
// CLI Tool

Sources/_OpenAPIGeneratorCore/Translator/Content/ContentInspector.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ extension FileTranslator {
127127
let (contentType, contentValue) = mapWithContentTypes.first(where: { $0.type.isBinary })
128128
{
129129
chosenContent = (
130-
contentType, .init(contentType: contentType, schema: .b(.string(format: .binary))), contentValue
130+
contentType, .init(contentType: contentType, schema: .b(.string(contentEncoding: .binary))),
131+
contentValue
131132
)
132133
} else {
133134
diagnostics.emitUnsupported("Unsupported content", foundIn: foundIn)
@@ -185,7 +186,7 @@ extension FileTranslator {
185186
}
186187
if contentType.isUrlEncodedForm { return .init(contentType: contentType, schema: contentValue.schema) }
187188
if !excludeBinary, contentType.isBinary {
188-
return .init(contentType: contentType, schema: .b(.string(format: .binary)))
189+
return .init(contentType: contentType, schema: .b(.string(contentEncoding: .binary)))
189190
}
190191
diagnostics.emitUnsupported("Unsupported content", foundIn: foundIn)
191192
return nil

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,7 @@ struct TypeMatcher {
302302
case .binary: typeName = .body
303303
case .base64: typeName = .base64
304304
default:
305-
// Check the format as well, for docs converted from OpenAPI 3.0.
306305
switch core.format {
307-
case .binary: typeName = .body
308-
case .byte: typeName = .base64
309306
case .dateTime: typeName = .date
310307
default: typeName = .string
311308
}

Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeMatcher.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ final class Test_TypeMatcher: Test_Core {
2424
}
2525

2626
static let builtinTypes: [(JSONSchema, String)] = [
27-
(.string, "Swift.String"), (.string(.init(format: .binary), .init()), "OpenAPIRuntime.HTTPBody"),
28-
(.string(.init(), .init(contentEncoding: .binary)), "OpenAPIRuntime.HTTPBody"),
29-
(.string(.init(format: .byte), .init()), "OpenAPIRuntime.Base64EncodedData"),
30-
(.string(.init(), .init(contentEncoding: .base64)), "OpenAPIRuntime.Base64EncodedData"),
27+
(.string, "Swift.String"), (.string(contentEncoding: .binary), "OpenAPIRuntime.HTTPBody"),
28+
(.string(contentEncoding: .base64), "OpenAPIRuntime.Base64EncodedData"),
3129
(.string(.init(format: .date), .init()), "Swift.String"),
3230
(.string(.init(format: .dateTime), .init()), "Foundation.Date"),
3331

Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ paths:
219219
content:
220220
application/octet-stream:
221221
schema:
222-
format: binary
222+
contentEncoding: binary
223223
type: string
224224
responses:
225225
'200':
226226
description: Echoes avatar back
227227
content:
228228
application/octet-stream:
229229
schema:
230-
format: binary
230+
contentEncoding: binary
231231
type: string
232232
'412':
233233
description: Avatar is not acceptable
@@ -284,7 +284,7 @@ components:
284284
genome:
285285
description: "Pet genome (base64-encoded)"
286286
type: string
287-
format: byte
287+
contentEncoding: base64
288288
kind:
289289
$ref: '#/components/schemas/PetKind'
290290
MixedAnyOf:
@@ -329,7 +329,7 @@ components:
329329
type: string
330330
genome:
331331
type: string
332-
format: byte
332+
contentEncoding: base64
333333
Pets:
334334
type: array
335335
items:

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ final class SnippetBasedReferenceTests: XCTestCase {
11211121
schemas:
11221122
MyData:
11231123
type: string
1124-
format: byte
1124+
contentEncoding: base64
11251125
""",
11261126
"""
11271127
public enum Schemas {
@@ -1140,7 +1140,7 @@ final class SnippetBasedReferenceTests: XCTestCase {
11401140
properties:
11411141
stuff:
11421142
type: string
1143-
format: byte
1143+
contentEncoding: base64
11441144
""",
11451145
"""
11461146
public enum Schemas {
@@ -2481,7 +2481,7 @@ final class SnippetBasedReferenceTests: XCTestCase {
24812481
application/json:
24822482
schema:
24832483
type: string
2484-
format: byte
2484+
contentEncoding: base64
24852485
examples:
24862486
application/json:
24872487
summary: "a hello response"

0 commit comments

Comments
 (0)