From 3a5b182ff3590f2834526ec366f0ebd2aa08cd9a Mon Sep 17 00:00:00 2001 From: Arthur Crocquevieille Date: Fri, 11 Aug 2023 09:06:54 +0200 Subject: [PATCH] Restore correct parameters ordering --- .../Translator/Operations/OperationDescription.swift | 11 ++++++----- .../Operations/Test_OperationDescription.swift | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift b/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift index 87b58631..b21f63fc 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift @@ -150,23 +150,24 @@ extension OperationDescription { /// - Returns: An array of merged path item and operation level parameters without duplicates. /// - Throws: When an invalid JSON reference is found. var allParameters: [UnresolvedParameter] { - get throws { + get throws { var mergedParameters: [UnresolvedParameter] = [] var uniqueIdentifiers: Set = [] - for parameter in operation.parameters + pathParameters { + let allParameters = pathParameters + operation.parameters + for parameter in allParameters.reversed() { let resolvedParameter = try parameter.resolve(in: components) let identifier = resolvedParameter.location.rawValue + ":" + resolvedParameter.name - guard !uniqueIdentifiers.contains(identifier) else { - continue + guard !uniqueIdentifiers.contains(identifier) else { + continue } mergedParameters.append(parameter) uniqueIdentifiers.insert(identifier) } - return mergedParameters + return mergedParameters.reversed() } } diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift index b79ca4de..2501508a 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift @@ -74,7 +74,7 @@ final class Test_OperationDescription: Test_Core { ) let allParameters = try _test(pathItem) - XCTAssertEqual(allParameters, [operationLevelParameter, pathLevelParameter]) + XCTAssertEqual(allParameters, [pathLevelParameter, operationLevelParameter]) } private func _test(_ pathItem: OpenAPI.PathItem) throws -> [UnresolvedParameter] {