fix(python-flask): import UUID in generated models

Merged
KA
1mo ago
+216-0

Fixes #23897

Description

Generated Python Flask models reference UUID in type annotations without importing it, causing a NameError. Add from uuid import UUID when a model property uses UUID directly or within arrays, maps, object properties, or composition branches.

Models without UUID properties do not receive the import.

Testing

  • Added a regression test checking the generated UUID type and import.
  • Confirmed the test fails without the fix.
  • All 3 tests in PythonFlaskConnexionServerCodegenTest pass with the fix.

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.

@cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10)


Summary by cubic

Fixes python-flask generated models raising NameError for UUID properties, because UUID was used without importing it. Generated models now add from uuid import UUID when a UUID is found anywhere in the property tree, including nested arrays, maps, object properties, and allOf/oneOf/anyOf/not branches. Fixes #23897.

Bug Fixes

  • Adds a recursive property search that safely handles shared and cyclic property graphs.
  • Adds regression tests for nested containers, composed schemas, and a control model without UUIDs.