-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Milestone
Description
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: stringCommand 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
- Run the above command line with provided yaml and conf
- 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.