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

"httpx (>=0.28.1)",
{{/httpx}}
{{#asyncio}}
{{#async}}
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.

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.

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>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.</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
{{#async}}
{{#asyncio}}
Fix with Cubic

{{/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

{{#-first}}
{{#-last}}
{{! Single value enum - use Literal }}
{{name}}: Literal['{{{.}}}'] = Field(
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.

P2: Single-value enum Literal always uses string quoting. For integer enums (IntEnum mentioned in PR), Literal['{{{.}}}'] will produce Literal['1'] instead of Literal[1]. Consider using conditional quoting based on the enum type or using {{{.}}} without quotes.

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 39:

<comment>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.</comment>

<file context>
@@ -28,7 +29,33 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
+          {{#-first}}
+            {{#-last}}
+              {{! Single value enum - use Literal }}
+    {{name}}: Literal[&#39;{{{.}}}&#39;] = Field(
+        {{#required}}...{{/required}}{{^required}}None{{/required}},
+        description=&quot;{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}&quot;
</file context>
Fix with Cubic

{{#vars}}
{{#isEnum}}
{{#allowableValues}}
{{^isArray}}
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 field definition for array enum types. When isEnum=true AND isArray=true, no field is rendered because the {{^isArray}} block is skipped but there's no {{#isArray}} handler. Consider adding a fallback or explicit array enum handling.

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 34:

<comment>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.</comment>

<file context>
@@ -28,7 +29,33 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
 {{#vars}}
+  {{#isEnum}}
+    {{#allowableValues}}
+      {{^isArray}}
+        {{#values}}
+          {{#-first}}
</file context>
Fix with Cubic

{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance = {{classname}}.model_validate_json(json)
# print the JSON string representation of the object
print({{classname}}.to_json())
print({{classname}}.model_dump_json(by_alias=True, exclude_unset=True))
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: 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.

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_doc.mustache, line 24:

<comment>`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`.</comment>

<file context>
@@ -19,14 +19,14 @@ from {{modelPackage}}.{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}} im
+{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance = {{classname}}.model_validate_json(json)
 # print the JSON string representation of the object
-print({{classname}}.to_json())
+print({{classname}}.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print({{classname}}.model_dump_json(by_alias=True, exclude_unset=True))
print({{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

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.

Comment on lines +30 to +31
if hasattr(self, 'root') and self.root is not None:
return getattr(self.root, name)
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

P2: Calling hasattr(self, 'root') inside __getattr__ risks infinite recursion. Use self.__dict__.get('root') instead to safely check for the attribute without triggering recursive __getattr__ calls.

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 30:

<comment>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.</comment>

<file context>
@@ -7,203 +7,26 @@ import pprint
+        &quot;&quot;&quot;
+        if name in self.__dict__:
+            return super().__getattribute__(name)
+        if hasattr(self, &#39;root&#39;) and self.root is not None:
+            return getattr(self.root, name)
+        raise AttributeError(f&quot;&#39;{self.__class__.__name__}&#39; object has no attribute &#39;{name}&#39;&quot;)
</file context>
Suggested change
if hasattr(self, 'root') and self.root is not None:
return getattr(self.root, name)
root = self.__dict__.get('root')
if root is not None:
return getattr(root, name)
Fix with Cubic

test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate_json(json)
# print the JSON string representation of the object
print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.to_json())
print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md, line 23:

<comment>`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.</comment>

<file context>
@@ -18,14 +18,14 @@ from openapi_client.models.test_query_style_deep_object_explode_true_object_all_
+test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate_json(json)
 # print the JSON string representation of the object
-print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.to_json())
+print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True))
print(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

data_query_instance = DataQuery.model_validate_json(json)
# print the JSON string representation of the object
print(DataQuery.to_json())
print(DataQuery.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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/docs/DataQuery.md, line 22:

<comment>`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.</comment>

<file context>
@@ -17,14 +17,14 @@ from openapi_client.models.data_query import DataQuery
+data_query_instance = DataQuery.model_validate_json(json)
 # print the JSON string representation of the object
-print(DataQuery.to_json())
+print(DataQuery.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(DataQuery.model_dump_json(by_alias=True, exclude_unset=True))
print(data_query_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate_json(json)
# print the JSON string representation of the object
print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.to_json())
print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md, line 20:

<comment>`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.</comment>

<file context>
@@ -15,14 +15,14 @@ from openapi_client.models.test_query_style_form_explode_true_array_string_query
+test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate_json(json)
 # print the JSON string representation of the object
-print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.to_json())
+print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True))
print(test_query_style_form_explode_true_array_string_query_object_parameter_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.model_validate_json(json)
# print the JSON string representation of the object
print(TestFormObjectMultipartRequestMarker.to_json())
print(TestFormObjectMultipartRequestMarker.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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/docs/TestFormObjectMultipartRequestMarker.md, line 20:

<comment>`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.</comment>

<file context>
@@ -15,14 +15,14 @@ from openapi_client.models.test_form_object_multipart_request_marker import Test
+test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.model_validate_json(json)
 # print the JSON string representation of the object
-print(TestFormObjectMultipartRequestMarker.to_json())
+print(TestFormObjectMultipartRequestMarker.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(TestFormObjectMultipartRequestMarker.model_dump_json(by_alias=True, exclude_unset=True))
print(test_form_object_multipart_request_marker_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

category_instance = Category.model_validate_json(json)
# print the JSON string representation of the object
print(Category.to_json())
print(Category.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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/docs/Category.md, line 21:

<comment>`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.</comment>

<file context>
@@ -16,14 +16,14 @@ from openapi_client.models.category import Category
+category_instance = Category.model_validate_json(json)
 # print the JSON string representation of the object
-print(Category.to_json())
+print(Category.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(Category.model_dump_json(by_alias=True, exclude_unset=True))
print(category_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

bird_instance = Bird.model_validate_json(json)
# print the JSON string representation of the object
print(Bird.to_json())
print(Bird.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

P1: model_dump_json() is an instance method in Pydantic v2, but it's being called on the class Bird instead of the instance bird_instance. This documentation example will not work as written.

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/docs/Bird.md, line 21:

<comment>`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.</comment>

<file context>
@@ -16,14 +16,14 @@ from openapi_client.models.bird import Bird
+bird_instance = Bird.model_validate_json(json)
 # print the JSON string representation of the object
-print(Bird.to_json())
+print(Bird.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(Bird.model_dump_json(by_alias=True, exclude_unset=True))
print(bird_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

# Allowed enum values
{{#enumVars}}
{{{name}}} = {{{value}}}
{{name}} = {{{value}}}
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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_enum.mustache, line 25:

<comment>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.</comment>

<file context>
@@ -1,36 +1,32 @@
+    # Allowed enum values
     {{#enumVars}}
-    {{{name}}} = {{{value}}}
+    {{name}} = {{{value}}}
     {{/enumVars}}
 
</file context>
Suggested change
{{name}} = {{{value}}}
{{{name}}} = {{{value}}}
Fix with Cubic

bird_instance = Bird.model_validate_json(json)
# print the JSON string representation of the object
print(Bird.to_json())
print(Bird.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

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.

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/docs/Bird.md, line 21:

<comment>`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.</comment>

<file context>
@@ -16,14 +16,14 @@ from openapi_client.models.bird import Bird
+bird_instance = Bird.model_validate_json(json)
 # print the JSON string representation of the object
-print(Bird.to_json())
+print(Bird.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(Bird.model_dump_json(by_alias=True, exclude_unset=True))
print(bird_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

query_instance = Query.model_validate_json(json)
# print the JSON string representation of the object
print(Query.to_json())
print(Query.model_dump_json(by_alias=True, exclude_unset=True))
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

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

P1: model_dump_json() is an instance method in Pydantic v2, not a class method. Should be called on query_instance instead of Query.

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/docs/Query.md, line 21:

<comment>`model_dump_json()` is an instance method in Pydantic v2, not a class method. Should be called on `query_instance` instead of `Query`.</comment>

<file context>
@@ -16,14 +16,14 @@ from openapi_client.models.query import Query
+query_instance = Query.model_validate_json(json)
 # print the JSON string representation of the object
-print(Query.to_json())
+print(Query.model_dump_json(by_alias=True, exclude_unset=True))
 
 # convert the object into a dict
</file context>
Suggested change
print(Query.model_dump_json(by_alias=True, exclude_unset=True))
print(query_instance.model_dump_json(by_alias=True, exclude_unset=True))
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant