diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 74a5bf2c600..961a760c2e8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -1173,9 +1173,9 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen { String pattern = schema.getPattern(); /* RxGen does not support our ECMA dialect https://github.com/curious-odd-man/RgxGen/issues/56 - So strip off the leading / and trailing / and turn on ignore case if we have it + So strip off the leading /, trailing / and trailing /i, and turn on ignore case if we have it */ - Pattern valueExtractor = Pattern.compile("^/?(.+?)/?(.?)$"); + Pattern valueExtractor = Pattern.compile("^/?(.+?)/?(i?)$"); Matcher m = valueExtractor.matcher(pattern); RgxGen rgxGen = null; if (m.find()) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java index 028316f4193..2ff86d741d6 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java @@ -35,6 +35,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.openapitools.codegen.*; import org.openapitools.codegen.languages.PythonClientCodegen; import org.openapitools.codegen.utils.ModelUtils; @@ -453,6 +456,30 @@ public class PythonClientTest { Assert.assertEquals(property1.baseName, "datetime"); Assert.assertEquals(property1.pattern, "/[\\d]{4}-[\\d]{2}-[\\d]{2}T[\\d]{1,2}:[\\d]{2}Z/"); Assert.assertEquals(property1.vendorExtensions.get("x-regex"), "[\\d]{4}-[\\d]{2}-[\\d]{2}T[\\d]{1,2}:[\\d]{2}Z"); + + // ignore warnings, should be the same as in issue_11521.yaml + Pattern pattern = Pattern.compile("[\\d]{4}-[\\d]{2}-[\\d]{2}T[\\d]{1,2}:[\\d]{2}Z"); + Matcher matcher = pattern.matcher(property1.example); + Assert.assertTrue(matcher.find()); + } + + @Test(description = "tests uuid example works even if a pattern is provided") + public void testUuidExampleWorksEvenIfPatternIsDefined() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issues_13069.yaml"); + final DefaultCodegen codegen = new PythonClientCodegen(); + codegen.setOpenAPI(openAPI); + + Operation operation = openAPI.getPaths().get("/test").getGet(); + CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER); + codegen.setParameterExampleValue(codegenParameter, operation.getParameters().get(0)); + + String modelName = "UUID"; + Schema modelSchema = ModelUtils.getSchema(openAPI, modelName); + final CodegenModel model = codegen.fromModel(modelName, modelSchema); + + Pattern pattern = Pattern.compile("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"); + Matcher matcher = pattern.matcher(codegenParameter.example); + Assert.assertTrue(matcher.find()); } @Test(description = "tests RecursiveToExample") diff --git a/modules/openapi-generator/src/test/resources/3_0/issues_13069.yaml b/modules/openapi-generator/src/test/resources/3_0/issues_13069.yaml new file mode 100644 index 00000000000..fc644ef5ba2 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issues_13069.yaml @@ -0,0 +1,23 @@ +--- +openapi: 3.0.3 +info: + title: Test + version: 1.0.0-SNAPSHOT +paths: + /test: + get: + parameters: + - name: uuid + in: query + schema: + $ref: '#/components/schemas/UUID' + responses: + "200": + description: OK + +components: + schemas: + UUID: + format: uuid + pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" + type: string \ No newline at end of file diff --git a/samples/client/petstore/python/docs/FakeApi.md b/samples/client/petstore/python/docs/FakeApi.md index c52fe144aba..7c12e3bd188 100644 --- a/samples/client/petstore/python/docs/FakeApi.md +++ b/samples/client/petstore/python/docs/FakeApi.md @@ -865,7 +865,7 @@ with petstore_api.ApiClient(configuration) as api_client: api_instance = fake_api.FakeApi(api_client) number = 32.1 # float | None double = 67.8 # float | None - pattern_without_delimiter = "Aj" # str | None + pattern_without_delimiter = "AUR,rZ#UM/?R,Fp^l6$ARjbhJk C>" # str | None byte = 'YQ==' # str | None integer = 10 # int | None (optional) int32 = 20 # int | None (optional) diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/FakeApi.md b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/FakeApi.md index c52fe144aba..7c12e3bd188 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/FakeApi.md +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/FakeApi.md @@ -865,7 +865,7 @@ with petstore_api.ApiClient(configuration) as api_client: api_instance = fake_api.FakeApi(api_client) number = 32.1 # float | None double = 67.8 # float | None - pattern_without_delimiter = "Aj" # str | None + pattern_without_delimiter = "AUR,rZ#UM/?R,Fp^l6$ARjbhJk C>" # str | None byte = 'YQ==' # str | None integer = 10 # int | None (optional) int32 = 20 # int | None (optional) diff --git a/samples/openapi3/client/petstore/python/docs/FakeApi.md b/samples/openapi3/client/petstore/python/docs/FakeApi.md index 97d25d3a017..07ecc5cf925 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/FakeApi.md @@ -1327,7 +1327,7 @@ with petstore_api.ApiClient(configuration) as api_client: api_instance = fake_api.FakeApi(api_client) number = 32.1 # float | None double = 67.8 # float | None - pattern_without_delimiter = "Aj" # str | None + pattern_without_delimiter = "AUR,rZ#UM/?R,Fp^l6$ARjbhJk C>" # str | None byte = 'YQ==' # str | None integer = 10 # int | None (optional) int32 = 20 # int | None (optional)