swagger-api/swagger-codegen

[DOTNETCORE] regex pattern include trailing and ending /

Opened this issue · 0 comments

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.
#5548
#3839
#2794

Suggest a fix/enhancement

#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?