Open CyrilleBenard opened 6 years ago
Having the same problem for Java code generation, using:
org.openapitools:openapi-generator-gradle-plugin:3.3.2
myField:
type: string
pattern: '[0-9]{10,11}'
example: '12223334444'
Also tried pattern '/[0-9]{10,11}/'
I have created a patch providing a const validator doing pattern validation via std::regex at strings and range checks at numbers throwing an exception. Is someone already fixing it or should I share my draft ;-)
By default, I would have said : "Share it" :)
Pull it :)
It is really tricky to provide a clean solution since arrays are not explicit generated to a model and so all validation items of an array type has to be passed using root nodes at java.
next issue is that at the moment any value can be returned by design.
this is a draft. I am not really satisfied with it. But it works fine. 0000-CPistacheServer-remove-not-generated-but-included-file-Objecth.patch.txt
flame on ;-)
Description
The generator does not consider the pattern "inside" a string type. I mean, when the openapi file describes the below syntax :
The generator does not take into account the pattern restriction. No dedicated code is generated
openapi-generator version
Current master : 3.3.1-SNAPSHOT
OpenAPI declaration file content or url
Command line used for generation
Generate :
Compile :
Steps to reproduce
Generate & compile
Related issues/PRs
N/A
Suggest a fix/enhancement
Each variable should be validated with the pattern before any other treatment, in case there is a pattern to apply, of course. If the string (other type ?) does not match, return a dedicated HTTP error code 4xx : 412 ? 422 ? or the "generic" 400
As the pattern is regex compliant, the C++ std::regex lib may be used and the pattern transmitted as this to the std::regex_match method.