Repository navigation
Drop paths left empty by tag and operationId filtering #2638
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,3 +128,45 @@ func TestFilterOperationsByOperationID(t *testing.T) { | |
| assert.NotContains(t, code, `"/cat"`) | ||
| }) | ||
| } | ||
|
|
||
| func TestFilterRemovesPathsWithNoOperationsLeft(t *testing.T) { | ||
| const spec = ` | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: filter | ||
| version: "1" | ||
| paths: | ||
| /kept: | ||
| get: | ||
| operationId: getKept | ||
| tags: [kept] | ||
| responses: | ||
| "200": | ||
| description: ok | ||
| /dropped: | ||
| get: | ||
| operationId: getDropped | ||
| tags: [dropped] | ||
| responses: | ||
| "200": | ||
| description: ok | ||
| ` | ||
| load := func(t *testing.T) *openapi3.T { | ||
| t.Helper() | ||
| swagger, err := openapi3.NewLoader().LoadFromData([]byte(spec)) | ||
| assert.NoError(t, err) | ||
| return swagger | ||
| } | ||
|
|
||
| t.Run("by tag", func(t *testing.T) { | ||
| swagger := load(t) | ||
| filterOperationsByTag(swagger, Configuration{OutputOptions: OutputOptions{IncludeTags: []string{"kept"}}}) | ||
| assert.Equal(t, []string{"/kept"}, swagger.Paths.Keys()) | ||
| }) | ||
|
|
||
| t.Run("by operation id", func(t *testing.T) { | ||
| swagger := load(t) | ||
| filterOperationsByOperationID(swagger, Configuration{OutputOptions: OutputOptions{ExcludeOperationIDs: []string{"getDropped"}}}) | ||
| assert.Equal(t, []string{"/kept"}, swagger.Paths.Keys()) | ||
|
Comment on lines
+161
to
+170
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test checks only paths with one operation each. Add a path that starts empty and a path with both a kept and a removed operation, then assert that both paths survive under each filter kind. These cases protect the two deletion guards; the current tests would still pass if either guard were removed. Prompt To Fix With AIThis is a comment left during a code review.
Path: pkg/codegen/filter_test.go
Line: 161-170
Comment:
**Path preservation lacks tests**
The new test checks only paths with one operation each. Add a path that starts empty and a path with both a kept and a removed operation, then assert that both paths survive under each filter kind. These cases protect the two deletion guards; the current tests would still pass if either guard were removed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting the whole path also removes references from its shared parameters. If a filtered-out path has a parameter referencing
#/components/schemas/ItemID, that reference previously keptItemIDin the generated Go code. NowpruneUnusedComponentsdeletes it when nothing else references it, breaking downstream code that uses the exported type. Both filter helpers have this problem.The repository requires compatibility protection for changes to generated APIs. Preserve the existing type output by default or make this broader change opt-in.
Prompt To Fix With AI