swagger-api / swagger-api/swagger-codegen
[DOTNETCORE] regex pattern include trailing and ending /
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Code generation of reqex pattern will add a trailing and ending / to the pattern i.e. /[A-Z]/ which by my understanding is not a valid reqex in .net core.
Swagger-codegen version
Version: 2.3.1
Swagger declaration file content or url
Using this definition in the yaml file
Person:
properties:
id:
type: string
pattern: '[a-z0-9]'
description: Id of the person
Will give this output:
/// The id of the person
[RegularExpression("/[a-z0-9]/")]
Note that you need to update the template files to have the RegularExpression in the generated model file.
The generated model (-DdebugModels) include the the regexp with / so the fault is there when generating the model.
Command line used for generation
java -jar mmodules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -l aspnetcore -i file.yml
Steps to reproduce
- add pattern to yaml file
- code generate
Related issues/PRs
Found similar issues where it seems to be introduced due to some python stuff and then other that pinpoint the problem.
https://github.com/swagger-api/swagger-codegen/issues/5548
https://github.com/swagger-api/swagger-codegen/issues/3839
https://github.com/swagger-api/swagger-codegen/pull/2794
Suggest a fix/enhancement
https://github.com/swagger-api/swagger-codegen/issues/3839
Pinpoint where in code the / are introduced and a proposal that I think will work.
Why does the code gen add the /? Isn't it better to move any need of trailing/ending slash to the language specifics template files instead?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided YAML and the aspnetcore generator command, then inspect the generated model and -DdebugModels output to locate where the regex delimiters are added. Done means the generated RegularExpression value contains [a-z0-9] without surrounding slashes, with coverage for the pattern-generation path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100