Skip to content

Comments

Add uuid pattern tests to python client#23040

Merged
wing328 merged 1 commit intomasterfrom
add-test-uuid
Feb 24, 2026
Merged

Add uuid pattern tests to python client#23040
wing328 merged 1 commit intomasterfrom
add-test-uuid

Conversation

@wing328
Copy link
Member

@wing328 wing328 commented Feb 24, 2026

a follow up PR to #22947

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.

Summary by cubic

Added UUID pattern validation tests to Python clients to enforce schemas with format: uuid + pattern. This improves correctness by rejecting invalid UUID v4 values.

  • New Features

    • Added UuidWithPattern to the test spec with a v4 UUID regex.
    • Generated UuidWithPattern models and unit tests for python, python-aiohttp, python-httpx, python-lazyImports, python-pydantic-v1, and python-pydantic-v1-aiohttp (typed as UUID for v2, constrained str for v1).
    • Updated docs and exposed the model in each client’s package init.
  • Dependencies

    • Regenerated Spring Boot samples; generator version strings updated to 7.21.0-SNAPSHOT.

Written for commit 65d99d8. Summary will update on new commits.

@wing328 wing328 marked this pull request as ready for review February 24, 2026 01:47
@wing328 wing328 merged commit e01fdee into master Feb 24, 2026
147 of 148 checks passed
@wing328 wing328 deleted the add-test-uuid branch February 24, 2026 01:47
Copy link
Contributor

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

Choose a reason for hiding this comment

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

6 issues found across 114 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. If appropriate, use sub-agents to investigate and fix each issue separately.


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

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/models/uuid_with_pattern.py:39">
P1: Validator calls re.match on a UUID instance (value) which will raise TypeError; must convert to string or handle None/UUID before regex.</violation>
</file>

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

<violation number="1" location="samples/openapi3/client/petstore/python/petstore_api/models/uuid_with_pattern.py:40">
P2: `field_validator` runs after UUID parsing, so `value` is a UUID instance and `re.match` will raise `TypeError`. Convert to string (or run the validator in `mode="before"`) to avoid runtime validation errors.</violation>
</file>

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

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/uuid_with_pattern.py:40">
P2: `re.match` is called on a UUID instance, which raises `TypeError` during validation. Convert the UUID to a string before applying the regex.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-pydantic-v1/docs/UuidWithPattern.md">

<violation number="1" location="samples/openapi3/client/petstore/python-pydantic-v1/docs/UuidWithPattern.md:19">
P3: The example uses Python 2 print syntax and calls `to_json` as a class method. Under Python 3.7+, this is a SyntaxError and `to_json` should be called on the instance. Update the sample to print the instance JSON.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/UuidWithPattern.md">

<violation number="1" location="samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/UuidWithPattern.md:19">
P2: The example uses Python 2 print statement syntax, which is invalid in the Python 3.7+ client. Use the print() function to keep the docs runnable.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-lazyImports/docs/UuidWithPattern.md">

<violation number="1" location="samples/openapi3/client/petstore/python-lazyImports/docs/UuidWithPattern.md:20">
P2: The documentation example calls `to_json` on the class, but `to_json` is an instance method. This example will fail with a missing `self` argument. Use the instance created earlier in the snippet.</violation>
</file>

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

if value is None:
return value

if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 24, 2026

Choose a reason for hiding this comment

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

P1: Validator calls re.match on a UUID instance (value) which will raise TypeError; must convert to string or handle None/UUID before regex.

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/uuid_with_pattern.py, line 39:

<comment>Validator calls re.match on a UUID instance (value) which will raise TypeError; must convert to string or handle None/UUID before regex.</comment>

<file context>
@@ -0,0 +1,98 @@
+        if value is None:
+            return value
+
+        if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
+            raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/")
+        return value
</file context>
Fix with Cubic

if value is None:
return value

if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 24, 2026

Choose a reason for hiding this comment

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

