Allow generating a list of strict operation IDs#2414
Open
AnthonySuper wants to merge 2 commits into
Open
Conversation
The generated code presently passes a strict operation ID to every `StrictMiddlewareFunc` you have configured for a server. This is great for writing auth-like middleware: you can have a unified function that handles authorization on the *operational* level, and test it by itself. This is not so great if you're forgetful (like the author of this MR) and sometimes forget to write those tests... or to update your handler function. By generating a list of all operation handlers, we make it much easier to write a test that asserts that some `StrictMiddlewareFunc` has proper behavior for *all* operation IDs.
AnthonySuper
force-pushed
the
add-ability-to-list-all-operation-ids
branch
from
June 18, 2026 16:34
bff9920 to
4382333
Compare
Contributor
Greptile SummaryThis PR adds an optional generated list of strict operation IDs. The main changes are:
Confidence Score: 3/5This should be fixed before merging.
pkg/codegen/codegen.go and pkg/codegen/templates/operation-list.tmpl
|
| Filename | Overview |
|---|---|
| pkg/codegen/codegen.go | Adds strict operation list generation, but currently includes alias operations that strict middleware never sees. |
| pkg/codegen/templates/operation-list.tmpl | Emits the new StrictOperationIDs variable with a fixed top-level name that can collide with generated symbols. |
| pkg/codegen/configuration.go | Adds the YAML config field for the new generation option. |
Reviews (1): Last reviewed commit: "Allow generating a list of strict operat..." | Re-trigger Greptile
| // argument to every StrictMiddlewareFunc call. Each entry is the normalized | ||
| // Go identifier for the operation (e.g. "ListUsers"), matching exactly what | ||
| // the strict handler passes when it invokes the middleware chain. | ||
| var StrictOperationIDs = []string{ |
Contributor
There was a problem hiding this comment.
StrictOperationIDs is emitted as a fixed top-level package symbol, but it is not checked against generated type names. If a spec already has a component schema named StrictOperationIDs, code generation can emit both type StrictOperationIDs ... and var StrictOperationIDs = []string{...} in the same package. Go rejects that as a redeclaration, so enabling this option can make an otherwise valid spec fail to compile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generated code presently passes a strict operation ID to every
StrictMiddlewareFuncyou have configured for a server. This is great for writing auth-like middleware: you can have a unified function that handles authorization on the operational level, and test it by itself.This is not so great if you're forgetful (like the author of this MR) and sometimes forget to write those tests... or to update your handler function.
By generating a list of all operation handlers, we make it much easier to write a test that asserts that some
StrictMiddlewareFunchas proper behavior for all operation IDs. Something like: