Skip to content
Merged
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 @@ -1173,9 +1173,9 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
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?)$");
Copy link
Contributor

Choose a reason for hiding this comment

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

How about Pattern.compile("^/?(.+?)/?([gim]?)$")

Matcher m = valueExtractor.matcher(pattern);
RgxGen rgxGen = null;
if (m.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
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;
Expand Down Expand Up @@ -453,6 +456,30 @@ public void testRegexObjects() {
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")
Expand Down
23 changes: 23 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issues_13069.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion samples/client/petstore/python/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/python/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down