GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: add SetGlobalStateOptions and ResetGlobalState by toller892 · Pull Request #2393 · oapi-codegen/oapi-codegen ConversationProblemWhen using oapi-codegen as a library and calling SolutionThis PR adds two new exported functions, following the pattern established by
Usage// Generate with first set of options result1, err := codegen.Generate(spec, opts1) // Reset state before next call codegen.ResetGlobalState() // Generate with different options result2, err := codegen.Generate(spec, opts2) Or for just overriding options: codegen.SetGlobalStateOptions(newOpts) result, err := codegen.Generate(spec, newOpts) Fixes #1805
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Add SetGlobalStateOptions to allow setting globalState.options without calling Generate, following the pattern established by SetGlobalStateSpec (PR oapi-codegen#1174). Add ResetGlobalState to reset all global state fields to their zero values, preventing state leakage between successive Generate calls when using oapi-codegen as a library. Fixes oapi-codegen#1805
Contributor
Reviews (1): Last reviewed commit: "feat: add SetGlobalStateOptions and Rese..." | Re-trigger Greptile All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+1488
to
+1497
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.
Suggested change
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+1488
to
+1497
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.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Merged
3 tasks done
adamwg
added a commit
to crossplane/cli
that referenced
this pull request
…sistent The oapi-codegen package we use to generate Go code keeps a bunch of internal global state that affects how code is generated. In particular, the name normalizer it uses to form types names is a global variable initialized when we call `codegen.Generate`. We call some of the codegen package's utility functions to form custom names for types before generating code. These utility functions also use the global state set up by `codegen.Generate`, which isn't initialized when we call them, resulting in the utility functions producing different names than we expect. This makes our code generation non-deterministic: we get different name capitalization depending what order schemas get generated in. Make a no-op call to `codegen.Generate` with our desired options before calling the mutators to ensure that the global state is initialized for all our calls. Note that once oapi-codegen/oapi-codegen#2393 is merged in the upstream code generator, we can use the new `SetGlobalStateOptions` function rather than the dummy `Generate` call. Fixes #113 Signed-off-by: Adam Wolfe Gordon <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersAt least 1 approving review is required to merge this pull request. Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Allow resetting globalState.optionsUh oh!
There was an error while loading. Please reload this page. 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. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |