Skip to content

Drop paths left empty by tag and operationId filtering - #2638

Open
56steve wants to merge 1 commit into
oapi-codegen:mainfrom
56steve:fix/filter-drop-empty-paths
Open

56steve wants to merge 1 commit into
oapi-codegen:mainfrom
56steve:fix/filter-drop-empty-paths

Conversation

@56steve

@56steve 56steve commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

When include-tags, exclude-tags, include-operation-ids or exclude-operation-ids removed every operation of a path, the path item stayed in the spec as an empty entry, so the embedded spec still listed it (for example "/t2":{}). I now delete a path once filtering has removed all of its operations. Paths that never had operations are left alone. Two existing prune tests asserted the old behaviour and now check that the path is gone, and I added a test covering both filter kinds.

@56steve
56steve requested a review from a team as a code owner October 29, 2026 04:48
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches code generation runs that use operation filters.

Preserve compatibility for previously generated types before merging.

Findings

  1. P1 Previously generated types disappear ▶
  2. P2 Path preservation lacks tests ▶
Fix with agent prompt
### Issue 1
pkg/codegen/filter.go:40-41
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 kept `ItemID` in the generated Go code. Now `pruneUnusedComponents` deletes 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.

### Issue 2
pkg/codegen/filter_test.go:161-170
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR removes paths after tag or operation-ID filtering removes their last operation.

  • Filtered paths disappear once none of their operations remain.

Reviews (1) · Last reviewed commit: "Drop paths with no operations left after..." · Reviewed by Greptile

Comment thread pkg/codegen/filter.go
Comment on lines +40 to +41
if len(names) > 0 && len(pathItem.Operations()) == 0 {
paths.Delete(path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Previously generated types disappear

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 kept ItemID in the generated Go code. Now pruneUnusedComponents deletes 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
This is a comment left during a code review.
Path: pkg/codegen/filter.go
Line: 40-41

Comment:
**Previously generated types disappear**

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 kept `ItemID` in the generated Go code. Now `pruneUnusedComponents` deletes 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.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +161 to +170
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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Prompt To Fix With AI
This 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant