Skip to content

refactor: introduce EnumVarMap for improved enum handling across code generators - #24665

Open
Mattias-Sehlstedt wants to merge 2 commits into
OpenAPITools:masterfrom
Mattias-Sehlstedt:enum-map
Open

refactor: introduce EnumVarMap for improved enum handling across code generators#24665
Mattias-Sehlstedt wants to merge 2 commits into
OpenAPITools:masterfrom
Mattias-Sehlstedt:enum-map

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Introduces a enum wrapper model that collects the common operations that are done when creating an enum variable.

This is done as a HashMap wrapper rather than a Codegen model since we want to retain the easy extension of the data. This structure mimics the already existing XMap models that are within the model folder.

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

Introduces EnumVarMap to standardize and type-safe enum handling across generators, moving enum constants off CodegenConstants and replacing getEnumVarsAsString with getEnumVars. Refactor spans multiple generators with no changes to generated outputs.

  • Refactors

    • Added EnumVarMap (HashMap wrapper) with helpers and ENUM_* constants.
    • Switched enum flows to List<EnumVarMap> in core (buildEnumVars, post-processing, extension updates).
    • Removed EnumUtils.getEnumVarsAsString; updated generators to EnumUtils.getEnumVars (C#, Dart, F#, PHP, Python incl. Pydantic V1, Java/Helidon, Go, Nim, OCaml, Haskell, Crystal, Ruby, TypeScript Fetch, Avro, Protobuf, etc.).
    • Protobuf: migrated to EnumVarMap, added enum indexes; tests updated to assert boolean isString.
  • Migration

    • Signatures now use List<EnumVarMap>:
      • buildEnumVars(List<Object>, String) returns List<EnumVarMap>.
      • updateEnumVarsWithExtensions(...) accepts List<EnumVarMap>.
    • Replace CodegenConstants.ENUM_* with EnumVarMap.ENUM_*.
    • Replace EnumUtils.getEnumVarsAsString(...) with EnumUtils.getEnumVars(...).
    • When mutating enum vars, use EnumVarMap methods: enumVar(...), setEnumName(...), setEnumValue(...), isString(boolean), getEnumName(), getEnumValue(), isString().

Written for commit 889607d. Summary will update on new commits.

Review in cubic

@Mattias-Sehlstedt
Mattias-Sehlstedt marked this pull request as ready for review August 10, 2026 10:00

@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.

All reported issues were addressed across 30 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the enum-map branch 4 times, most recently from 76b963c to cc3987e Compare August 10, 2026 11: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.

1 participant