Skip to content

Commit

Permalink
Add test for allParameters ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurcro committed Aug 11, 2023
1 parent 3a5b182 commit a0d04b2
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,51 @@ 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.")
return []
}

let operationDescription = OperationDescription(
path: .init(["\test"]),
path: .init(["/test"]),
endpoint: endpoint,
pathParameters: pathItem.parameters,
components: .init(),
Expand Down

0 comments on commit a0d04b2

Please sign in to comment.