Skip to content

Commit

Permalink
Add support for OpenAPI 3.0.4 and 3.1.1 (#665)
Browse files Browse the repository at this point in the history
### Motivation

OpenAPI 3.0.4 and 3.1.1 dropped, mostly containing clarifications:
https://www.openapis.org/blog/2024/10/25/announcing-openapi-specification-patch-releases

### Modifications

- Bumped the OpenAPIKit dependency to get the new versions parsed.
- Added the two new versions to our enum.
- Added unit tests.

### Result

We can parse the new versions.

### Test Plan

Added unit tests.
  • Loading branch information
czechboy0 authored Nov 4, 2024
1 parent 827fa72 commit 759c30b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"),

// Read OpenAPI documents
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.1.2"),
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.3.0"),
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"6.0.0"),

// CLI Tool
Expand Down
4 changes: 2 additions & 2 deletions Sources/_OpenAPIGeneratorCore/Parser/YamsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public struct YamsParser: ParserProtocol {
do {
let document: OpenAPIKit.OpenAPI.Document
switch openAPIVersion {
case "3.0.0", "3.0.1", "3.0.2", "3.0.3":
case "3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4":
let openAPI30Document = try decoder.decode(OpenAPIKit30.OpenAPI.Document.self, from: input.contents)
document = openAPI30Document.convert(to: .v3_1_0)
case "3.1.0": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents)
case "3.1.0", "3.1.1": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents)
default:
throw Diagnostic.openAPIVersionError(
versionString: "openapi: \(openAPIVersion)",
Expand Down
2 changes: 2 additions & 0 deletions Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ final class Test_YamsParser: Test_Core {
XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.1"))
XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.2"))
XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.3"))
XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.4"))
XCTAssertNoThrow(try _test(openAPIVersionString: "3.1.0"))
XCTAssertNoThrow(try _test(openAPIVersionString: "3.1.1"))

let expected1 =
"/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."
Expand Down

0 comments on commit 759c30b

Please sign in to comment.