swagger-api / swagger-api/swagger-codegen

[DOTNETCORE] regex pattern include trailing and ending /

Open
#8,124 0 comments 0 reactions 0 assignees View on GitHub

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
  1. add pattern to yaml file
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.