Skip to content

[python] centralize the Python constraint rules#24141

Open
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:centralize-python-constraint-rules
Open

[python] centralize the Python constraint rules#24141
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:centralize-python-constraint-rules

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Centralize the handling of applying constraints to different OAS types to remove duplicates (e.g., the current String and Binary logic is the exact same). This also makes it easier to reuse them, for example when creating types that are purely tied to the constraints coming from OAS and not those that may be relevant for different internal Python validators (e.g., Pydantic).

This could also be helpful for the case where you might want to represent constraints differently for different contexts, for example this PR where queries has to be handled differently with how constraints are constructed.

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.

Python technical committee — @cbornet @tomplus @krjakbrjak @fa0311 @multani (@krjakbrjak as the python-fastapi generator author).


Summary by cubic

Centralized how OAS constraints are applied in the Python generator to remove duplicated logic and keep behavior consistent across types. This simplifies future changes and enables context-specific constraint handling.

  • Refactors
    • Added ConstraintApplier and ConstraintType (incl. ROUNDED_NUMBER) to standardize length and numeric rules.
    • Replaced inline constraint code for arrays, strings, binaries, numbers, ints, and decimals in AbstractPythonCodegen; removed PydanticType.applyConstraints and centralized comparison constants.
    • Kept semantics unchanged: inclusive/exclusive bounds, ceil/floor for integer limits, and multiple_of only for non-rounded numeric types.

Written for commit dd8d9e7. 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 1 file

Re-trigger cubic

@Mattias-Sehlstedt Mattias-Sehlstedt force-pushed the centralize-python-constraint-rules branch from 66aa2f6 to dd8d9e7 Compare June 27, 2026 17:05
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