swagger-api / swagger-api/swagger-codegen

[JAVA] Bug code generation cannot deal with quotes in @ApiModelProperty

Open
#7,703 0 comments 2 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

The result model of my API is annotated with @ApiModelProperty. At some locations I provide example values for the Swagger documentation, for instance:

  @ApiModelProperty(value = "A list with correction suggestions", example = "[\"misspelled\", \"suggested\"]")
  public Collection<String> getSuggestions() {

The Java code generation fails due to the escaped quotation marks in the example attribute. It generates:

  @ApiModelProperty(example = "&quot;[\&quot;misspelled\&quot;, \&quot;suggested\&quot;]&quot;", value = "A list with correction suggestions")
  public List<String> getSuggestions() {
Swagger declaration file content or url

The input specification looks like that:

 ...
        "suggestions" : {
          "type" : "array",
          "example" : "[\"misspelled\", \"suggested\"]",
          "description" : "A list with correction suggestions",
          "items" : {
            "type" : "string"
          }
Swagger-codegen version

I use io.swagger:swagger-codegen-maven-plugin:2.2.2. I cannot take a newer version because I don't use Maven 3.

Command line used for generation

I configured the plugin as follows:

        <plugin>
          <groupId>io.swagger</groupId>
          <artifactId>swagger-codegen-maven-plugin</artifactId>
          ...
          <executions>
            <execution>
              <phase>generate-sources</phase>
              <goals>
                <goal>generate</goal>
              </goals>
              <configuration>
                <addCompileSourceRoot>false</addCompileSourceRoot>
                <output>${project.build.directory}/swagger</output>
                <inputSpec>swagger.json</inputSpec>
                <inputSpec>${project.build.directory}/swagger/${project.groupId}.json</inputSpec>
                <language>java</language>
                <apiPackage>${project.artifactId}.api</apiPackage>
                <modelPackage>${project.artifactId}.model</modelPackage>
                <invokerPackage>${project.artifactId}.invoker</invokerPackage>
                <generateApis>true</generateApis>
                <generateApiTests>true</generateApiTests>
                <generateApiDocumentation>true</generateApiDocumentation>
                <generateModels>true</generateModels>
                <generateModelTests>true</generateModelTests>
                <generateModelDocumentation>true</generateModelDocumentation>
                <generateSupportingFiles>false</generateSupportingFiles>
                <library>jersey2</library>
              </configuration>
            ...

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

Start by reproducing the failure with the provided Swagger declaration and the Java generator configuration using swagger-codegen-maven-plugin 2.2.2. Trace the Java model generation and @ApiModelProperty rendering; done means escaped quotation marks in the example remain valid Java annotation content rather than becoming HTML entities, with coverage for this input.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.