Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,10 @@ private PythonType fromCommon(IJsonSchemaValidationProperties cp) {
moduleImports.add("pydantic", "field_validator");
}

if (cp.getPattern() != null) {
moduleImports.add("pydantic", "field_validator");
}

if (cp.getIsArray()) {
return arrayType(cp);
} else if (cp.getIsMap() || cp.getIsFreeFormObject()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,16 @@ public void testPoetry1LicenseFormat() throws IOException {
TestUtils.assertFileNotContains(pyprojectPath, "license = { text = \"Apache-2.0\" }");
}

@Test(description = "UUID property with pattern should import field_validator")
public void testUuidWithPatternImportsFieldValidator() throws IOException {
final DefaultCodegen codegen = new PythonClientCodegen();
final String outputPath = generateFiles(codegen, "src/test/resources/bugs/issue_uuid_with_pattern.yaml");
final Path p = Paths.get(outputPath + "openapi_client/models/uuid_with_pattern.py");

assertFileExists(p);
assertFileContains(p, "from pydantic import BaseModel, ConfigDict, field_validator");
}

@Test(description = "Verify non-poetry1 mode uses object notation for license")
public void testNonPoetry1LicenseFormat() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openapi: 3.0.0
info:
title: Test UUID with pattern
version: 1.0.0
paths: {}
components:
schemas:
UuidWithPattern:
type: object
properties:
id:
type: string
format: uuid
pattern: "^[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}$"
Loading