Skip to content

Conversation

@padznich
Copy link

@padznich padznich commented Dec 30, 2025

for Python 3.11+
anyOf / allOf Root model based
StrEnum, IntEnum

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.

@cbornet
@tomplus
@krjakbrjak
@fa0311
@multani

Fixes issues:


Summary by cubic

Modernizes the Python generator for 3.11+ by adopting Pydantic v2 APIs and RootModel-based unions for anyOf/oneOf. Adds StrEnum/IntEnum, simplifies serialization, and updates client/header handling for urllib3 v2.

  • New Features

    • anyOf/oneOf now use RootModel[Union[...]] with optional discriminator.
    • String and integer enums generate StrEnum/IntEnum.
    • Switch to Pydantic v2 methods (model_validate, model_dump, model_validate_json, model_dump_json).
    • Cleaner exceptions with unified body/data output.
    • ApiClient uses getheader/getheaders and model_validate for deserialization.
  • Migration

    • Requires Python 3.11+; urllib3 >= 2.1.0.
    • Replace:
      • from_json → model_validate_json
      • to_json → model_dump_json(by_alias=True, exclude_unset=True)
      • from_dict → model_validate
      • to_dict → model_dump(by_alias=True)
    • anyOf/oneOf values are on .root.
    • ApiClient now calls klass.model_validate(data); response headers use getheaders() (list of pairs) instead of a mapping. Adjust code that reads headers accordingly.

Written for commit 0ab86bf. Summary will update on new commits.

for Python 3.11+
anyOf / allOf Root model based
StrEnum, IntEnum
Copy link

@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.

6 issues found across 9 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/python/pyproject.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/pyproject.mustache:64">
P2: Inconsistent template variable: poetry1 section uses `{{#asyncio}}` for aiohttp dependencies (line 38), but the non-poetry section uses `{{#async}}` (line 64). These should use the same template variable for consistent behavior across both output formats.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/python/pyproject.mustache:64">
P1: Missing httpx dependency in non-poetry section. The `{{#httpx}}` block was removed from the `{{^poetry1}}` dependencies array, but it still exists in the `{{#poetry1}}` section. Projects using httpx with the modern pyproject.toml format will fail at runtime due to missing dependency.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_generic.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_generic.mustache:34">
P1: Missing field definition for array enum types. When `isEnum=true` AND `isArray=true`, no field is rendered because the `{{^isArray}}` block is skipped but there&#39;s no `{{#isArray}}` handler. Consider adding a fallback or explicit array enum handling.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/python/model_generic.mustache:39">
P2: Single-value enum Literal always uses string quoting. For integer enums (IntEnum mentioned in PR), `Literal[&#39;{{{.}}}&#39;]` will produce `Literal[&#39;1&#39;]` instead of `Literal[1]`. Consider using conditional quoting based on the enum type or using `{{{.}}}` without quotes.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_doc.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_doc.mustache:24">
P1: `model_dump_json()` is an instance method in Pydantic v2 and must be called on the instance variable, not the class. This code will fail at runtime with a `TypeError`.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:13">
P2: Redundant imports: `Literal` and `Union` are imported from both `typing` and `typing_extensions`. Since this is for Python 3.11+, these are already available in `typing`. The `typing_extensions` import should only include `Self` (or be removed entirely since `Self` is also in `typing` for 3.11+).</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

