diff --git a/Sources/OpenAPIKitCompat/Compat30To31.swift b/Sources/OpenAPIKitCompat/Compat30To31.swift index 0f2aa235e..b16b82c84 100644 --- a/Sources/OpenAPIKitCompat/Compat30To31.swift +++ b/Sources/OpenAPIKitCompat/Compat30To31.swift @@ -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 diff --git a/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift b/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift index cff4a22a5..c908b9965 100644 --- a/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift +++ b/Tests/OpenAPIKitCompatTests/DocumentConversionTests.swift @@ -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: [:], @@ -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) }