Skip to content

Commit fcaa564

Browse files
committed
[Parsing] Allow OAS versions 3.1.2 and 3.2.0
1 parent 076b1f7 commit fcaa564

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let package = Package(
4545
.package(url: "https://github.com/apple/swift-collections", from: "1.1.4"),
4646

4747
// Read OpenAPI documents
48-
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.3.0"),
48+
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.9.0"),
4949
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"7.0.0"),
5050

5151
// CLI Tool

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The code is generated at build-time, so it's always in sync with the OpenAPI doc
1717

1818
## Features
1919

20-
- Works with OpenAPI Specification versions 3.0 and 3.1.
20+
- Works with OpenAPI Specification versions 3.0 and 3.1 and has preliminary support for version 3.2.
2121
- Streaming request and response bodies enabling use cases such as JSON event streams, and large payloads without buffering.
2222
- Support for JSON, multipart, URL-encoded form, base64, plain text, and raw bytes, represented as value types with type-safe properties.
2323
- Client, server, and middleware abstractions, decoupling the generated code from the HTTP client library and web framework.
@@ -91,9 +91,9 @@ The Swift OpenAPI Generator project is split across multiple repositories to ena
9191

9292
## Requirements and supported features
9393

94-
| Generator versions | Supported OpenAPI versions |
95-
| ------------------ | -------------------------- |
96-
| `1.0.0` ... `main` | 3.0, 3.1 |
94+
| Generator versions | Supported OpenAPI versions |
95+
| ------------------ | --------------------------- |
96+
| `1.0.0` ... `main` | 3.0, 3.1, 3.2 (preliminary) |
9797

9898
See also [Supported OpenAPI features][supported-openapi-features].
9999

Sources/_OpenAPIGeneratorCore/Parser/YamsParser.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public struct YamsParser: ParserProtocol {
5454
let decoder = YAMLDecoder()
5555
let openapiData = input.contents
5656

57+
let decodingOptions = [
58+
DocumentConfiguration.versionMapKey: [
59+
// Until we move to OpenAPIKit v5.0+ we will parse OAS 3.2.0 as if it were OAS 3.1.2
60+
"3.2.0": OpenAPI.Document.Version.v3_1_2
61+
]
62+
]
63+
5764
struct OpenAPIVersionedDocument: Decodable { var openapi: String? }
5865

5966
let versionedDocument: OpenAPIVersionedDocument
@@ -73,7 +80,8 @@ public struct YamsParser: ParserProtocol {
7380
case "3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4":
7481
let openAPI30Document = try decoder.decode(OpenAPIKit30.OpenAPI.Document.self, from: input.contents)
7582
document = openAPI30Document.convert(to: .v3_1_0)
76-
case "3.1.0", "3.1.1": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents)
83+
case "3.1.0", "3.1.1", "3.1.2": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents)
84+
case "3.2.0": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents, userInfo: decodingOptions)
7785
default:
7886
throw Diagnostic.openAPIVersionError(
7987
versionString: "openapi: \(openAPIVersion)",
@@ -128,7 +136,7 @@ extension Diagnostic {
128136
static func openAPIVersionError(versionString: String, location: Location) -> Diagnostic {
129137
error(
130138
message:
131-
"Unsupported document version: \(versionString). Please provide a document with OpenAPI versions in the 3.0.x or 3.1.x sets.",
139+
"Unsupported document version: \(versionString). Please provide a document with OpenAPI versions in the 3.0.x, 3.1.x, or 3.2.x sets.",
132140
location: location
133141
)
134142
}
@@ -139,7 +147,7 @@ extension Diagnostic {
139147
static func openAPIMissingVersionError(location: Location) -> Diagnostic {
140148
error(
141149
message:
142-
"No key named openapi found. Please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x or 3.1.x sets.",
150+
"No key named openapi found. Please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x, 3.1.x, or 3.2.x sets.",
143151
location: location
144152
)
145153
}

Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ final class Test_YamsParser: Test_Core {
2424
XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.4"))
2525
XCTAssertNoThrow(try _test(openAPIVersionString: "3.1.0"))
2626
XCTAssertNoThrow(try _test(openAPIVersionString: "3.1.1"))
27+
XCTAssertNoThrow(try _test(openAPIVersionString: "3.1.2"))
28+
XCTAssertNoThrow(try _test(openAPIVersionString: "3.2.0"))
2729

2830
let expected1 =
29-
"/foo.yaml: error: Unsupported document version: openapi: 3.2.0. Please provide a document with OpenAPI versions in the 3.0.x or 3.1.x sets."
30-
assertThrownError(try _test(openAPIVersionString: "3.2.0"), expectedDiagnostic: expected1)
31+
"/foo.yaml: error: Unsupported document version: openapi: 3.3.0. Please provide a document with OpenAPI versions in the 3.0.x, 3.1.x, or 3.2.x sets."
32+
assertThrownError(try _test(openAPIVersionString: "3.3.0"), expectedDiagnostic: expected1)
3133

3234
let expected2 =
33-
"/foo.yaml: error: Unsupported document version: openapi: 2.0. Please provide a document with OpenAPI versions in the 3.0.x or 3.1.x sets."
35+
"/foo.yaml: error: Unsupported document version: openapi: 2.0. Please provide a document with OpenAPI versions in the 3.0.x, 3.1.x, or 3.2.x sets."
3436
assertThrownError(try _test(openAPIVersionString: "2.0"), expectedDiagnostic: expected2)
3537
}
3638

@@ -56,7 +58,7 @@ final class Test_YamsParser: Test_Core {
5658
"""
5759

5860
let expected =
59-
"/foo.yaml: error: No key named openapi found. Please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x or 3.1.x sets."
61+
"/foo.yaml: error: No key named openapi found. Please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x, 3.1.x, or 3.2.x sets."
6062
assertThrownError(try _test(yaml), expectedDiagnostic: expected)
6163
}
6264

@@ -121,7 +123,7 @@ final class Test_YamsParser: Test_Core {
121123
"""
122124

123125
let expected = """
124-
/foo.yaml: error: Found neither a $ref nor a PathItem in Document.paths['/system'].
126+
/foo.yaml: error: Found neither a $ref nor a PathItem in Document.paths['/system'].
125127
126128
PathItem could not be decoded because:
127129
Inconsistency encountered when parsing `Vendor Extension` for the **GET** endpoint under `/system`: Found at least one vendor extension property that does not begin with the required 'x-' prefix. Invalid properties: [ resonance ]..

0 commit comments

Comments
 (0)