From a0d04b2b23e0d4440ee9844e8e36db0b8c17a74f Mon Sep 17 00:00:00 2001 From: Arthur Crocquevieille Date: Fri, 11 Aug 2023 13:17:56 +0200 Subject: [PATCH] Add test for allParameters ordering --- .../Test_OperationDescription.swift | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift index 2501508a..8f6824af 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift @@ -77,6 +77,43 @@ final class Test_OperationDescription: Test_Core { XCTAssertEqual(allParameters, [pathLevelParameter, operationLevelParameter]) } + func testAllParameters_duplicates_ordering() throws { + let pathLevelParameter = UnresolvedParameter.b( + OpenAPI.Parameter( + name: "test1", + context: .query(required: false), + schema: .integer + ) + ) + let duplicatedParameter = UnresolvedParameter.b( + OpenAPI.Parameter( + name: "test2", + context: .query(required: false), + schema: .integer + ) + ) + let operationLevelParameter = UnresolvedParameter.b( + OpenAPI.Parameter( + name: "test3", + context: .query(required: false), + schema: .string + ) + ) + + let pathItem = OpenAPI.PathItem( + parameters: [pathLevelParameter, duplicatedParameter], + get: .init( + parameters: [duplicatedParameter, operationLevelParameter], + requestBody: .b(.init(content: [:])), + responses: [:] + ), + vendorExtensions: [:] + ) + let allParameters = try _test(pathItem) + + XCTAssertEqual(allParameters, [pathLevelParameter, duplicatedParameter, operationLevelParameter]) + } + private func _test(_ pathItem: OpenAPI.PathItem) throws -> [UnresolvedParameter] { guard let endpoint = pathItem.endpoints.first else { XCTFail("Unable to retrieve the path item first endpoint.") @@ -84,7 +121,7 @@ final class Test_OperationDescription: Test_Core { } let operationDescription = OperationDescription( - path: .init(["\test"]), + path: .init(["/test"]), endpoint: endpoint, pathParameters: pathItem.parameters, components: .init(),