feat(go): add enumUnknownDefaultCase config option#23417
Open
marceljk wants to merge 3 commits intoOpenAPITools:masterfrom
Open
feat(go): add enumUnknownDefaultCase config option#23417marceljk wants to merge 3 commits intoOpenAPITools:masterfrom
marceljk wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 19 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/generators/go.md">
<violation number="1" location="docs/generators/go.md:23">
P3: Fix the sentence break and pluralization in this option description (missing space after the period and "enum's" should be "enums").</violation>
</file>
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java:157">
P3: This option is already registered in DefaultCodegen, so adding it again here duplicates the CLI option entry and creates redundant config setup. Rely on the base class definition instead.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| cliOptions.add(CliOption.newBoolean(CodegenConstants.GENERATE_MARSHAL_JSON, CodegenConstants.GENERATE_MARSHAL_JSON_DESC, true)); | ||
| cliOptions.add(CliOption.newBoolean(CodegenConstants.GENERATE_UNMARSHAL_JSON, CodegenConstants.GENERATE_UNMARSHAL_JSON_DESC, true)); | ||
|
|
||
| CliOption enumUnknownDefaultCaseOpt = CliOption.newBoolean( |
Contributor
There was a problem hiding this comment.
P3: This option is already registered in DefaultCodegen, so adding it again here duplicates the CLI option entry and creates redundant config setup. Rely on the base class definition instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java, line 157:
<comment>This option is already registered in DefaultCodegen, so adding it again here duplicates the CLI option entry and creates redundant config setup. Rely on the base class definition instead.</comment>
<file context>
@@ -153,6 +153,19 @@ public GoClientCodegen() {
cliOptions.add(CliOption.newBoolean(CodegenConstants.GENERATE_MARSHAL_JSON, CodegenConstants.GENERATE_MARSHAL_JSON_DESC, true));
cliOptions.add(CliOption.newBoolean(CodegenConstants.GENERATE_UNMARSHAL_JSON, CodegenConstants.GENERATE_UNMARSHAL_JSON_DESC, true));
+
+ CliOption enumUnknownDefaultCaseOpt = CliOption.newBoolean(
+ CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE,
+ CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE_DESC).defaultValue(Boolean.FALSE.toString());
</file context>
Contributor
Author
There was a problem hiding this comment.
In the AbstractGoCodegen, all cliOptions from the DefaultCodegen get cleared. So it's needed to configure it again
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
722b3c4 to
f33a6a3
Compare
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.
This PR supersedes #18748
fixes the issue that the Go generator doesn't support the enumUnknownDefaultCase config option: #18747
Credits to @jonrosner for the original pull request
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5
Summary by cubic
Adds a new
enumUnknownDefaultCaseoption to the Go generator to safely decode unknown enum values by falling back to a default during JSON unmarshalling. Fixes #18747 and prevents errors when servers add new enum cases.New Features
enumUnknownDefaultCasein Go generator (default: false).unknown_default_open_api, andUnmarshalJSONfalls back to it instead of returning an error.docs/generators/go.mdand enabled inbin/configs/go-petstore.yaml.Bug Fixes
enumUnknownDefaultCasedescriptions across generator docs; added the Go docs entry.Written for commit f33a6a3. Summary will update on new commits.