diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index d8b577c93cae..d04177a51766 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -917,6 +917,11 @@ public String toEnumVarName(String value, String datatype) { public boolean specVersionGreaterThanOrEqualTo310(OpenAPI openAPI) { String originalSpecVersion; String xOriginalSwaggerVersion = "x-original-swagger-version"; + + if (openAPI == null) { + return false; + } + if (openAPI.getExtensions() != null && !openAPI.getExtensions().isEmpty() && openAPI.getExtensions().containsValue(xOriginalSwaggerVersion)) { originalSpecVersion = (String) openAPI.getExtensions().get(xOriginalSwaggerVersion); } else { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 3bc48fb57de3..dc363e158fda 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -29,6 +29,7 @@ import java.io.File; import java.util.*; +import java.util.regex.Matcher; import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER; import static org.openapitools.codegen.utils.StringUtils.camelize; @@ -38,6 +39,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege private final Logger LOGGER = LoggerFactory.getLogger(AbstractGoCodegen.class); private static final String NUMERIC_ENUM_PREFIX = "_"; + private static final String X_GO_CUSTOM_TAG = "x-go-custom-tag"; @Setter protected boolean withGoCodegenComment = false; @@ -785,9 +787,20 @@ public ModelsMap postProcessModels(ModelsMap objs) { } if (cp.pattern != null) { - cp.vendorExtensions.put("x-go-custom-tag", "validate:\"regexp=" + - cp.pattern.replace("\\", "\\\\").replaceAll("^/|/$", "") + - "\""); + String regexp = String.format(Locale.getDefault(), "regexp=%s", cp.pattern); + + // Replace backtick by \\x60, if found + if (regexp.contains("`")) { + regexp = regexp.replace("`", "\\x60"); + } + + // Escape comma + if (regexp.contains(",")) { + regexp = regexp.replace(",", "\\\\,"); + } + + String validate = String.format(Locale.getDefault(), "validate:\"%s\"", regexp); + cp.vendorExtensions.put(X_GO_CUSTOM_TAG, validate); } // construct data tag in the template: x-go-datatag @@ -813,8 +826,8 @@ public ModelsMap postProcessModels(ModelsMap objs) { } // {{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}} - if (StringUtils.isNotEmpty(String.valueOf(cp.vendorExtensions.getOrDefault("x-go-custom-tag", "")))) { - goDataTag += " " + cp.vendorExtensions.get("x-go-custom-tag"); + if (StringUtils.isNotEmpty(String.valueOf(cp.vendorExtensions.getOrDefault(X_GO_CUSTOM_TAG, "")))) { + goDataTag += " " + cp.vendorExtensions.get(X_GO_CUSTOM_TAG); } // if it contains backtick, wrap with " instead @@ -874,6 +887,11 @@ public ModelsMap postProcessModels(ModelsMap objs) { return postProcessModelsEnum(objs); } + @Override + public String addRegularExpressionDelimiter(String pattern) { + return pattern; + } + @Override public Map postProcessSupportingFileData(Map objs) { generateYAMLSpecFile(objs); diff --git a/modules/openapi-generator/src/main/resources/go/model_oneof.mustache b/modules/openapi-generator/src/main/resources/go/model_oneof.mustache index e62c5e82d2b1..dfa6c8995425 100644 --- a/modules/openapi-generator/src/main/resources/go/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/go/model_oneof.mustache @@ -79,7 +79,16 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") + {{#oneOf}} + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf({{classname}}): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") + } + {{/oneOf}} + {{^oneOf}} + return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") + {{/oneOf}} } {{/discriminator}} {{/useOneOfDiscriminatorLookup}} @@ -114,7 +123,16 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") + {{#oneOf}} + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf({{classname}}): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") + } + {{/oneOf}} + {{^oneOf}} + return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") + {{/oneOf}} } {{/useOneOfDiscriminatorLookup}} } diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_api_default_test.go b/modules/openapi-generator/src/test/resources/3_0/issue_20079_api_default_test.go new file mode 100644 index 000000000000..46e656cfd384 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_api_default_test.go @@ -0,0 +1,70 @@ +package openapi + +import ( + "context" + "encoding/json" + openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "os" + "testing" +) + +func Test_openapi_DefaultAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Matching regex", func(t *testing.T) { + filesNames := []string{"issue_20079_matching01.json", "issue_20079_matching02.json", "issue_20079_matching03.json", "issue_20079_matching04.json"} + + for _, fileName := range filesNames { + data, errLoad := os.ReadFile(fileName) + + if errLoad != nil { + t.Errorf("Cannot read test file resource %s: %s", fileName, errLoad.Error()) + } + + var importCode *openapiclient.FooGet200ResponseCode + + errParse := json.Unmarshal(data, &importCode) + + if errParse != nil { + t.Errorf("The resource file %s that was expected matching, doesn't: %s", fileName, errParse.Error()) + } + } + }) + + t.Run("Non-matching regex", func(t *testing.T) { + filesNames := []string{"issue_20079_non_matching01.json", "issue_20079_non_matching02.json", "issue_20079_non_matching03.json", "issue_20079_non_matching04.json"} + + for _, fileName := range filesNames { + data, errLoad := os.ReadFile(fileName) + + if errLoad != nil { + t.Errorf("Cannot read test file resource %s: %s", fileName, errLoad.Error()) + } + + var importCode *openapiclient.FooGet200ResponseCode + + errParse := json.Unmarshal(data, &importCode) + + if errParse == nil { + t.Errorf("The resource file %s that was expected non-matching, does", fileName) + } + } + }) + + t.Run("Test DefaultAPIService FooGet", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + resp, httpRes, err := apiClient.DefaultAPI.FooGet(context.Background()).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_go_regex_wrongly_translated.yaml b/modules/openapi-generator/src/test/resources/3_0/issue_20079_go_regex_wrongly_translated.yaml new file mode 100644 index 000000000000..e719858d39c6 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_go_regex_wrongly_translated.yaml @@ -0,0 +1,191 @@ +openapi: '3.0.3' +info: + title: API Test + version: '1.0' +paths: + /foo: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + code: + oneOf: + - $ref: "#/components/schemas/importCode" + +components: + schemas: + importCode: + type: object + properties: + code: + type: string + pattern: "^[0-9]{2,}$" + + creditCard: + description: "Visa credit card\n + matches: 4123 6453 2222 1746\n + non-matches: 3124 5675 4400 4567, 4123-6453-2222-1746" + type: string + + pattern: "^4[0-9]{3}\\s[0-9]{4}\\s[0-9]{4}\\s[0-9]{4}$" + # Original was: 4[0-9]{3}\s[0-9]{4}\s[0-9]{4}\s[0-9]{4} + + date: + description: "Some dates\n + matches: 31/04/1999, 15/12/4567\n + non-matches: 31/4/1999, 31/4/99, 1999/04/19, 42/67/25456" + type: string + pattern: "^([0-2][0-9]|30|31)/(0[1-9]|1[0-2])/[0-9]{4}$" + # Original was: ([0-2][0-9]|30|31)/(0[1-9]|1[0-2])/[0-9]{4} : unchanged + + windowsAbsolutePath: + description: "Windows absolute path\n + matches: \\\\server\\share\\file\n + non-matches: \\directory\\directory2, /directory2" + type: string + + # This test case doesn't work due to a problem (?) in validator.v2 (?) + # it issues an unexpected unknown tag or Bad Parameter. + + # pattern: "^([A-Za-z]:|\\)\\[[:alnum:][:whitespace:]!\"#$%&'()+,-.;=@[]^_`{}~.]*$" + # Original was: ([A-Za-z]:|\\)\\[[:alnum:][:whitespace:]!"#$%&'()+,-.\\;=@\[\]^_`{}~.]* + + email1: + description: "Email Address 1\n + matches: abc.123@def456.com, _123@abc.ca\n + non-matches: abc@dummy, ab*cd@efg.hijkl" + type: string + + pattern: "^[[:word:]\\-.]+@[[:word:]\\-.]+\\.[[:alpha:]]{2,3}$" + # Original was: [[:word:]\-.]+@[[:word:]\-.]+\.[[:alpha:]]{2,3} + + email2: + description: "Email Address 2\n + matches: *@qrstuv@wxyz.12345.com, __1234^%@@abc.def.ghijkl\n + non-matches: abc.123.*&ca, ^%abcdefg123" + type: string + + pattern: "^.+@.+\\..+$" + # Original was: .+@.+\..+ + + htmlHexadecimalColorCode1: + description: "HTML Hexadecimal Color Code 1\n + matches: AB1234, CCCCCC, 12AF3B\n + non-matches: 123G45, 12-44-CC" + type: string + pattern: "^[A-F0-9]{6}$" + # Original was: [A-F0-9]{6} : unchanged + + htmlHexadecimalColorCode2: + description: "HTML Hexadecimal Color Code 2\n + matches: AB 11 00, CC 12 D3\n + non-matches: SS AB CD, AA BB CC DD, 1223AB" + type: string + + pattern: "^[A-F0-9]{2}\\s[A-F0-9]{2}\\s[A-F0-9]{2}$" + # Original was: [A-F0-9]{2}\s[A-F0-9]{2}\s[A-F0-9]{2} + + ipAddress: + description: "IP Address\n + matches: 10.25.101.216\n + non-matches: 0.0.0, 256.89.457.02" + type: string + + pattern: "^((2(5[0-5]|[0-4][0-9])|1([0-9][0-9])|([1-9][0-9])|[0-9])\\.){3}(2(5[0-5]|[0-4][0-9])|1([0-9][0-9])|([1-9][0-9])|[0-9])$" + # Original was: ((2(5[0-5]|[0-4][0-9])|1([0-9][0-9])|([1-9][0-9])|[0-9])\.){3}(2(5[0-5]|[0-4][0-9])|1([0-9][0-9])|([1-9][0-9])|[0-9]) + + javaComments: + description: "Java Comments\n + matches: Matches Java comments that are between /* and */, or one line comments prefaced by //\n + non-matches: a=1" + type: string + + # This test case doesn't work due to a problem (?) in validator.v2 (?) + # org.yaml.snakeyaml.scanner declares \* being an invalid escape code at yaml checking step + + # pattern: "^/\*.*\*/|//[^\\n]*$" + # Original was: /\*.*\*/|//[^\n]* + + money: + description: "\n + matches: $1.00, -$97.65 + non-matches: $1, 1.00$, $-75.17" + type: string + + pattern: "^(\\+|-)?\\$[0-9]*\\.[0-9]{2}$" + # Original was: (\+|-)?\$[0-9]*\.[0-9]{2} + + positiveNegativeDecimalValue: + description: "Positive, negative numbers, and decimal values\n + matches: +41, -412, 2, 7968412, 41, +41.1, -3.141592653 + non-matches: ++41, 41.1.19, -+97.14" + type: string + + pattern: "^(\\+|-)?[0-9]+(\\.[0-9]+)?$" + # Original was: (\+|-)?[0-9]+(\.[0-9]+)? + + password1: + description: "Passwords 1\n + matches: abcd, 1234, A1b2C3d4, 1a2B3\n + non-matches: abc, *ab12, abcdefghijkl" + type: string + pattern: "^[[:alnum:]]{4,10}$" + # Original was: [[:alnum:]]{4,10} : unchanged + + password2: + description: "Passwords 2\n + matches: AB_cd, A1_b2c3, a123_\n + non-matches: *&^g, abc, 1bcd" + type: string + + pattern: "^[a-zA-Z]\\w{3,7}$" + # Original was: [a-zA-Z]\w{3,7} : unchanged + + phoneNumber: + description: "Phone Numbers\n + matches: 519-883-6898, 519 888 6898\n + non-matches: 888 6898, 5198886898, 519 883-6898" + type: string + + pattern: "^([2-9][0-9]{2}-[2-9][0-9]{2}-[0-9]{4})|([2-9][0-9]{2}\\s[2-9][0-9]{2}\\s[0-9]{4})$" + # Original was: ([2-9][0-9]{2}-[2-9][0-9]{2}-[0-9]{4})|([2-9][0-9]{2}\s[2-9][0-9]{2}\s[0-9]{4}) + + sentence1: + description: "Sentences 1\n + matches: Hello, how are you?\n + non-matches: i am fine" + type: string + + pattern: "^[A-Z0-9].*(\\.|\\?|!)$" + # Original was: [A-Z0-9].*(\.|\?|!) + + sentence2: + description: "Sentences 2\n + matches: Hello, how are you?n + non-matches: i am fine" + type: string + pattern: "^[[:upper:]0-9].*[.?!]$" + # Original was: [[:upper:]0-9].*[.?!] : unchanged + + socialSecurityNumber: + description: "Social Security Number\n + matches: 123-45-6789\n + non-matches: 123 45 6789, 123456789, 1234-56-7891" + type: string + pattern: "^[0-9]{3}-[0-9]{2}-[0-9]{4}$" + # Original was: [0-9]{3}-[0-9]{2}-[0-9]{4} : unchanged + + url: + description: "URL\n + matches: http://www.sample.com, www.sample.com\n + non-matches: http://sample.com, http://www.sample.comm" + type: string + + # \. ==> \\. + pattern: "^(http://)?www\\.[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$" + # Original was: (http://)?www\.[a-zA-Z0-9]+\.[a-zA-Z]{2,3} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching01.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching01.json new file mode 100644 index 000000000000..ad6491579920 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching01.json @@ -0,0 +1,24 @@ +{ + "code": "52", + "creditCard": "4123 6453 2222 1746", + "date": "31/04/1999", + "windowsAbsolutePath": "\\\\server\\share\\file", + + "email1": "abc.123@def456.com", + "email2": "*@qrstuv@wxyz.12345.com", + "htmlHexadecimalColorCode1": "AB1234", + "htmlHexadecimalColorCode2": "AB 11 00", + "ipAddress": "10.25.101.216", + + "javaComments": "/* a comment */", + "money": "$1.00", + "positiveNegativeDecimalValue": "+41", + "password1": "abcd", + "password2": "AB_cd", + + "phoneNumber": "519-883-6898", + "sentence1": "Hello, how are you?", + "sentence2": "Hello, how are you?", + "socialSecurityNumber": "123-45-6789", + "url": "http://www.sample.com" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching02.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching02.json new file mode 100644 index 000000000000..2bc80ce4428f --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching02.json @@ -0,0 +1,24 @@ +{ + "code": "52", + "creditCard": "4123 6453 2222 1746", + "date": "15/12/4567", + "windowsAbsolutePath": "\\\\server\\share\\file", + + "email1": "_123@abc.ca", + "email2": "*__1234^%@@abc.def.ghijkl", + "htmlHexadecimalColorCode1": "CCCCCC", + "htmlHexadecimalColorCode2": "CC 12 D3", + "ipAddress": "10.25.101.216", + + "javaComments": "// another comment", + "money": "-$97.65", + "positiveNegativeDecimalValue": "-412", + "password1": "1234", + "password2": "A1_b2c3", + + "phoneNumber": "519 888 6898", + "sentence1": "Hello, how are you?", + "sentence2": "Hello, how are you?", + "socialSecurityNumber": "123-45-6789", + "url": "www.sample.com" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching03.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching03.json new file mode 100644 index 000000000000..e65fc31309c0 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching03.json @@ -0,0 +1,25 @@ +{ + "code": "52", + "creditCard": "4123 6453 2222 1746", + "date": "15/12/4567", + "windowsAbsolutePath": "\\\\server\\share\\file", + + "email1": "_123@abc.ca", + "email2": "*__1234^%@@abc.def.ghijkl", + "htmlHexadecimalColorCode1": "CCCCCC", + "htmlHexadecimalColorCode2": "CC 12 D3", + "ipAddress": "10.25.101.216", + + "javaComments": "// another comment", + "money": "-$97.65", + "positiveNegativeDecimalValue": "7968412", + "password1": "A1b2C3d4", + "password2": "a123_", + + "phoneNumber": "519 888 6898", + "sentence1": "Hello, how are you?", + "sentence2": "Hello, how are you?", + "socialSecurityNumber": "123-45-6789", + + "url": "www.sample.com" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching04.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching04.json new file mode 100644 index 000000000000..e92e83ce2b75 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_matching04.json @@ -0,0 +1,24 @@ +{ + "code": "52", + "creditCard": "4123 6453 2222 1746", + "date": "15/12/4567", + "windowsAbsolutePath": "\\\\server\\share\\file", + + "email1": "_123@abc.ca", + "email2": "*__1234^%@@abc.def.ghijkl", + "htmlHexadecimalColorCode1": "CCCCCC", + "htmlHexadecimalColorCode2": "CC 12 D3", + "ipAddress": "10.25.101.216", + + "javaComments": "// another comment", + "money": "-$97.65", + "positiveNegativeDecimalValue": "-3.141592653", + "password1": "1a2B3", + "password2": "a123_", + + "phoneNumber": "519 888 6898", + "sentence1": "Hello, how are you?", + "sentence2": "Hello, how are you?", + "socialSecurityNumber": "123-45-6789", + "url": "www.sample.com" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching01.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching01.json new file mode 100644 index 000000000000..17af97214be5 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching01.json @@ -0,0 +1,24 @@ +{ + "code": "52,", + "creditCard": "3124 5675 4400 4567", + "date": "31/4/1999", + "windowsAbsolutePath": "\\\\directory\\\\directory2", + + "email1": "abc@dummy", + "email2": "abc.123.*&ca", + "htmlHexadecimalColorCode1": "123G45", + "htmlHexadecimalColorCode2": "SS AB CD", + "ipAddress": "0.0.0", + + "javaComments": "a=1", + "money": "$1", + "positiveNegativeDecimalValue": "++41", + "password1": "abc", + "password2": "*&^g", + + "phoneNumber": "888 6898", + "sentence1": "i am fine", + "sentence2": "i am fine", + "socialSecurityNumber": "123 45 6789", + "url": "http://sample.com" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching02.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching02.json new file mode 100644 index 000000000000..5055732f14ae --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching02.json @@ -0,0 +1,25 @@ +{ + + "code": "52,", + "creditCard": "4123-6453-2222-1746", + "date": "31/4/99", + "windowsAbsolutePath": "/directory2", + + "email1": "ab*cd@efg.hijkl", + "email2": "^%abcdefg123", + "htmlHexadecimalColorCode1": "12-44-CC", + "htmlHexadecimalColorCode2": "AA BB CC DD", + "ipAddress": "256.89.457.02", + + "javaComments": "a=1", + "money": "1.00$", + "positiveNegativeDecimalValue": "41.1.19", + "password1": "*ab12", + "password2": "abc", + + "phoneNumber": "5198886898", + "sentence1": "i am fine", + "sentence2": "i am fine", + "socialSecurityNumber": "123456789", + "url": "http://www.sample.comm" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching03.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching03.json new file mode 100644 index 000000000000..b1250e2017ae --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching03.json @@ -0,0 +1,24 @@ +{ + "code": "52,", + "creditCard": "4123-6453-2222-1746", + "date": "1999/04/19", + "windowsAbsolutePath": "/directory2", + + "email1": "ab*cd@efg.hijkl", + "email2": "^%abcdefg123", + "htmlHexadecimalColorCode1": "12-44-CC", + "htmlHexadecimalColorCode2": "1223AB", + "ipAddress": "256.89.457.02", + + "javaComments": "a=1", + "money": "$-75.17", + "positiveNegativeDecimalValue": "-+97.14", + "password1": "*abcdefghijkl", + "password2": "1bcd", + + "phoneNumber": "519 883-6898", + "sentence1": "i am fine", + "sentence2": "i am fine", + "socialSecurityNumber": "1234-56-7891", + "url": "http://www.sample.comm" +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching04.json b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching04.json new file mode 100644 index 000000000000..15291fa82a94 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_20079_non_matching04.json @@ -0,0 +1,24 @@ +{ + "code": "52,", + "creditCard": "4123-6453-2222-1746", + "date": "42/67/25456", + "windowsAbsolutePath": "/directory2", + + "email1": "ab*cd@efg.hijkl", + "email2": "^%abcdefg123", + "htmlHexadecimalColorCode1": "12-44-CC", + "htmlHexadecimalColorCode2": "1223AB", + "ipAddress": "256.89.457.02", + + "javaComments": "a=1", + "money": "$-75.17", + "positiveNegativeDecimalValue": "-+97.14", + "password1": "*abcdefghijkl", + "password2": "1bcd", + + "phoneNumber": "519 883-6898", + "sentence1": "i am fine", + "sentence2": "i am fine", + "socialSecurityNumber": "1234-56-7891", + "url": "http://www.sample.comm" +} diff --git a/samples/client/others/go/oneof-anyof-required/model_object.go b/samples/client/others/go/oneof-anyof-required/model_object.go index f0a03353b5c2..d57faa84691e 100644 --- a/samples/client/others/go/oneof-anyof-required/model_object.go +++ b/samples/client/others/go/oneof-anyof-required/model_object.go @@ -84,7 +84,16 @@ func (dst *Object) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(Object)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(Object): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(Object)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(Object): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(Object)") + } } } diff --git a/samples/client/petstore/go/go-petstore/model_format_test_.go b/samples/client/petstore/go/go-petstore/model_format_test_.go index 0dddb61a87a9..d1ed724b0ecc 100644 --- a/samples/client/petstore/go/go-petstore/model_format_test_.go +++ b/samples/client/petstore/go/go-petstore/model_format_test_.go @@ -29,8 +29,8 @@ type FormatTest struct { Number float32 `json:"number"` Float *float32 `json:"float,omitempty"` Double *float64 `json:"double,omitempty"` - String *string `json:"string,omitempty" validate:"regexp=[a-z]/i"` - Byte string `json:"byte" validate:"regexp=^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=)?$"` + String *string `json:"string,omitempty" validate:"regexp=/[a-z]/i"` + Byte string `json:"byte" validate:"regexp=^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"` Binary **os.File `json:"binary,omitempty"` Date string `json:"date"` DateTime *time.Time `json:"dateTime,omitempty"` diff --git a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/model_category.go b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/model_category.go index e962c7ef185d..172396474534 100644 --- a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/model_category.go +++ b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/model_category.go @@ -20,7 +20,7 @@ var _ MappedNullable = &Category{} // Category A category for a pet type Category struct { Id *int64 `json:"id,omitempty"` - Name *string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name *string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` AdditionalProperties map[string]interface{} } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go b/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go index e7529f6d4532..31d86cc7d6f5 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go @@ -28,7 +28,7 @@ type FormatTest struct { Number float32 `json:"number"` Float *float32 `json:"float,omitempty"` Double *float64 `json:"double,omitempty"` - String *string `json:"string,omitempty" validate:"regexp=[a-z]/i"` + String *string `json:"string,omitempty" validate:"regexp=/[a-z]/i"` Byte string `json:"byte"` Binary **os.File `json:"binary,omitempty"` Date string `json:"date"` @@ -36,10 +36,10 @@ type FormatTest struct { Uuid *string `json:"uuid,omitempty"` Password string `json:"password"` // A string that is a 10 digit number. Can have leading zeros. - PatternWithDigits *string `json:"pattern_with_digits,omitempty" validate:"regexp=^\\\\d{10}$"` + PatternWithDigits *string `json:"pattern_with_digits,omitempty" validate:"regexp=^\\d{10}$"` // A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. - PatternWithDigitsAndDelimiter *string `json:"pattern_with_digits_and_delimiter,omitempty" validate:"regexp=^image_\\\\d{1,3}$/i"` - PatternWithBacktick *string "json:\"pattern_with_backtick,omitempty\" validate:\"regexp=^$|^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$\"" + PatternWithDigitsAndDelimiter *string `json:"pattern_with_digits_and_delimiter,omitempty" validate:"regexp=/^image_\\d{1\\,3}$/i"` + PatternWithBacktick *string `json:"pattern_with_backtick,omitempty" validate:"regexp=^$|^[a-zA-Z0-9.!#$%&'*+/=?^_\x60{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0\\,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0\\,61}[a-zA-Z0-9])?)*$"` AdditionalProperties map[string]interface{} } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go b/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go index 8bc39dc50703..7b1f6bdf6cbd 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go @@ -84,7 +84,16 @@ func (dst *Fruit) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(Fruit)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(Fruit): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(Fruit)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(Fruit): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(Fruit)") + } } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go index d2b0a4f878a5..c7c254fdf180 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go @@ -84,7 +84,16 @@ func (dst *FruitReq) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(FruitReq)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(FruitReq): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(FruitReq)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(FruitReq): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(FruitReq)") + } } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go b/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go index e2d1fd6beee8..c475b85faca4 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go @@ -89,7 +89,16 @@ func (dst *IncidentData) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(IncidentData)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(IncidentData): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(IncidentData)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(IncidentData): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(IncidentData)") + } } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go b/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go index dfc3359257a7..3cbc9604fce3 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go @@ -84,7 +84,16 @@ func (dst *Mammal) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(Mammal)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(Mammal): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(Mammal)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(Mammal): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(Mammal)") + } } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go index 77c1786358c4..c9ba10e4bfd5 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go @@ -110,7 +110,21 @@ func (dst *OneOfPrimitiveType) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType)") + } } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go index cd739f07abc4..1e1f6686982b 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go @@ -85,7 +85,16 @@ func (dst *OneOfPrimitiveTypes) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveTypes)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveTypes): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveTypes)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveTypes): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveTypes)") + } } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go index d945fbd2e78f..e226e6ec6dd1 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go @@ -84,7 +84,16 @@ func (dst *OneOfWithComplexType) UnmarshalJSON(data []byte) error { } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(OneOfWithComplexType)") + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfWithComplexType): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfWithComplexType)") + } + if err != nil { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfWithComplexType): %v", err) + } else { + return fmt.Errorf("data failed to match schemas in oneOf(OneOfWithComplexType)") + } } } diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/model_category.go b/samples/openapi3/server/petstore/go/go-petstore/go/model_category.go index a8c835c0da4d..ef07e88e2f32 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/model_category.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/model_category.go @@ -18,7 +18,7 @@ type Category struct { Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` } // AssertCategoryRequired checks if the required fields are not zero-ed diff --git a/samples/server/petstore/go-api-server/go/model_category.go b/samples/server/petstore/go-api-server/go/model_category.go index a8c835c0da4d..ef07e88e2f32 100644 --- a/samples/server/petstore/go-api-server/go/model_category.go +++ b/samples/server/petstore/go-api-server/go/model_category.go @@ -18,7 +18,7 @@ type Category struct { Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` } // AssertCategoryRequired checks if the required fields are not zero-ed diff --git a/samples/server/petstore/go-chi-server/go/model_category.go b/samples/server/petstore/go-chi-server/go/model_category.go index a8c835c0da4d..ef07e88e2f32 100644 --- a/samples/server/petstore/go-chi-server/go/model_category.go +++ b/samples/server/petstore/go-chi-server/go/model_category.go @@ -18,7 +18,7 @@ type Category struct { Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` } // AssertCategoryRequired checks if the required fields are not zero-ed diff --git a/samples/server/petstore/go-echo-server/models/model_category.go b/samples/server/petstore/go-echo-server/models/model_category.go index ea8cd109fde3..0a3ef7f75d05 100644 --- a/samples/server/petstore/go-echo-server/models/model_category.go +++ b/samples/server/petstore/go-echo-server/models/model_category.go @@ -5,5 +5,5 @@ type Category struct { Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` } diff --git a/samples/server/petstore/go-gin-api-server-interface-only/go/model_category.go b/samples/server/petstore/go-gin-api-server-interface-only/go/model_category.go index 165983fbcaaa..174d5f9ae145 100644 --- a/samples/server/petstore/go-gin-api-server-interface-only/go/model_category.go +++ b/samples/server/petstore/go-gin-api-server-interface-only/go/model_category.go @@ -14,5 +14,5 @@ type Category struct { Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` } diff --git a/samples/server/petstore/go-gin-api-server/go/model_category.go b/samples/server/petstore/go-gin-api-server/go/model_category.go index 165983fbcaaa..174d5f9ae145 100644 --- a/samples/server/petstore/go-gin-api-server/go/model_category.go +++ b/samples/server/petstore/go-gin-api-server/go/model_category.go @@ -14,5 +14,5 @@ type Category struct { Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$"` + Name string `json:"name,omitempty" validate:"regexp=^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"` }