Skip to content

fix(go-server): avoid AssertstringRequired for primitive-typed models - #24374

Open
halfcrazy wants to merge 1 commit into
OpenAPITools:masterfrom
halfcrazy:fix/go-server-assertstring-and-ref-readonly
Open

fix(go-server): avoid AssertstringRequired for primitive-typed models#24374
halfcrazy wants to merge 1 commit into
OpenAPITools:masterfrom
halfcrazy:fix/go-server-assertstring-and-ref-readonly

Conversation

@halfcrazy

@halfcrazy halfcrazy commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

oneOf/nullable enums can flatten to string while still flagged as models, so templates must not emit Assertstring helpers that do not exist.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Stops Go server codegen from emitting Assertstring* calls when composed schemas flatten to Go primitives (e.g., nullable oneOf enums), preventing bad references and compile errors. Primitive detection is centralized in AbstractGoCodegen so all Go generators treat these as primitives.

  • Bug Fixes
    • Clear isModel and set isPrimitiveType in AbstractGoCodegen.fromProperty when the Go type (incl. pointer types) is primitive; applies to array items too.
    • Add missing Go builtins to languageSpecificPrimitives: uint8, uint16, int8, int16, uintptr, and update Go generator docs to list them.
    • Tests and sample spec verify no AssertstringRequired/Constraints generation and AssertThingRequired is a no-op.

Written for commit 2b5ed04. Summary will update on new commits.

Review in cubic

@halfcrazy

Copy link
Copy Markdown
Contributor Author

cc @antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @jirikuncar (2021/01) @ph4r5h4d (2021/04) @lwj5 (2023/04)

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 4 files

Re-trigger cubic

}
for (CodegenProperty v : model.vars) {
clearModelFlagForPrimitives(v);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for the PR

what about updating https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java#L96C9-L96C36 instead to clearly indicate which type is classified as a primitive type ?

@halfcrazy
halfcrazy force-pushed the fix/go-server-assertstring-and-ref-readonly branch from 0b652fe to 1c666ae Compare July 29, 2026 12:37
oneOf/nullable enums can flatten to *string while still flagged as
models at the OpenAPI level (DefaultCodegen marks composed schemas as
models regardless of the language type mapping), so go-server templates
emit Assertstring* helpers that do not exist.

Fix the classification where it happens instead of patching generated
flags downstream: complete AbstractGoCodegen.languageSpecificPrimitives
with the remaining Go builtin integer types and clear isModel in
AbstractGoCodegen.fromProperty when the resulting Go type is classified
as a primitive. All Go generators share the corrected classification
and array items are covered through the fromProperty recursion.

Regenerate Go generator docs for the updated primitive type list.

Signed-off-by: Yan Zhu <hackzhuyan@gmail.com>
@halfcrazy
halfcrazy force-pushed the fix/go-server-assertstring-and-ref-readonly branch from 1c666ae to 2b5ed04 Compare July 29, 2026 13:00
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.

2 participants