Skip to content

Commit

Permalink
Restore correct parameters ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurcro committed Aug 11, 2023
1 parent 35c99ff commit 3a5b182
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = []

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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down

0 comments on commit 3a5b182

Please sign in to comment.