Repository navigation
Conversation
When an operation sets the `x-stability-level` extension (as used by oasdiff: `draft`, `alpha`, `beta`, `stable`), note the level in the Godoc of the generated client methods, so callers can see whether the API they are calling is potentially unstable. Operations without the extension, or with a non-string or empty value, generate exactly the same output as before. Closes oapi-codegen#2483
Anandb71
marked this pull request as ready for review
October 6, 2026 13:28
Contributor
|
Member
|
Not quite sure on the wording - I've not really decided how I want this to be shared with the user 🤔 |
Author
|
Thanks for taking a look! Happy to go with whatever reads best to you. A few options:
I'm also fine converting this back to a draft while you decide. I'll update it as soon as you pick a direction. |
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.
Closes #2483
What
When an operation sets the
x-stability-levelextension, the generated client methods now say so in their Godoc. This coversClientInterface,Client,ClientWithResponsesInterfaceandClientWithResponses, including the typed request-body variants:How
extStabilityLevel = "x-stability-level"sits next toextDeprecationReasoninpkg/codegen/extension.go.OperationDefinition.StabilityComment()reads the extension with the existingextStringhelper and trims it. It returns one comment line, or""when the spec is nil, the extension is missing, the value isn't a string, or the value is empty.OperationDefinition.GenerateFunctionCommentandRequestBodyDefinition.GenerateFunctionCommentare the buildersclient_view.gouses for every client method comment. When that line is set, both append a//separator and then the line, in the summary and the no-summary branches.draft,alpha,betaandstable, but the generator doesn't enforce them.client, so I kept this to the client. If you'd like the same line on the server interfaces too, I'm happy to extend it.When an operation has no
x-stability-level, output is byte-for-byte the same as before. Regeneratingexamples/andinternal/test/touches no existing generated file.Docs and example
x-stability-levelsection indocs/extensions.md, afterx-deprecated-reason.examples/extensions/xstabilitylevel/(spec, config,generate.goand the generatedgen.go), in the same layout asxdeprecatedreason. It has analphaoperation, abetaoperation with a JSON body, and one operation without the extension.Tests
TestStabilityComment(nil spec, missing extension,alpha, surrounding whitespace, empty string, non-string value).TestOperationDefinition_GenerateFunctionCommentandTestRequestBodyDefinition_GenerateFunctionComment, with and without a summary and with and withoutWithResponse.Without the change, the new tests fail.
StabilityCommentis undefined, and with only the comment-builder hunks reverted, bothGenerateFunctionCommenttests fail. With the change, they pass.Commands run (Go 1.25;
makeisn't available on my machine, so I ran what the Makefile targets run):Note for review: with my local Go 1.25 toolchain,
go generaterewrites the base64 chunks of the embeddedswaggerSpecin existing*.gen.gofiles. That only happens with my toolchain (compressor output differs between Go versions) and has nothing to do with this change: every changed line was one of those chunks. I reverted all of them, so this PR doesn't touch any existing generated file. The new example has no embedded spec.