P2: field_validator runs after UUID parsing, so value is a UUID instance and re.match will raise TypeError. Convert to string (or run the validator in mode="before") to avoid runtime validation 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/uuid_with_pattern.py, line 40:

<comment>`field_validator` runs after UUID parsing, so `value` is a UUID instance and `re.match` will raise `TypeError`. Convert to string (or run the validator in `mode="before"`) to avoid runtime validation errors.</comment>

<file context>
@@ -0,0 +1,111 @@
+        if value is None:
+            return value
+
+        if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
+            raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/")
+        return value
</file context>
Fix with Cubic

if value is None:
return value

if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 24, 2026

Choose a reason for hiding this comment

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

P2: re.match is called on a UUID instance, which raises TypeError during validation. Convert the UUID to a string before applying the regex.

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/uuid_with_pattern.py, line 40:

<comment>`re.match` is called on a UUID instance, which raises `TypeError` during validation. Convert the UUID to a string before applying the regex.</comment>

<file context>
@@ -0,0 +1,111 @@
+        if value is None:
+            return value
+
+        if not re.match(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$", value):
+            raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/")
+        return value
</file context>
Fix with Cubic

# create an instance of UuidWithPattern from a JSON string
uuid_with_pattern_instance = UuidWithPattern.from_json(json)
# print the JSON string representation of the object
print UuidWithPattern.to_json()
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 24, 2026

Choose a reason for hiding this comment

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

P2: The example uses Python 2 print statement syntax, which is invalid in the Python 3.7+ client. Use the print() function to keep the docs runnable.

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-pydantic-v1-aiohttp/docs/UuidWithPattern.md, line 19:

<comment>The example uses Python 2 print statement syntax, which is invalid in the Python 3.7+ client. Use the print() function to keep the docs runnable.</comment>

<file context>
@@ -0,0 +1,28 @@
+# create an instance of UuidWithPattern from a JSON string
+uuid_with_pattern_instance = UuidWithPattern.from_json(json)
+# print the JSON string representation of the object
+print UuidWithPattern.to_json()
+
+# convert the object into a dict
</file context>
Fix with Cubic

# create an instance of UuidWithPattern from a JSON string
uuid_with_pattern_instance = UuidWithPattern.from_json(json)
# print the JSON string representation of the object
print(UuidWithPattern.to_json())
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 24, 2026

Choose a reason for hiding this comment

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

P2: The documentation example calls to_json on the class, but to_json is an instance method. This example will fail with a missing self argument. Use the instance created earlier in the snippet.

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

<comment>The documentation example calls `to_json` on the class, but `to_json` is an instance method. This example will fail with a missing `self` argument. Use the instance created earlier in the snippet.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of UuidWithPattern from a JSON string
+uuid_with_pattern_instance = UuidWithPattern.from_json(json)
+# print the JSON string representation of the object
+print(UuidWithPattern.to_json())
+
+# convert the object into a dict
</file context>
Fix with Cubic

# create an instance of UuidWithPattern from a JSON string
uuid_with_pattern_instance = UuidWithPattern.from_json(json)
# print the JSON string representation of the object
print UuidWithPattern.to_json()
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 24, 2026

Choose a reason for hiding this comment

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

P3: The example uses Python 2 print syntax and calls to_json as a class method. Under Python 3.7+, this is a SyntaxError and to_json should be called on the instance. Update the sample to print the instance JSON.

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-pydantic-v1/docs/UuidWithPattern.md, line 19:

<comment>The example uses Python 2 print syntax and calls `to_json` as a class method. Under Python 3.7+, this is a SyntaxError and `to_json` should be called on the instance. Update the sample to print the instance JSON.</comment>

<file context>
@@ -0,0 +1,28 @@
+# create an instance of UuidWithPattern from a JSON string
+uuid_with_pattern_instance = UuidWithPattern.from_json(json)
+# print the JSON string representation of the object
+print UuidWithPattern.to_json()
+
+# convert the object into a dict
</file context>
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