{{/poetry1}}
keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"]
{{#poetry1}}
include = ["{{packageName}}/py.typed"]
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 30, 2025

Choose a reason for hiding this comment

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

P1: Missing httpx dependency in non-poetry section. The {{#httpx}} block was removed from the {{^poetry1}} dependencies array, but it still exists in the {{#poetry1}} section. Projects using httpx with the modern pyproject.toml format will fail at runtime due to missing dependency.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/pyproject.mustache, line 64:

<comment>Missing httpx dependency in non-poetry section. The `{{#httpx}}` block was removed from the `{{^poetry1}}` dependencies array, but it still exists in the `{{#poetry1}}` section. Projects using httpx with the modern pyproject.toml format will fail at runtime due to missing dependency.</comment>

<file context>
@@ -58,20 +56,15 @@ lazy-imports = &quot;&gt;= 1, &lt; 2&quot;
-  &quot;httpx (&gt;=0.28.1)&quot;,
-{{/httpx}}
-{{#asyncio}}
+{{#async}}
   &quot;aiohttp (&gt;=3.8.4)&quot;,
   &quot;aiohttp-retry (&gt;=2.8.3)&quot;,
</file context>
Suggested change
include = ["{{packageName}}/py.typed"]
{{#httpx}}
"httpx (>=0.28.1)",
{{/httpx}}
{{#async}}
Fix with Cubic

Copy link
Author

Choose a reason for hiding this comment

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

Copy link

@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.

33 issues found across 965 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/python/model_oneof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:30">
P2: Calling `hasattr(self, &#39;root&#39;)` inside `__getattr__` risks infinite recursion. Use `self.__dict__.get(&#39;root&#39;)` instead to safely check for the attribute without triggering recursive `__getattr__` calls.</violation>
</file>

<file name="samples/client/echo_api/python/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md">

<violation number="1" location="samples/client/echo_api/python/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md:23">
P1: `model_dump_json()` should be called on the instance, not the class. This will fail at runtime since `model_dump_json` is an instance method in Pydantic v2.</violation>
</file>

<file name="samples/client/echo_api/python/docs/DataQuery.md">

<violation number="1" location="samples/client/echo_api/python/docs/DataQuery.md:22">
P1: `model_dump_json` is an instance method in Pydantic v2, not a class method. This should be called on `data_query_instance` to serialize the object that was just created from JSON.</violation>
</file>

<file name="samples/client/echo_api/python/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md">

<violation number="1" location="samples/client/echo_api/python/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md:20">
P1: `model_dump_json()` is an instance method in Pydantic v2, not a class method. This should be called on the instance (`test_query_style_form_explode_true_array_string_query_object_parameter_instance`) rather than the class, otherwise it will raise an AttributeError.</violation>
</file>

<file name="samples/client/echo_api/python/docs/TestFormObjectMultipartRequestMarker.md">

<violation number="1" location="samples/client/echo_api/python/docs/TestFormObjectMultipartRequestMarker.md:20">
P1: `model_dump_json()` is an instance method in Pydantic v2 but is being called on the class. This should be called on the instance `test_form_object_multipart_request_marker_instance` that was created on the previous line.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Tag.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Tag.md:21">
P1: Incorrect method call: `model_dump_json()` is an instance method in Pydantic v2, not a class method. This should be called on `tag_instance` instead of `Tag`.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/pyproject.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/pyproject.mustache:64">
P1: Missing httpx dependency in non-poetry1 section. The `{{#httpx}}` block with the httpx dependency was removed, but it&#39;s still present in the poetry1 section. When using the httpx library option, the generated pyproject.toml won&#39;t include httpx as a required dependency, causing import failures at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md:28">
P1: `model_dump_json()` is an instance method in Pydantic v2 and must be called on the instance, not the class. This should use `default_value_instance.model_dump_json(...)` to match the previous behavior of `to_json()`.</violation>
</file>

<file name="samples/client/echo_api/python/docs/Pet.md">

<violation number="1" location="samples/client/echo_api/python/docs/Pet.md:25">
P1: `model_dump_json()` is an instance method in Pydantic v2, not a class method. This should be called on `pet_instance` instead of the class `Pet`.</violation>
</file>

<file name="samples/client/echo_api/python/docs/Query.md">

<violation number="1" location="samples/client/echo_api/python/docs/Query.md:21">
P2: `model_dump_json()` is an instance method in Pydantic v2, but it&#39;s being called on the class `Query` instead of the instance `query_instance`. This example code will raise a `TypeError` when executed.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py:18">
P2: Duplicate import of `Annotated`: imported from `typing` here but also still imported from `typing_extensions` on line 22. The `typing_extensions` import shadows this one, making it redundant. Since this PR targets Python 3.11+, the `typing_extensions` import on line 22 should be removed instead.</violation>
</file>

<file name="samples/client/echo_api/python/docs/Category.md">

<violation number="1" location="samples/client/echo_api/python/docs/Category.md:21">
P1: `model_dump_json` is an instance method in Pydantic v2, not a class method. This should be called on `category_instance` instead of the `Category` class, otherwise it will raise a `TypeError`.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestFormObjectMultipartRequestMarker.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestFormObjectMultipartRequestMarker.md:20">
P1: `model_dump_json()` is an instance method in Pydantic v2, but it&#39;s being called on the class. This will raise an error at runtime. It should be called on `test_form_object_multipart_request_marker_instance` instead.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_doc.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_doc.mustache:24">
P1: `model_dump_json()` is an instance method in Pydantic v2, but it&#39;s being called on the class instead of the instance. This will cause an `AttributeError` at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md:20">
P1: `model_dump_json()` is an instance method in Pydantic v2, but it&#39;s being called on the class instead of the instance. This will raise a TypeError at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md:23">
P1: `model_dump_json` is an instance method in Pydantic v2, not a class method. This should be called on the instance `test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance` instead of the class.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/api/body_api.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/api/body_api.py:18">
P3: This import is immediately shadowed by `from typing_extensions import Annotated` on line 22, making it redundant. Either remove this line or remove the duplicate `typing_extensions` import below.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/pet.py:37">
P0: `StatusEnum` is used as a type annotation but is never defined or imported. This will cause a `NameError` when the module is imported.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_generic.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_generic.mustache:33">
P1: Missing field definition for array-typed enum fields. When `isEnum` is true AND `isArray` is true, no field definition is generated because the only rendering path is inside `{{^isArray}}`. This would cause missing fields in generated models for OpenAPI specs with array enum properties.</violation>
</file>

<file name="samples/client/echo_api/python/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python/docs/DefaultValue.md:28">
P1: `model_dump_json()` is an instance method in Pydantic v2, not a class method. This should be called on `default_value_instance` to print the JSON representation of the object created earlier.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DataQuery.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DataQuery.md:22">
P1: `model_dump_json()` is an instance method in Pydantic v2 and should be called on `data_query_instance`, not on the class `DataQuery`. This will raise a `TypeError` at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md:25">
P1: `model_dump_json` is an instance method in Pydantic v2, not a class method. This should be called on `pet_instance` rather than the `Pet` class to avoid a runtime TypeError.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/exceptions.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/exceptions.mustache:160">
P2: Using `or` operator to select between `data` and `body` fails for falsy but valid data values like empty dicts/lists. If `self.data` is `{}` or `[]`, it will incorrectly show `self.body` instead. Consider using explicit `None` checks:
```python
if self.data is not None or self.body:
    error_message += &quot;HTTP response body: {0}\n&quot;.format(self.data if self.data is not None else self.body)
```</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py:37">
P0: `StatusEnum` is used as a type annotation but is not defined or imported anywhere in this file. This will cause a `NameError: name &#39;StatusEnum&#39; is not defined` when the module loads.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/NumberPropertiesOnly.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/NumberPropertiesOnly.md:22">
P1: `model_dump_json()` is an instance method in Pydantic v2, but it&#39;s being called on the class instead of the instance. This documentation example will fail at runtime.</violation>
</file>

<file name="samples/client/echo_api/python/docs/Tag.md">

<violation number="1" location="samples/client/echo_api/python/docs/Tag.md:21">
P1: `model_dump_json()` is an instance method in Pydantic v2 and must be called on an instance, not the class. This should be `tag_instance.model_dump_json(...)` to match the created instance from the previous line.</violation>
</file>

<file name="samples/client/echo_api/python/docs/NumberPropertiesOnly.md">

<violation number="1" location="samples/client/echo_api/python/docs/NumberPropertiesOnly.md:22">
P1: `model_dump_json()` is a Pydantic v2 instance method but is being called on the class instead of the instance. This will cause a `TypeError` at runtime. Should be called on `number_properties_only_instance` instead of `NumberPropertiesOnly`.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:34">
P2: Using `hasattr(self, &#39;root&#39;)` inside `__getattr__` can cause infinite recursion. When `root` isn&#39;t accessible through normal attribute lookup, `hasattr` triggers `__getattr__(&#39;root&#39;)` which calls `hasattr(self, &#39;root&#39;)` again. Use `object.__getattribute__` instead.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Category.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Category.md:21">
P1: `model_dump_json()` is an instance method in Pydantic v2 and must be called on `category_instance`, not on the `Category` class. This example code will fail at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md:21">
P1: `model_dump_json()` is an instance method in Pydantic v2, but it&#39;s being called on the class `Bird` instead of the instance `bird_instance`. This documentation example will not work as written.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_enum.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_enum.mustache:25">
P2: Using `{{name}}` (double braces) instead of `{{{name}}}` (triple braces) causes HTML escaping of enum member names, which could corrupt identifiers containing special characters. This is also inconsistent with `{{{value}}}` on the same line which remains unescaped.</violation>
</file>

<file name="samples/client/echo_api/python/docs/Bird.md">

<violation number="1" location="samples/client/echo_api/python/docs/Bird.md:21">
P1: `model_dump_json()` is an instance method in Pydantic v2, not a class method. This should be called on `bird_instance` rather than the `Bird` class. The current code will raise a `TypeError` at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Query.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Query.md:21">
P1: `model_dump_json()` is an instance method in Pydantic v2, not a class method. Should be called on `query_instance` instead of `Query`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@plaes
Copy link

plaes commented Jan 13, 2026

Looks a like an excellent cleanup (and improvement), though I don't like the unexpected removal of existing methods: from_dict/from_json and to_dict/to_json. I would keep these for at least a few versions, but with @warnings.deprecated annotation.

And unfortunately doesn't seem to be a solution for #22687. - seems to be core issue.

./mvnw clean package || exit
./bin/generate-samples.sh ./bin/configs/*.yaml || exit
./bin/utils/export_docs_generators.sh || exit
Copy link

@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.

22 issues found across 965 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/python/setup.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/setup.mustache:14">
P2: PYTHON_REQUIRES set to ">= 3.11" but never passed to setup(); generated package won’t enforce the minimum Python version.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/exceptions.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/exceptions.py:172">
P2: Parsed response data replaces raw body in error message, hiding the actual HTTP body and mislabeling parsed data as the body.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_oneof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:11">
P2: Unused and duplicate imports added (BaseModel, ConfigDict, StrictStr, model_validator, Any, List, Set, Optional, Dict, Literal, Self; Union imported twice) making generated code fail linting</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:15">
P2: oneOf exclusivity no longer enforced; RootModel Union parsing can accept inputs matching multiple schemas without error, unlike prior explicit match-counting validator</violation>

<violation number="3" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:19">
P2: Nullable oneOf schemas no longer accept None: root is required and Union excludes Optional/None, breaking nullable oneOf handling</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py:25">
P2: Minimum Python version not enforced: PYTHON_REQUIRES is defined/updated but not passed to setup(), so install metadata won’t block unsupported Python versions.</violation>
</file>

<file name="samples/client/echo_api/python/setup.py">

<violation number="1" location="samples/client/echo_api/python/setup.py:25">
P2: Python version requirement updated to ">= 3.11" but not passed to setup(); package metadata will not enforce this minimum version.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/category.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/category.py:23">
P2: Unused and duplicate imports added: Set/Literal/Self/Field are unused and Optional is imported twice.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/default_value.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/default_value.py:32">
P2: Field uses undefined type and incompatible nested list annotation, causing NameError/TypeError in validation</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py:37">
P1: `StatusEnum` is undefined and not imported; the `status` field annotation references a missing type, causing Pydantic model resolution to fail.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/query.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/query.py:31">
P1: Nested `outcomes` type is validated as flat list, causing `TypeError: unhashable list` on valid inputs</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md:28">
P2: Doc example hides default values: exclude_unset=True omits defaulted fields after validating empty input, defeating the default-value demonstration.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py:32">
P1: Undefined enum type and mismatched nested list annotation will break model build/validation for `array_string_enum_default`.</violation>
</file>

<file name="samples/client/echo_api/python/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python/docs/DefaultValue.md:28">
P2: Example hides default-valued fields by using exclude_unset=True, so the default-value demo outputs an empty object.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/api_client.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/api_client.mustache:719">
P1: Downloaded file path uses unsanitized Content-Disposition filename, allowing path traversal writes outside temp directory.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/pet.py:37">
P1: `StatusEnum` referenced in field annotation but never defined or imported, causing unresolved annotation at runtime</violation>

<violation number="2" location="samples/client/echo_api/python/openapi_client/models/pet.py:61">
P2: Removed Pet serialization helpers while other code still calls them; Pet.from_json/to_json/to_dict/from_dict now raise AttributeError</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/number_properties_only.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/number_properties_only.py:24">
P2: Redundant/unused imports added (duplicate Optional/Field and unused Set/Literal/Self) after helper removal</violation>

<violation number="2" location="samples/client/echo_api/python/openapi_client/models/number_properties_only.py:24">
P1: Removed serialization helpers while call sites remain: `NumberPropertiesOnly.from_json` is still used and will now fail with AttributeError.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/api_client.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/api_client.py:384">
P2: `model_dump` result may be scalar; `.items()` call will raise for RootModel serialization</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:12">
P2: Unused imports added/left over; symbols like Literal, Self, getfullargspec, json, pprint, TYPE_CHECKING, etc. are not used in the generated anyOf model, causing unused-import lint failures.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:23">
P1: Nullable anyOf schemas now reject null because the required root Union field no longer includes Optional/nullable handling.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +37 to +39
status: Optional[StatusEnum] = Field(
None,
description="pet status in the store"
Copy link

Choose a reason for hiding this comment

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

P1: StatusEnum is undefined and not imported; the status field annotation references a missing type, causing Pydantic model resolution to fail.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py, line 37:

<comment>`StatusEnum` is undefined and not imported; the `status` field annotation references a missing type, causing Pydantic model resolution to fail.</comment>

<file context>
@@ -34,7 +34,10 @@ class Pet(BaseModel):
     photo_urls: List[StrictStr] = Field(alias="photoUrls")
     tags: Optional[List[Tag]] = None
-    status: Optional[StrictStr] = Field(default=None, description="pet status in the store")
+    status: Optional[StatusEnum] = Field(
+        None,
+        description="pet status in the store"
</file context>
Suggested change
status: Optional[StatusEnum] = Field(
None,
description="pet status in the store"
status: Optional[Literal["available", "pending", "sold"]] = Field(
None,
description="pet status in the store"
)

./mvnw clean package || exit
./bin/generate-samples.sh ./bin/configs/*.yaml || exit
./bin/utils/export_docs_generators.sh || exit
filename = os.path.basename(m.group(1))
Copy link

@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.

28 issues found across 965 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/echo_api/python/openapi_client/models/category.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/category.py:23">
P3: Unused typing imports (Optional/Set/Literal/Self) were added but never referenced, leading to lint/type-check failures and unnecessary noise.</violation>

<violation number="2" location="samples/client/echo_api/python/openapi_client/models/category.py:24">
P3: Unused pydantic Field import was added but never used, causing lint failures and dead code.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md:28">
P2: Documentation example hides defaulted fields by using exclude_unset=True, so the sample prints `{}` instead of showing defaults.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/default_value.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/default_value.py:32">
P1: `array_string_enum_default` references undefined enum type and is typed as nested list, conflicting with validator and causing model build/validation failure.</violation>
</file>

<file name="samples/client/echo_api/python/setup.py">

<violation number="1" location="samples/client/echo_api/python/setup.py:25">
P2: Python 3.11+ requirement is defined but not enforced in setup() because python_requires is omitted.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py:37">
P1: `StatusEnum` annotation is undefined; model references a non-existent type causing runtime resolution failure</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py:31">
P2: `OutcomesEnum` is referenced in the `outcomes` annotation but is not imported/defined, causing Pydantic to fail when resolving the model.</violation>

<violation number="2" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py:31">
P1: `outcomes` validator rejects all non-empty nested lists: it now checks list items against strings instead of iterating inner enum values, so valid inputs fail validation.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/query.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/query.py:31">
P1: `OutcomesEnum` is referenced in the outcomes type annotation but is never defined or imported, so the model will error when Pydantic resolves annotations.</violation>

<violation number="2" location="samples/client/echo_api/python/openapi_client/models/query.py:31">
P1: Validator still treats outcomes as a flat string list; with the new nested list type this membership check hashes a list and raises TypeError, preventing valid data from passing validation.</violation>
</file>

<file name="samples/client/echo_api/python/pyproject.toml">

<violation number="1" location="samples/client/echo_api/python/pyproject.toml:11">
P2: Python version requirement bumped to 3.11 while README still promises support for 3.9+, leading to installation failure for users on 3.9/3.10 following the docs.</violation>
</file>

<file name="samples/client/echo_api/python/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python/docs/DefaultValue.md:28">
P2: Default-value example omits defaults because `exclude_unset=True` drops defaulted fields, so the sample prints `{}` instead of showing defaults.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py:25">
P2: Duplicate and unused imports introduced (Optional/Field re-imported; Set/Literal/Self unused), likely to trigger lint errors.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_oneof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:13">
P2: Forward-ref handling removed: oneOf RootModel no longer runs postponed imports or model_rebuild, so generated models with circular/forward refs will fail.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:17">
P2: Strict oneOf exclusivity validation removed; Union parsing now accepts ambiguous inputs instead of rejecting 0 or multiple matches</violation>

<violation number="3" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:17">
P2: Nullable oneOf models are no longer supported; generated model requires a non-null root even when schema is nullable.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py:384">
P1: `model_dump` on Pydantic RootModel can return a primitive; code assumes dict and will crash calling `.items()`.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/exceptions.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/exceptions.mustache:161">
P2: ApiException __str__ now drops one of body/data and mislabels data as body due to `self.data or self.body`</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py:18">
P2: Annotated is imported from typing but then immediately shadowed by a later import from typing_extensions, leaving duplicate/contradictory imports and keeping the typing_extensions dependency.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/number_properties_only.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/number_properties_only.py:47">
P1: Removed serialization helpers (`from_json`/`to_json`/`from_dict`) break existing calls; NumberPropertiesOnly no longer provides these methods but tests still invoke them, leading to AttributeError at runtime.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py:172">
P2: Error message now drops either the raw body or parsed data when both are present, reducing debugging information.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/pet.py:37">
P1: `StatusEnum` is referenced in the status field annotation but is not defined or imported, causing runtime failures when Pydantic resolves annotations.</violation>

<violation number="2" location="samples/client/echo_api/python/openapi_client/models/pet.py:61">
P1: Removed Pet serialization helpers (`to_json/from_json/to_dict/from_dict`) but callers/tests still invoke them, causing AttributeError.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py:23">
P2: Unused and duplicate imports (`Optional`, `Set`, `Literal`, `Self`, `Field`) were added; they aren’t referenced anywhere, so linting (F401) will fail.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_generic.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_generic.mustache:38">
P2: Non-required single-value enums are typed as non-optional Literal while defaulting to None, causing a type/validation mismatch.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:15">
P2: Assignment-time validation and protected namespace overrides were removed from anyOf models, changing behavior and allowing invalid root assignments</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py:32">
P1: array_string_enum_default references an undefined type and uses an incorrect nested list type that breaks validation</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/api_client.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/api_client.py:384">
P1: RootModel outputs from model_dump can be primitives, so obj_dict.items() will raise AttributeError during serialization</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

photo_urls: List[StrictStr] = Field(alias="photoUrls")
tags: Optional[List[Tag]] = None
status: Optional[StrictStr] = Field(default=None, description="pet status in the store")
status: Optional[StatusEnum] = Field(
Copy link

Choose a reason for hiding this comment

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

P1: StatusEnum annotation is undefined; model references a non-existent type causing runtime resolution failure

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py, line 37:

<comment>`StatusEnum` annotation is undefined; model references a non-existent type causing runtime resolution failure</comment>

<file context>
@@ -34,7 +34,10 @@ class Pet(BaseModel):
     photo_urls: List[StrictStr] = Field(alias="photoUrls")
     tags: Optional[List[Tag]] = None
-    status: Optional[StrictStr] = Field(default=None, description="pet status in the store")
+    status: Optional[StatusEnum] = Field(
+        None,
+        description="pet status in the store"
</file context>
Suggested change
status: Optional[StatusEnum] = Field(
from openapi_client.models.status_enum import StatusEnum
...
status: Optional[StatusEnum] = Field(
None,
description="pet status in the store"
)

{{#-first}}
{{#-last}}
{{! Single value enum - use Literal }}
{{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
Copy link

Choose a reason for hiding this comment

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

P2: Non-required single-value enums are typed as non-optional Literal while defaulting to None, causing a type/validation mismatch.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/model_generic.mustache, line 38:

<comment>Non-required single-value enums are typed as non-optional Literal while defaulting to None, causing a type/validation mismatch.</comment>

<file context>
@@ -28,7 +28,40 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
+          {{#-first}}
+            {{#-last}}
+              {{! Single value enum - use Literal }}
+    {{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
+        {{#required}}...{{/required}}{{^required}}None{{/required}},
+        description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}"
</file context>
Suggested change
{{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
{{name}}: {{#required}}Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}]{{/required}}{{^required}}Optional[Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}]]{{/required}} = Field(

./mvnw clean package || exit
./bin/generate-samples.sh ./bin/configs/*.yaml || exit
./bin/utils/export_docs_generators.sh || exi
Copy link

@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.

22 issues found across 965 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/echo_api/python/openapi_client/models/number_properties_only.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/number_properties_only.py:47">
P1: Removed `from_json`/`to_json` helpers while tests still call them, causing AttributeError</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md:23">
P2: Docs example validates an empty JSON string, which raises ValidationError because required fields (name, photoUrls) are missing.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py:23">
P3: Unused imports (Set, Literal, Self, Field) were introduced but are never referenced after removing the serialization helpers, leaving dead code that will trip lint/static checks.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md:28">
P2: Default-value example omits defaults by using `exclude_unset=True`, so printing from `{}` hides defaulted fields and misleads the example.</violation>
</file>

<file name="samples/client/echo_api/python/docs/DefaultValue.md">

<violation number="1" location="samples/client/echo_api/python/docs/DefaultValue.md:28">
P2: Doc example hides default values by using exclude_unset=True, so printing from '{}' shows an empty JSON instead of the defaults the doc aims to demonstrate.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/default_value.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/default_value.py:32">
P1: `array_string_enum_default` uses an undefined enum type and validator logic that doesn’t match its nested list annotation, causing import/validation errors.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py:47">
P1: Removed serialization helpers (`from_json`/`to_json`/`from_dict`/`to_dict`) while tests still call them, causing AttributeError.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py:32">
P1: `array_string_enum_default` now refers to an undefined enum and the validator still expects a flat list, leading to import/validation failures.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/exceptions.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/exceptions.py:171">
P2: Error message now collapses body and data, hiding one and mislabeling parsed data as body when both are set</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/setup.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/setup.mustache:14">
P2: Minimum Python version (>=3.11) is not enforced because python_requires is never passed to setup()</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py:37">
P1: `StatusEnum` is referenced in the `status` annotation but is not defined or imported, causing Pydantic to fail resolving the type at runtime.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/pet.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/pet.py:37">
P1: Undefined type `StatusEnum` used in `status` annotation causes model import/validation failure.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_oneof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:13">
P1: oneOf uniqueness enforcement removed; ambiguous payloads now validate via plain Union</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/string_enum_ref.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/string_enum_ref.py:18">
P2: Unused imports Enum and IntEnum are added but never used, which can trigger lint failures or add unnecessary noise.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_generic.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_generic.mustache:38">
P2: Enum fields lack alias mapping, so JSON keys differing from the Python attribute won’t serialize/deserialize correctly</violation>
</file>

<file name="samples/client/echo_api/python/setup.py">

<violation number="1" location="samples/client/echo_api/python/setup.py:25">
P2: Updated PYTHON_REQUIRES is unused—setup() omits python_requires, so the minimum Python version isn’t enforced from this setup.py.</violation>
</file>

<file name="samples/client/echo_api/python/openapi_client/models/query.py">

<violation number="1" location="samples/client/echo_api/python/openapi_client/models/query.py:31">
P2: `OutcomesEnum` is referenced in the `outcomes` annotation but is never imported or defined, causing Pydantic type resolution to fail at runtime.</violation>

<violation number="2" location="samples/client/echo_api/python/openapi_client/models/query.py:31">
P1: Validator rejects valid nested outcomes because it still assumes a flat list of enum strings after outcomes became a list of lists.</violation>
</file>

<file name="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py">

<violation number="1" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py:31">
P1: Missing import/definition for `OutcomesEnum` makes the `outcomes` annotation undefined, causing model build/import failure.</violation>

<violation number="2" location="samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py:31">
P1: `outcomes` now declared as nested list but validator still flat, causing TypeError/unusable validation for any non-null value</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:15">
P2: Nullable anyOf root models no longer accept `null`/`None` because the root union and Field are required and exclude `None`.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:15">
P1: RootModel base evaluates anyOf types before postponed imports, risking NameError when any union member is only imported in the deferred block.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

"double": obj.get("double")
})
return _obj

Copy link

Choose a reason for hiding this comment

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

P1: Removed serialization helpers (from_json/to_json/from_dict/to_dict) while tests still call them, causing AttributeError.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py, line 47:

<comment>Removed serialization helpers (`from_json`/`to_json`/`from_dict`/`to_dict`) while tests still call them, causing AttributeError.</comment>

<file context>
@@ -44,55 +44,5 @@ def to_str(self) -> str:
-            "double": obj.get("double")
-        })
-        return _obj
 
 
</file context>
Suggested change
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return self.model_dump_json(by_alias=True, exclude_none=True)
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of NumberPropertiesOnly from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias."""
_dict = self.model_dump(by_alias=True, exclude_none=True)
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of NumberPropertiesOnly from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in NumberPropertiesOnly) in the input: " + _key)
return cls.model_validate({
"number": obj.get("number"),
"float": obj.get("float"),
"double": obj.get("double")
})

Comment on lines +32 to +35
array_string_enum_default: Optional[List[List[Array_string_enum_defaultEnum]]] = Field(
None,
description="array_string_enum_default of the DefaultValue"
)
Copy link

Choose a reason for hiding this comment

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

P1: array_string_enum_default now refers to an undefined enum and the validator still expects a flat list, leading to import/validation failures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py, line 32:

<comment>`array_string_enum_default` now refers to an undefined enum and the validator still expects a flat list, leading to import/validation failures.</comment>

<file context>
@@ -21,15 +21,18 @@
     """ # noqa: E501
     array_string_enum_ref_default: Optional[List[StringEnumRef]] = None
-    array_string_enum_default: Optional[List[StrictStr]] = None
+    array_string_enum_default: Optional[List[List[Array_string_enum_defaultEnum]]] = Field(
+        None,
+        description="array_string_enum_default of the DefaultValue"
</file context>
Suggested change
array_string_enum_default: Optional[List[List[Array_string_enum_defaultEnum]]] = Field(
None,
description="array_string_enum_default of the DefaultValue"
)
array_string_enum_default: Optional[List[StrictStr]] = Field(
None,
description="array_string_enum_default of the DefaultValue"
)

photo_urls: List[StrictStr] = Field(alias="photoUrls")
tags: Optional[List[Tag]] = None
status: Optional[StrictStr] = Field(default=None, description="pet status in the store")
status: Optional[StatusEnum] = Field(
Copy link

Choose a reason for hiding this comment

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

P1: StatusEnum is referenced in the status annotation but is not defined or imported, causing Pydantic to fail resolving the type at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py, line 37:

<comment>`StatusEnum` is referenced in the `status` annotation but is not defined or imported, causing Pydantic to fail resolving the type at runtime.</comment>

<file context>
@@ -34,7 +34,10 @@ class Pet(BaseModel):
     photo_urls: List[StrictStr] = Field(alias="photoUrls")
     tags: Optional[List[Tag]] = None
-    status: Optional[StrictStr] = Field(default=None, description="pet status in the store")
+    status: Optional[StatusEnum] = Field(
+        None,
+        description="pet status in the store"
</file context>

Comment on lines +38 to +41
{{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
{{#required}}...{{/required}}{{^required}}None{{/required}},
description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}"
)
Copy link

Choose a reason for hiding this comment

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

P2: Enum fields lack alias mapping, so JSON keys differing from the Python attribute won’t serialize/deserialize correctly

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/model_generic.mustache, line 38:

<comment>Enum fields lack alias mapping, so JSON keys differing from the Python attribute won’t serialize/deserialize correctly</comment>

<file context>
@@ -28,7 +28,40 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
+          {{#-first}}
+            {{#-last}}
+              {{! Single value enum - use Literal }}
+    {{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
+        {{#required}}...{{/required}}{{^required}}None{{/required}},
+        description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}"
</file context>
Suggested change
{{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
{{#required}}...{{/required}}{{^required}}None{{/required}},
description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}"
)
{{name}}: Literal[{{#isString}}"{{{.}}}"{{/isString}}{{^isString}}{{{.}}}{{/isString}}] = Field(
{{#required}}...{{/required}}{{^required}}None{{/required}},
description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}",
alias="{{{baseName}}}"
)

NAME = "openapi-client"
VERSION = "1.0.0"
PYTHON_REQUIRES = ">= 3.9"
PYTHON_REQUIRES = ">= 3.11"
Copy link

Choose a reason for hiding this comment

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

P2: Updated PYTHON_REQUIRES is unused—setup() omits python_requires, so the minimum Python version isn’t enforced from this setup.py.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python/setup.py, line 25:

<comment>Updated PYTHON_REQUIRES is unused—setup() omits python_requires, so the minimum Python version isn’t enforced from this setup.py.</comment>

<file context>
@@ -23,7 +22,7 @@
 NAME = "openapi-client"
 VERSION = "1.0.0"
-PYTHON_REQUIRES = ">= 3.9"
+PYTHON_REQUIRES = ">= 3.11"
 REQUIRES = [
     "urllib3 >= 2.1.0, < 3.0.0",
</file context>

""" # noqa: E501
id: Optional[StrictInt] = Field(default=None, description="Query")
outcomes: Optional[List[StrictStr]] = None
outcomes: Optional[List[List[OutcomesEnum]]] = Field(
Copy link

Choose a reason for hiding this comment

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

P2: OutcomesEnum is referenced in the outcomes annotation but is never imported or defined, causing Pydantic type resolution to fail at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python/openapi_client/models/query.py, line 31:

<comment>`OutcomesEnum` is referenced in the `outcomes` annotation but is never imported or defined, causing Pydantic type resolution to fail at runtime.</comment>

<file context>
@@ -20,15 +20,18 @@
     """ # noqa: E501
     id: Optional[StrictInt] = Field(default=None, description="Query")
-    outcomes: Optional[List[StrictStr]] = None
+    outcomes: Optional[List[List[OutcomesEnum]]] = Field(
+        None,
+        description="outcomes of the Query"
</file context>

Comment on lines 15 to 22
class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]):
"""
{{{description}}}{{^description}}{{{classname}}}{{/description}}
"""

{{#composedSchemas.anyOf}}
# data type: {{{dataType}}}
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
{{/composedSchemas.anyOf}}
if TYPE_CHECKING:
actual_instance: Optional[Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}]] = None
else:
actual_instance: Any = None
any_of_schemas: Set[str] = { {{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}} }

model_config = {
"validate_assignment": True,
"protected_namespaces": (),
}
{{#discriminator}}

discriminator_value_class_map: Dict[str, str] = {
{{#children}}
'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}}
{{/children}}
}
{{/discriminator}}

def __init__(self, *args, **kwargs) -> None:
if args:
if len(args) > 1:
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
if kwargs:
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
super().__init__(actual_instance=args[0])
else:
super().__init__(**kwargs)

@field_validator('actual_instance')
def actual_instance_must_validate_anyof(cls, v):
{{#isNullable}}
if v is None:
return v

{{/isNullable}}
instance = {{{classname}}}.model_construct()
error_messages = []
{{#composedSchemas.anyOf}}
# validate data type: {{{dataType}}}
{{#isContainer}}
try:
instance.{{vendorExtensions.x-py-name}} = v
return v
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
try:
instance.{{vendorExtensions.x-py-name}} = v
return v
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isPrimitiveType}}
{{^isPrimitiveType}}
if not isinstance(v, {{{dataType}}}):
error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`")
else:
return v

{{/isPrimitiveType}}
{{/isContainer}}
{{/composedSchemas.anyOf}}
if error_messages:
# no match
raise ValueError("No match found when setting the actual_instance in {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages))
else:
return v

@classmethod
def from_dict(cls, obj: Dict[str, Any]) -> Self:
return cls.from_json(json.dumps(obj))

@classmethod
def from_json(cls, json_str: str) -> Self:
"""Returns the object represented by the json string"""
instance = cls.model_construct()
{{#isNullable}}
if json_str is None:
return instance

{{/isNullable}}
error_messages = []
{{#composedSchemas.anyOf}}
{{#isContainer}}
# deserialize data into {{{dataType}}}
try:
# validation
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
# assign value to actual_instance
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
# deserialize data into {{{dataType}}}
try:
# validation
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
# assign value to actual_instance
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isPrimitiveType}}
{{^isPrimitiveType}}
# {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
try:
instance.actual_instance = {{{dataType}}}.from_json(json_str)
return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isPrimitiveType}}
{{/isContainer}}
{{/composedSchemas.anyOf}}

if error_messages:
# no match
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages))
else:
return instance

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
if self.actual_instance is None:
return "null"
root: Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}] = Field(
...{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}}
)
Copy link

Choose a reason for hiding this comment

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

P2: Nullable anyOf root models no longer accept null/None because the root union and Field are required and exclude None.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/model_anyof.mustache, line 15:

<comment>Nullable anyOf root models no longer accept `null`/`None` because the root union and Field are required and exclude `None`.</comment>

<file context>
@@ -1,177 +1,40 @@
 
-class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}):
+
+class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]):
     """
     {{{description}}}{{^description}}{{{classname}}}{{/description}}
</file context>
Suggested change
class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]):
"""
{{{description}}}{{^description}}{{{classname}}}{{/description}}
"""
{{#composedSchemas.anyOf}}
# data type: {{{dataType}}}
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
{{/composedSchemas.anyOf}}
if TYPE_CHECKING:
actual_instance: Optional[Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}]] = None
else:
actual_instance: Any = None
any_of_schemas: Set[str] = { {{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}} }
model_config = {
"validate_assignment": True,
"protected_namespaces": (),
}
{{#discriminator}}
discriminator_value_class_map: Dict[str, str] = {
{{#children}}
'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}}
{{/children}}
}
{{/discriminator}}
def __init__(self, *args, **kwargs) -> None:
if args:
if len(args) > 1:
raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
if kwargs:
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
super().__init__(actual_instance=args[0])
else:
super().__init__(**kwargs)
@field_validator('actual_instance')
def actual_instance_must_validate_anyof(cls, v):
{{#isNullable}}
if v is None:
return v
{{/isNullable}}
instance = {{{classname}}}.model_construct()
error_messages = []
{{#composedSchemas.anyOf}}
# validate data type: {{{dataType}}}
{{#isContainer}}
try:
instance.{{vendorExtensions.x-py-name}} = v
return v
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
try:
instance.{{vendorExtensions.x-py-name}} = v
return v
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isPrimitiveType}}
{{^isPrimitiveType}}
if not isinstance(v, {{{dataType}}}):
error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`")
else:
return v
{{/isPrimitiveType}}
{{/isContainer}}
{{/composedSchemas.anyOf}}
if error_messages:
# no match
raise ValueError("No match found when setting the actual_instance in {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages))
else:
return v
@classmethod
def from_dict(cls, obj: Dict[str, Any]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
def from_json(cls, json_str: str) -> Self:
"""Returns the object represented by the json string"""
instance = cls.model_construct()
{{#isNullable}}
if json_str is None:
return instance
{{/isNullable}}
error_messages = []
{{#composedSchemas.anyOf}}
{{#isContainer}}
# deserialize data into {{{dataType}}}
try:
# validation
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
# assign value to actual_instance
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
# deserialize data into {{{dataType}}}
try:
# validation
instance.{{vendorExtensions.x-py-name}} = json.loads(json_str)
# assign value to actual_instance
instance.actual_instance = instance.{{vendorExtensions.x-py-name}}
return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isPrimitiveType}}
{{^isPrimitiveType}}
# {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
try:
instance.actual_instance = {{{dataType}}}.from_json(json_str)
return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
{{/isPrimitiveType}}
{{/isContainer}}
{{/composedSchemas.anyOf}}
if error_messages:
# no match
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages))
else:
return instance
def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
if self.actual_instance is None:
return "null"
root: Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}] = Field(
...{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}}
)
class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}{{#isNullable}}, None{{/isNullable}}]]):
"""
{{{description}}}{{^description}}{{{classname}}}{{/description}}
"""
root: Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}{{#isNullable}}, None{{/isNullable}}] = Field(
{{#isNullable}}None{{/isNullable}}{{^isNullable}}...{{/isNullable}}{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}}
)

from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self
from typing import Optional, Set, Literal, Self
Copy link

Choose a reason for hiding this comment

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

P3: Unused imports (Set, Literal, Self, Field) were introduced but are never referenced after removing the serialization helpers, leaving dead code that will trip lint/static checks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py, line 23:

<comment>Unused imports (Set, Literal, Self, Field) were introduced but are never referenced after removing the serialization helpers, leaving dead code that will trip lint/static checks.</comment>

<file context>
@@ -20,8 +20,8 @@
 from typing import Any, ClassVar, Dict, List, Optional
-from typing import Optional, Set
-from typing_extensions import Self
+from typing import Optional, Set, Literal, Self
+from pydantic import Field
 
</file context>

add to_json / to_dict/ to_str
./mvnw clean package || exit
./bin/generate-samples.sh ./bin/configs/*.yaml || exit
./bin/utils/export_docs_generators.sh || exit
Copy link

@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.

21 issues found across 28 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py:52">
P2: `to_dict` return type incorrectly marked Optional even though method always returns a dict and root is required</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py:18">
P1: Missing List import causes NameError when evaluating RootModel[Union[List[int], str]]</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/color.py:18">
P1: Missing `List` import causes NameError when evaluating `RootModel[Union[List[int], str]]`.</violation>

<violation number="2" location="samples/openapi3/client/petstore/python/petstore_api/models/color.py:49">
P2: `to_dict` return type/doc claims dict but returns root value (list/str) from RootModel, creating a type mismatch</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py:18">
P1: Module import fails: `List` is used in `RootModel[Union[List[int], str]]` but is no longer imported, causing NameError on module load.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py:18">
P1: List is used in the model base/annotations but is no longer imported, causing NameError at module import/class definition.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py:18">
P1: Missing List import causes NameError at class definition for RootModel[Union[List[int], str]]</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py:49">
P2: `to_dict` promises a dict but returns the root list/string from `RootModel.model_dump`, misleading callers and type checkers.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py:49">
P2: to_dict return type/docs claim a dict/optional but actually return raw int/str from RootModel, misleading callers</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py:51">
P2: `to_dict` is annotated/documented to return a dict but actually returns the root value; `RootModel.model_dump()` returns the root, not a dict, so callers will get a str/enum instead of a mapping.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py:49">
P2: `to_dict` advertises returning a dict but returns the root int/str value from `model_dump`, causing a type/documentation mismatch that can mislead callers.</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/task_activity.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/task_activity.py:52">
P3: `to_dict` return type is incorrectly marked Optional even though the method never returns None</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:40">
P2: Incorrect return type hint: `to_dict` uses `model_dump` (returns serialized data) but annotates union with model classes, misleading type checking.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py:18">
P1: Missing `List` import causes NameError when evaluating `RootModel[Union[List[int], str]]`</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py:49">
P2: `to_dict` return type claims a dict but `RootModel` dump returns list/str, misleading callers and risking runtime errors.</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py:18">
P1: `List` not imported: module will raise NameError when evaluating Union[List[int], str]</violation>

<violation number="2" location="samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py:51">
P2: Return annotation for to_dict is broader than actual: model_dump on this RootModel cannot return Dict or None; it returns the required Union[List[int], str].</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py:49">
P2: to_dict() is typed/doc’d to return a dict but RootModel.model_dump returns the root int/str, so callers will receive a primitive rather than the advertised dict</violation>
</file>

<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py:18">
P1: Missing typing.List import causes NameError when evaluating RootModel[Union[List[int], str]].</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py:49">
P2: `to_dict` is annotated/documented to return a dict, but for this RootModel it actually returns the root value (list/str), making the API contract misleading and potentially breaking callers expecting a mapping.</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py:49">
P1: `to_dict` is annotated/documented as returning a dict but actually returns the root int/str value from `RootModel.model_dump`, causing incorrect typing and potential runtime misuse.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

from typing_extensions import Literal, Self
from pydantic import Field
from pydantic import Field, RootModel
from typing import Any, Dict, Optional, Union
Copy link

Choose a reason for hiding this comment

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

P1: Missing List import causes NameError when evaluating RootModel[Union[List[int], str]]

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py, line 18:

<comment>Missing List import causes NameError when evaluating RootModel[Union[List[int], str]]</comment>

<file context>
@@ -13,12 +13,9 @@
-from typing import Union
+import pprint
 from pydantic import Field, RootModel
+from typing import Any, Dict, Optional, Union
 
 ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
</file context>
Suggested change
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, List, Optional, Union

from typing_extensions import Literal, Self
from pydantic import Field
from pydantic import Field, RootModel
from typing import Any, Dict, Optional, Union
Copy link

Choose a reason for hiding this comment

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

P1: Module import fails: List is used in RootModel[Union[List[int], str]] but is no longer imported, causing NameError on module load.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py, line 18:

<comment>Module import fails: `List` is used in `RootModel[Union[List[int], str]]` but is no longer imported, causing NameError on module load.</comment>

<file context>
@@ -13,12 +13,9 @@
-from typing import Union
+import pprint
 from pydantic import Field, RootModel
+from typing import Any, Dict, Optional, Union
 
 ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
</file context>
Suggested change
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, List, Optional, Union

from typing_extensions import Literal, Self
from pydantic import Field
from pydantic import Field, RootModel
from typing import Any, Dict, Optional, Union
Copy link

Choose a reason for hiding this comment

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

P1: List is used in the model base/annotations but is no longer imported, causing NameError at module import/class definition.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py, line 18:

<comment>List is used in the model base/annotations but is no longer imported, causing NameError at module import/class definition.</comment>

<file context>
@@ -13,12 +13,9 @@
-from typing import Union
+import pprint
 from pydantic import Field, RootModel
+from typing import Any, Dict, Optional, Union
 
 ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
</file context>
Suggested change
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, List, Optional, Union

from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field, RootModel
from typing import Any, Dict, Optional, Union
Copy link

Choose a reason for hiding this comment

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

P1: Missing List import causes NameError at class definition for RootModel[Union[List[int], str]]

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py, line 18:

<comment>Missing List import causes NameError at class definition for RootModel[Union[List[int], str]]</comment>

<file context>
@@ -13,11 +13,9 @@
+import pprint
 from pydantic import Field, RootModel
-from typing import Union
+from typing import Any, Dict, Optional, Union
 
 COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"]
</file context>
Suggested change
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, List, Optional, Union


def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
Copy link

Choose a reason for hiding this comment

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

P2: to_dict return type claims a dict but RootModel dump returns list/str, misleading callers and risking runtime errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py, line 49:

<comment>`to_dict` return type claims a dict but `RootModel` dump returns list/str, misleading callers and risking runtime errors.</comment>

<file context>
@@ -44,3 +42,15 @@ def __getattr__(self, name):
+        """Returns the JSON representation of the actual instance"""
+        return self.model_dump_json(by_alias=True)
+
+    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+        """Returns the dict representation of the actual instance"""
+        return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
def to_dict(self) -> Union[list[int], str]:

return self.actual_instance.to_json()
else:
return json.dumps(self.actual_instance)
return self.model_dump_json(by_alias=True)

def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
Copy link

Choose a reason for hiding this comment

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

P2: Return annotation for to_dict is broader than actual: model_dump on this RootModel cannot return Dict or None; it returns the required Union[List[int], str].

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py, line 51:

<comment>Return annotation for to_dict is broader than actual: model_dump on this RootModel cannot return Dict or None; it returns the required Union[List[int], str].</comment>

<file context>
@@ -47,4 +44,16 @@ def __getattr__(self, name):
+        """Returns the JSON representation of the actual instance"""
+        return self.model_dump_json(by_alias=True)
+
+    def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
+        """Returns the dict representation of the actual instance"""
+        return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
def to_dict(self) -> Union[List[int], str]:

Comment on lines 49 to 50
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
"""Returns the dict representation of the actual instance"""
Copy link

Choose a reason for hiding this comment

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

P2: to_dict() is typed/doc’d to return a dict but RootModel.model_dump returns the root int/str, so callers will receive a primitive rather than the advertised dict

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py, line 49:

<comment>to_dict() is typed/doc’d to return a dict but RootModel.model_dump returns the root int/str, so callers will receive a primitive rather than the advertised dict</comment>

<file context>
@@ -44,3 +42,15 @@ def __getattr__(self, name):
+        """Returns the JSON representation of the actual instance"""
+        return self.model_dump_json(by_alias=True)
+
+    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+        """Returns the dict representation of the actual instance"""
+        return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
"""Returns the dict representation of the actual instance"""
def to_dict(self) -> Union[int, str]:
"""Returns the root (int or str) representation of the actual instance"""

Comment on lines 49 to 51
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
return self.actual_instance.to_dict()
else:
# primitive type
return self.actual_instance
return self.model_dump(by_alias=True)
Copy link

Choose a reason for hiding this comment

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

P2: to_dict is annotated/documented to return a dict, but for this RootModel it actually returns the root value (list/str), making the API contract misleading and potentially breaking callers expecting a mapping.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py, line 49:

<comment>`to_dict` is annotated/documented to return a dict, but for this RootModel it actually returns the root value (list/str), making the API contract misleading and potentially breaking callers expecting a mapping.</comment>

<file context>
@@ -44,3 +42,15 @@ def __getattr__(self, name):
+        """Returns the JSON representation of the actual instance"""
+        return self.model_dump_json(by_alias=True)
+
+    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+        """Returns the dict representation of the actual instance"""
+        return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None
if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
return self.actual_instance.to_dict()
else:
# primitive type
return self.actual_instance
return self.model_dump(by_alias=True)
def to_dict(self) -> Union[list[int], str]:
"""Returns the root value of the actual instance"""
return self.model_dump(by_alias=True)

add to_json / to_dict/ to_str
./mvnw clean package || exit
./bin/generate-samples.sh ./bin/configs/*.yaml || exit
./bin/utils/export_docs_generators.sh || exi
Copy link

@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.

23 issues found across 28 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py:18">
P1: List is used in the RootModel type parameters but is not imported, causing a NameError at import time.</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py:51">
P2: `to_dict` return type is incorrect for RootModel; `model_dump` returns the root value (list/str), not a dict.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py:18">
P1: List not imported though used in RootModel type arguments, causing NameError at import time</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py:51">
P2: `to_dict` return annotation claims `Dict[str, Any]` but actually returns the root value (list or str) of this `RootModel`, causing a mismatched contract.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py:18">
P1: Missing import for `List` used in RootModel and annotations causes NameError at import time.</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py:51">
P2: to_dict() return type claims Dict but model_dump on RootModel returns the root list/str, so annotation and doc are incorrect</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py:18">
P1: `List` is referenced in the RootModel base type but is never imported, causing a NameError when the module is imported.</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py:51">
P2: `to_dict` return type is incorrect for RootModel; it returns the root value (list/str), not a dict.</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py:53">
P2: `to_dict` advertises `Dict[str, Any]` but returns the root scalar/enum from `RootModel.model_dump`, causing a runtime type mismatch</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/color.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/color.py:18">
P1: `List` is used in the base class but not imported, causing NameError at import time.</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py:18">
P1: Missing typing.List import causes NameError when evaluating RootModel[Union[List[int], str]].</violation>

<violation number="2" location="samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py:51">
P2: `to_dict` return type/docstring claims a dict but model_dump on RootModel returns the root value (list or str)</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py:18">
P1: Missing import for `List` causes NameError during class definition, breaking module import</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py:51">
P2: `to_dict` return type is incorrect for RootModel; model_dump returns the root list/str, not a dict</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_anyof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_anyof.mustache:40">
P2: `to_dict` now claims to return `Dict[str, Any]` but still returns the root value, which may be non-dict for primitive/array anyOf branches, causing a contract mismatch and potential runtime errors.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py:18">
P1: `List` is used in type arguments but never imported, causing a NameError during class definition.</violation>

<violation number="2" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py:51">
P2: to_dict() is now typed/documented as returning Dict but model_dump on RootModel returns the root value (list or str), so callers expecting a dict will misbehave.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py:51">
P2: to_dict() type/docstring claim a dict but returns scalar root value for this RootModel, breaking the method contract</violation>
</file>

<file name="samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py:51">
P2: to_dict() is annotated/docstringed to return a dict but actually returns the scalar root value for this RootModel (int/str), misleading callers and risking runtime errors</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py:53">
P2: `to_dict` return type is incorrect: RootModel.model_dump returns the root enum/string value, not a dict, so callers expecting a mapping will receive a scalar.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py:51">
P2: `to_dict` return type/docstring claim a dict but actually return an int/str from RootModel.model_dump, risking misuse and serialization errors.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/python/model_oneof.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_oneof.mustache:40">
P2: `to_dict` return type misdeclared: RootModel may return non-dict values for primitive/array oneOf variants</violation>
</file>

<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py">

<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py:51">
P2: `to_dict` type and docstring claim a dict but `model_dump` on RootModel returns the root value (`int`/`str`), so callers expecting a mapping will get a scalar.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field, RootModel
from typing import Any, Dict, Union
Copy link

Choose a reason for hiding this comment

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

P1: List is used in the RootModel type parameters but is not imported, causing a NameError at import time.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py, line 18:

<comment>List is used in the RootModel type parameters but is not imported, causing a NameError at import time.</comment>

<file context>
@@ -15,10 +15,12 @@
 import pprint
 from pydantic import Field, RootModel
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Union
+
 
</file context>
Suggested change
from typing import Any, Dict, Union
from typing import Any, Dict, List, Union

from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field, RootModel
from typing import Any, Dict, Union
Copy link

Choose a reason for hiding this comment

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

P1: List not imported though used in RootModel type arguments, causing NameError at import time

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py, line 18:

<comment>List not imported though used in RootModel type arguments, causing NameError at import time</comment>

<file context>
@@ -15,10 +15,12 @@
 import pprint
 from pydantic import Field, RootModel
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Union
+
 
</file context>
Suggested change
from typing import Any, Dict, Union
from typing import Any, Dict, List, Union

from typing_extensions import Literal, Self
from pydantic import Field
from pydantic import Field, RootModel
from typing import Any, Dict, Union
Copy link

Choose a reason for hiding this comment

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

P1: Missing import for List used in RootModel and annotations causes NameError at import time.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py, line 18:

<comment>Missing import for `List` used in RootModel and annotations causes NameError at import time.</comment>

<file context>
@@ -15,7 +15,7 @@
 import pprint
 from pydantic import Field, RootModel
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Union
 
 ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
</file context>
Suggested change
from typing import Any, Dict, Union
from typing import Any, Dict, List, Union

from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field, RootModel
from typing import Any, Dict, Union
Copy link

Choose a reason for hiding this comment

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

P1: List is referenced in the RootModel base type but is never imported, causing a NameError when the module is imported.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py, line 18:

<comment>`List` is referenced in the RootModel base type but is never imported, causing a NameError when the module is imported.</comment>

<file context>
@@ -15,10 +15,12 @@
 import pprint
 from pydantic import Field, RootModel
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Union
+
 
</file context>
Suggested change
from typing import Any, Dict, Union
from typing import Any, Dict, List, Union

from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field, RootModel
from typing import Any, Dict, Union
Copy link

Choose a reason for hiding this comment

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

P1: List is used in the base class but not imported, causing NameError at import time.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python/petstore_api/models/color.py, line 18:

<comment>`List` is used in the base class but not imported, causing NameError at import time.</comment>

<file context>
@@ -15,10 +15,12 @@
 import pprint
 from pydantic import Field, RootModel
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Union
+
 
</file context>
Suggested change
from typing import Any, Dict, Union
from typing import Any, Dict, List, Union

return json.dumps(self.actual_instance)

def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]:
def to_dict(self) -> Dict[str, Any]:
Copy link

Choose a reason for hiding this comment

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

P2: to_dict() is annotated/docstringed to return a dict but actually returns the scalar root value for this RootModel (int/str), misleading callers and risking runtime errors

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py, line 51:

<comment>to_dict() is annotated/docstringed to return a dict but actually returns the scalar root value for this RootModel (int/str), misleading callers and risking runtime errors</comment>

<file context>
@@ -46,7 +48,7 @@ def to_json(self) -> str:
         return self.model_dump_json(by_alias=True)
 
-    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+    def to_dict(self) -> Dict[str, Any]:
         """Returns the dict representation of the actual instance"""
         return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> Union[int, str]:
"""Returns the underlying root value of the actual instance"""
return self.model_dump(by_alias=True)

return json.dumps(self.actual_instance)

def to_dict(self) -> Optional[Union[Dict[str, Any], EnumString1, EnumString2]]:
def to_dict(self) -> Dict[str, Any]:
Copy link

Choose a reason for hiding this comment

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

P2: to_dict return type is incorrect: RootModel.model_dump returns the root enum/string value, not a dict, so callers expecting a mapping will receive a scalar.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py, line 53:

<comment>`to_dict` return type is incorrect: RootModel.model_dump returns the root enum/string value, not a dict, so callers expecting a mapping will receive a scalar.</comment>

<file context>
@@ -48,7 +50,7 @@ def to_json(self) -> str:
         return self.model_dump_json(by_alias=True)
 
-    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+    def to_dict(self) -> Dict[str, Any]:
         """Returns the dict representation of the actual instance"""
         return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> Union[EnumString1, EnumString2, str]:

return json.dumps(self.actual_instance)

def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]:
def to_dict(self) -> Dict[str, Any]:
Copy link

Choose a reason for hiding this comment

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

P2: to_dict return type/docstring claim a dict but actually return an int/str from RootModel.model_dump, risking misuse and serialization errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py, line 51:

<comment>`to_dict` return type/docstring claim a dict but actually return an int/str from RootModel.model_dump, risking misuse and serialization errors.</comment>

<file context>
@@ -46,7 +48,7 @@ def to_json(self) -> str:
         return self.model_dump_json(by_alias=True)
 
-    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+    def to_dict(self) -> Dict[str, Any]:
         """Returns the dict representation of the actual instance"""
         return self.model_dump(by_alias=True)
</file context>

return json.dumps(self.actual_instance)

def to_dict(self) -> Optional[Union[Dict[str, Any], {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]:
def to_dict(self) -> Dict[str, Any]:
Copy link

Choose a reason for hiding this comment

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

P2: to_dict return type misdeclared: RootModel may return non-dict values for primitive/array oneOf variants

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/model_oneof.mustache, line 40:

<comment>`to_dict` return type misdeclared: RootModel may return non-dict values for primitive/array oneOf variants</comment>

<file context>
@@ -35,7 +37,7 @@ class {{classname}}(RootModel[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/on
         return self.model_dump_json(by_alias=True)
 
-    def to_dict(self) -> Optional[Union[Dict[str, Any], {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]:
+    def to_dict(self) -> Dict[str, Any]:
         """Returns the dict representation of the actual instance"""
         return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> Any:

Comment on lines +51 to 52
def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of the actual instance"""
Copy link

Choose a reason for hiding this comment

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

P2: to_dict type and docstring claim a dict but model_dump on RootModel returns the root value (int/str), so callers expecting a mapping will get a scalar.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py, line 51:

<comment>`to_dict` type and docstring claim a dict but `model_dump` on RootModel returns the root value (`int`/`str`), so callers expecting a mapping will get a scalar.</comment>

<file context>
@@ -46,7 +48,7 @@ def to_json(self) -> str:
         return self.model_dump_json(by_alias=True)
 
-    def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
+    def to_dict(self) -> Dict[str, Any]:
         """Returns the dict representation of the actual instance"""
         return self.model_dump(by_alias=True)
</file context>
Suggested change
def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of the actual instance"""
def to_dict(self) -> Union[int, str]:
"""Returns the root value of the actual instance"""
return self.model_dump(by_alias=True)

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.

2 participants