Skip to content

Commit

Permalink
fix bug with conversion of Server Variable enum from OAS 3.0 to 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Aug 30, 2023
1 parent c598406 commit 0a94409
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Sources/OpenAPIKitCompat/Compat30To31.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ extension OpenAPIKit30.OpenAPI.Server: To31 {
public func to31() -> OpenAPIKit.OpenAPI.Server {

let newVariables = variables.mapValues { variable in
OpenAPIKit.OpenAPI.Server.Variable(
enum: variable.enum,
let enumValue: [String]?
if !variable.enum.isEmpty {
enumValue = variable.enum
} else {
enumValue = nil
}

return OpenAPIKit.OpenAPI.Server.Variable(
enum: enumValue,
default: variable.default,
description: variable.description,
vendorExtensions: variable.vendorExtensions
Expand Down
14 changes: 13 additions & 1 deletion Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ final class DocumentConversionTests: XCTestCase {
description: "hi",
variables: ["hello": .init(enum: ["1"], default: "1", description: "described", vendorExtensions: ["x-hi": "hello"])],
vendorExtensions: ["x-test": 2]
),
.init(
urlTemplate: try .init(templateString: "{protocol}://{hostname}/api/v3"),
variables: [
"protocol": .init(default: "http", description: "protocol"),
"hostname": .init(default: "HOSTNAME", description: "host name")
]
)
],
paths: [:],
Expand Down Expand Up @@ -479,10 +486,15 @@ fileprivate func assertEqualNewToOld(_ newServer: OpenAPIKit.OpenAPI.Server?, _
XCTAssertEqual(newServer.urlTemplate, oldServer.urlTemplate)
XCTAssertEqual(newServer.description, oldServer.description)
XCTAssertEqual(newServer.vendorExtensions, oldServer.vendorExtensions)
XCTAssertEqual(newServer.variables.count, oldServer.variables.count)
for (key, newVariable) in newServer.variables {
let oldVariable = oldServer.variables[key]
XCTAssertEqual(newVariable.description, oldVariable?.description)
XCTAssertEqual(newVariable.`enum`, oldVariable?.`enum`)
if (oldVariable?.enum ?? []).isEmpty {
XCTAssertNil(newVariable.`enum`)
} else {
XCTAssertEqual(newVariable.`enum`, oldVariable?.`enum`)
}
XCTAssertEqual(newVariable.`default`, oldVariable?.`default`)
XCTAssertEqual(newVariable.vendorExtensions, oldVariable?.vendorExtensions)
}
Expand Down

0 comments on commit 0a94409

Please sign in to comment.