Skip to content

fix: core: preserve OAS 3.1 numeric exclusive validation constraints in composed schemas#23053

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
raichuchuchu:feature/retry_22943
Feb 25, 2026
Merged

fix: core: preserve OAS 3.1 numeric exclusive validation constraints in composed schemas#23053
wing328 merged 2 commits intoOpenAPITools:masterfrom
raichuchuchu:feature/retry_22943

Conversation

@raichuchuchu
Copy link
Copy Markdown
Contributor

@raichuchuchu raichuchuchu commented Feb 25, 2026

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

PR Description Summary

  • Problem: OAS 3.1 numeric exclusive constraints were lost during code generation, especially when using allOf or model composition.
  • Solution: Synchronized OAS 3.1 numeric validation logic into ModelUtils#syncValidationProperties to ensure constraints are correctly mapped to CodegenProperty even in flattened or composed models.
  • Tests: Added comprehensive test cases in ExclusiveMinMaxTest.java covering OAS 3.0/3.1 syntax, "stricter-wins" logic, and allOf inheritance.

Description

This PR fixes a regression where OpenAPI 3.1 numeric exclusiveMinimum and exclusiveMaximum constraints were lost during code generation, particularly when using model composition (allOf) with $ref.

About Core Logic

Previously, in #22981, handling for OAS 3.1 numeric exclusive constraints was introduced in OpenAPINormalizer.java. However, due to the way OpenAPINormalizer runs early in the pipeline and how it handles recursive schema resolution, constraints were often lost when a model was defined using allOf combined with $ref. The normalization would skip referenced schemas or fail to persist the flags through the flattening process.

This PR synchronizes the "stricter-wins" validation logic into ModelUtils#syncValidationProperties. By handling the conversion from 3.1 numeric values to 3.0 boolean flags at this later stage (during CodegenProperty population), we ensure that:

  1. Validations are correctly preserved even in complex composed/flattened models.
  2. The logic remains robust regardless of whether the OpenAPI Normalizer is enabled.
  3. Legacy OAS 3.0 boolean constraints continue to work as expected.

Notably, this implementation serves as a reliable fail-safe. Even if the normalization logic in OpenAPINormalizer (introduced in #22981) were to be disabled or reverted, the new ExclusiveMinMaxTest.java will still pass. While a revert might cause the specific internal tests in OpenAPINormalizerTest to fail, the focus of this PR is ensuring the behavioral correctness of the final code generation output.

About Test Case

The tests introduced in #22981 (OpenAPINormalizerTest.java) verified the state of the intermediate Schema objects but did not validate the final CodegenProperty output, which is what templates actually use.

I have added ExclusiveMinMaxTest.java, which rewrites and expands these tests to:

  • Verify the final constraints on CodegenProperty.
  • Cover edge cases such as "inclusive boundary being stricter than exclusive boundary."
  • Ensure allOf inheritance correctly propagates exclusive constraints from parent schemas to child properties.

Validation

Verified the fix using:

./mvnw -pl modules/openapi-generator test -Dtest=ExclusiveMinMaxTest

All tests passed, confirming that constraints are now correctly mapped to the generated model properties.

Ran ./bin/generate-samples.sh . No changes observed in existing samples, indicating no regressions for legacy OAS 2.0/3.0 specifications.


Summary by cubic

Fixes preservation of OAS 3.1 numeric exclusiveMinimum/exclusiveMaximum in generated models and composed schemas, and keeps OAS 3.0 behavior intact.

  • Bug Fixes
    • Handle exclusiveMinimumValue/exclusiveMaximumValue (OAS 3.1) in ModelUtils: hasValidation, hasCommonAttributesDefined, and syncValidationProperties.
    • Stricter-wins merge: numeric exclusive values replace min/max when equal or stricter; inclusive stricter bounds remain.
    • Preserve OAS 3.0 boolean exclusive flags as-is.
    • Add tests for 3.1 endpoints and composed models, and new 3.0 spec to verify allOf inheritance and backward compatibility (PriceDto2/3).

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

@raichuchuchu raichuchuchu marked this pull request as ready for review February 25, 2026 04:19
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 5 files

@wing328 wing328 merged commit 5b89b47 into OpenAPITools:master Feb 25, 2026
15 checks passed
@wing328 wing328 added this to the 7.21.0 milestone Feb 25, 2026
@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 25, 2026

lgtm. thanks for the contribution

@raichuchuchu raichuchuchu deleted the feature/retry_22943 branch February 25, 2026 09:48
davidricodias pushed a commit to davidricodias/openapi-generator that referenced this pull request Mar 11, 2026
…in composed schemas (OpenAPITools#23053)

* test: add test case for `ExclusiveMinMax Test`

(OpenAPITools#22943)

* feat: Compatibility with exclusiveMinimum in OpenAPI 3.0.0 vs. 3.1.0

(OpenAPITools#22943)

---------

Co-authored-by: 葉宗原 TsungYuan Yeh <tsungyuan.yeh@tpisoftware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants