Skip to content

Include path item parameters in filter #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/_OpenAPIGeneratorCore/Hooks/FilteredDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ private extension FilteredDocumentBuilder {
guard predicate(endpoint) else { continue }
if requiredEndpoints[path] == nil { requiredEndpoints[path] = Set() }
if requiredEndpoints[path]!.insert(endpoint.method).inserted {
for parameter in originalPathItem.parameters { try includeParameter(parameter) }
try includeComponentsReferencedBy(endpoint.operation)
}
}
Expand Down
51 changes: 43 additions & 8 deletions Tests/OpenAPIGeneratorCoreTests/Hooks/Test_FilteredDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class Test_FilteredDocument: XCTestCase {
- name: t
paths:
/things/a:
parameters:
- $ref: '#/components/parameters/A'
get:
operationId: getA
tags:
Expand All @@ -52,6 +54,12 @@ final class Test_FilteredDocument: XCTestCase {
type: string
B:
$ref: '#/components/schemas/A'
parameters:
A:
in: query
schema:
type: string
name: A
responses:
A:
description: success
Expand All @@ -75,14 +83,16 @@ final class Test_FilteredDocument: XCTestCase {
filter: DocumentFilter(tags: ["t"]),
hasPaths: ["/things/a"],
hasOperations: ["getA"],
hasSchemas: ["A"]
hasSchemas: ["A"],
hasParameters: ["A"]
)
assert(
filtering: document,
filter: DocumentFilter(paths: ["/things/a"]),
hasPaths: ["/things/a"],
hasOperations: ["getA", "deleteA"],
hasSchemas: ["A"]
hasSchemas: ["A"],
hasParameters: ["A"]
)
assert(
filtering: document,
Expand All @@ -96,7 +106,8 @@ final class Test_FilteredDocument: XCTestCase {
filter: DocumentFilter(paths: ["/things/a", "/things/b"]),
hasPaths: ["/things/a", "/things/b"],
hasOperations: ["getA", "deleteA", "getB"],
hasSchemas: ["A", "B"]
hasSchemas: ["A", "B"],
hasParameters: ["A"]
)
assert(
filtering: document,
Expand All @@ -117,21 +128,24 @@ final class Test_FilteredDocument: XCTestCase {
filter: DocumentFilter(paths: ["/things/a"], schemas: ["B"]),
hasPaths: ["/things/a"],
hasOperations: ["getA", "deleteA"],
hasSchemas: ["A", "B"]
hasSchemas: ["A", "B"],
hasParameters: ["A"]
)
assert(
filtering: document,
filter: DocumentFilter(tags: ["t"], schemas: ["B"]),
hasPaths: ["/things/a"],
hasOperations: ["getA"],
hasSchemas: ["A", "B"]
hasSchemas: ["A", "B"],
hasParameters: ["A"]
)
assert(
filtering: document,
filter: DocumentFilter(operations: ["deleteA"]),
hasPaths: ["/things/a"],
hasOperations: ["deleteA"],
hasSchemas: []
hasSchemas: [],
hasParameters: ["A"]
)
}

Expand All @@ -141,6 +155,7 @@ final class Test_FilteredDocument: XCTestCase {
hasPaths paths: [OpenAPI.Path.RawValue],
hasOperations operationIDs: [String],
hasSchemas schemas: [String],
hasParameters parameters: [String] = [],
file: StaticString = #filePath,
line: UInt = #line
) {
Expand All @@ -149,11 +164,31 @@ final class Test_FilteredDocument: XCTestCase {
XCTFail("Filter threw error: \(error)", file: file, line: line)
return
}
XCTAssertUnsortedEqual(filteredDocument.paths.keys.map(\.rawValue), paths, file: file, line: line)
XCTAssertUnsortedEqual(filteredDocument.allOperationIds, operationIDs, file: file, line: line)
XCTAssertUnsortedEqual(
filteredDocument.paths.keys.map(\.rawValue),
paths,
"Paths don't match",
file: file,
line: line
)
XCTAssertUnsortedEqual(
filteredDocument.allOperationIds,
operationIDs,
"Operations don't match",
file: file,
line: line
)
XCTAssertUnsortedEqual(
filteredDocument.components.schemas.keys.map(\.rawValue),
schemas,
"Schemas don't match",
file: file,
line: line
)
XCTAssertUnsortedEqual(
filteredDocument.components.parameters.keys.map(\.rawValue),
parameters,
"Parameters don't match",
file: file,
line: line
)
Expand Down