Skip to content

fix(normalizer): restore behavior of clearing a oneOf if the schema content cannot currently be used by the generator - #24585

Open
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:only-retain-const-for-simplify-one-of
Open

fix(normalizer): restore behavior of clearing a oneOf if the schema content cannot currently be used by the generator#24585
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:only-retain-const-for-simplify-one-of

Conversation

@Mattias-Sehlstedt

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

Copy link
Copy Markdown
Contributor

Restores behavior of clearing a oneOf when running normalization normalizeOneOf as part of the SIMPLIFY_ONEOF_ANYOF rule.

The only case that currently is kept is when the oneOf only has const branches. Note that this case is not really relevant as of current, with the introduction of const parsing with #23869 (being part of rule SIMPLIFY_ONEOF_ANYOF_ENUM), which is processed before SIMPLIFY_ONEOF_ANYOF.

Would be good to get feedback from the original author, since it could be that #22571 looks to forward meta annotations from a oneOf that is not tied to const.

Fixes #24574

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

Restores the normalizer’s behavior to clear oneOf under SIMPLIFY_ONEOF_ANYOF when the generator can’t use its content, keeping it only when all branches are OAS 3.1 consts for potential enum handling. Fixes #24574.

  • Bug Fixes
    • Added clearOneOf() in OpenAPINormalizer to drop oneOf on integer/number/string schemas unless ModelUtils.isOneOfOfConsts() is true.
    • Implemented ModelUtils.isOneOfOfConsts() (OAS 3.1 only; all branches must have const).
    • Expanded tests: collapse differing string patterns (StringPatternsWithOneOf); preserve const-only oneOf when SIMPLIFY_ONEOF_ANYOF_ENUM is disabled; extracted option keys to constants.
    • Updated C# sample OpenAPI to include StringPatternsWithOneOf.

Written for commit cf098f6. 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.

No issues found across 4 files

Re-trigger cubic

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the only-retain-const-for-simplify-one-of branch 2 times, most recently from d52244c to 87bd29c Compare August 3, 2026 18:09
…ontent cannot currently be used by the generator
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the only-retain-const-for-simplify-one-of branch from 87bd29c to cf098f6 Compare August 3, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant