Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C# - aspnetcore] 'pattern' specification generated code regular expression is wrong #1365

Closed
grmcdorman opened this issue Nov 2, 2018 · 3 comments · Fixed by #1371
Closed

Comments

@grmcdorman
Copy link

Description

For a parameter specification similar to the following:

{
 "name": "ID",
  "in": "path",
  "description": "ID",
  "required": true,
  "type": "string",
  "pattern": "[0-9a-f]{8}"
}

the resulting action has a parameter decorated (correctly) with [FromRoute][Required]; however, the RegularExpression is incorrect:

[RegularExpression("/[0-9a-f]{8}/")]

The leading and trailing slashes are treated literally, i.e. they must (incorrectly) appear in the parameter value.

openapi-generator version

main; I do not know if this is a regression.

OpenAPI declaration file content or url
{
 "name": "ID",
  "in": "path",
  "description": "ID",
  "required": true,
  "type": "string",
  "pattern": "[0-9a-f]{8}"
}
Command line used for generation

java -jar "openapi-generator-cli.jar" generate -i $GenApiPath -g aspnetcore -o $CodeDirectory -c $Parameters

Steps to reproduce

Generate with the above parameter specification.

Related issues/PRs
Suggest a fix/enhancement
@wing328
Copy link
Member

wing328 commented Nov 5, 2018

@grmcdorman thanks for reporting the issue. I've filed #1371 to fix the issue and my test result looks good without the forward slashes:

         [Route("/v2/pet/{petId}")]
         [ValidateModelState]
         [SwaggerOperation("UpdatePetWithForm")]
-        public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status)
+        public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm][RegularExpression("[0-9a-f]{8}")]string name, [FromForm]string status)
         {
             //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ...

@grmcdorman
Copy link
Author

Nice; thanks. Good that there's an appropriate override, sign of a good design.

@wing328
Copy link
Member

wing328 commented Nov 5, 2018

@grmcdorman thanks for the quick review. The fix has been merged into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants