Skip to content

refactor(enum-utils): move normalization logic for enum handling to EnumUtils - #24382

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:enum-utils
Jul 22, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:enum-utils

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

This moves the remaining logic for enum processing in the OpenAPINormalizer to the EnumUtils.

This is done to centralize the logic for Enum processing, with the goal of being able to introduce a more explicit CodegenEnum model to carry the reoccurring Enum logic.

After this PR the OpenAPI representation -> Normalized OpenAPI representation step of the overall generator process

Specification -> 
OpenAPI representation -> 
Normalized OpenAPI representation -> 
Codegen models -> 
Code generated with mustache-templates

has been handled.

This should mean that we can now investigate Normalized OpenAPI representation -> Codegen model, which is the step that would contain CodegenEnum.


Note that this intentionally removes the protected method Schema createSimplifiedEnumSchema(...) from the OpenAPINormalizer.

This is done since I do not believe it is a logical extension point for a user, and that it rather only is a helper for the main rule method (Schema simplifyComposedSchemaWithEnums(...)). Thus that it belongs entirely in the Utils class. This is also based around the reasoning that the Normalizer mainly has one protected method per rules, so that if the user wants to adjust a rule, then they mainly override the entire rule-method.

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

Centralizes enum normalization in EnumUtils, moving logic out of OpenAPINormalizer. Unifies oneOf/anyOf (including OAS 3.1 const) into a single enum while preserving type and enum metadata.

  • Refactors

    • Added EnumUtils.simplifyComposedSchemaWithEnums(schema, subSchemas, composedType, openAPI) to resolve $refs and merge enum/const sub-schemas, preserving type, x-enum-descriptions, and x-enum-deprecated.
    • OpenAPINormalizer.simplifyComposedSchemaWithEnums(...) now delegates to EnumUtils and logs a standardized debug message when simplification occurs.
    • Consolidated enum-building helpers inside EnumUtils (now private), and introduced EnumUtils.ONE_OF/EnumUtils.ANY_OF constants for consistency.
  • Migration

    • Removed protected OpenAPINormalizer.createSimplifiedEnumSchema(...). If you customized it, override simplifyComposedSchemaWithEnums(...) instead.

Written for commit 0861724. Summary will update on new commits.

Review in cubic

@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 2 files

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

Re-trigger cubic

@wing328 wing328 added Feature: Enum Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. labels Jul 22, 2026
@wing328 wing328 added this to the 7.25.0 milestone Jul 22, 2026
@wing328
wing328 merged commit 3c53590 into OpenAPITools:master Jul 22, 2026
15 checks passed
@Mattias-Sehlstedt
Mattias-Sehlstedt deleted the enum-utils branch July 28, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. Feature: Enum

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants