Skip to content

Bean validation pattern html escaped in generated java code #5548

@apolci

Description

@apolci
Description

When generating a java model or api including a "pattern" validation, the pattern is html escaped in the generated java code.
As an example the pattern "[^&]*] translate to the following annotation:
@Pattern("[^&]")

Swagger-codegen version

I'm using 2.2.2 but also the current master present the same problem.

Swagger declaration file content or url
swagger: "2.0"
info:
  version: "1.0"
  title: "Hello World API"
paths:
  /hello/:
    get:
      description: Returns a greeting to the user!
      parameters:
        - name: user
          in: query
          type: string
          pattern: '[^&]*'
          required: true
          description: The name of the user to greet.
      responses:
        200:
          description: Returns the greeting.
          schema:
            type: string
Command line used for generation

java -Dapis -jar swagger-codegen-cli-2.2.2.jar generate -i test.yaml -l spring -c test.conf

Content of test.conf:

{
  "useBeanValidation": true,
  "library": "spring-mvc",
  "generateModelTests": false,
  "generateApis": false,
  "generateSupportingFiles": false,
  "dateLibrary": "java8",
  "interfaceOnly": true
}
Steps to reproduce
  1. Run the above command line with provided yaml and conf
  2. Search HelloApi.java in the generated sources, it will contain the code @Pattern(regexp="[^&]*")

Tested also in http://editor.swagger.io/

Suggest a Fix

In several mustache templates the text @Pattern(regexp="{{pattern}}") should be replaced with @Pattern(regexp="{{{pattern}}}") to avoid html escaping.

Pull request will follow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions