swagger-api / swagger-api/swagger-codegen-generators

Description of models in schema.requestbodies not escaped (DefaultCodeGenConfig)

Open
#221 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

Description

the description field of all models from schema.requestbodies are not escaped.

Swagger-codegen version

3.0.2
1.0.2
generatorName: jaxrs-spec

Swagger declaration file content or url
openapi: 3.0.1
paths:
  /accountReferenceIban:
    get:
    responses:
      '200':
      $ref: "#/components/requestBodies/myobject"
components:
  requestBodies:
    myobject:
      description: |
        mulitlinedescription
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/accountReferenceIban"
  schemas:
    accountReferenceIban:
      type: object
      required:
        - iban
      properties:
        iban:
          type: string
Command line used for generation

java -jar swagger-codegen-cli-3.0.2.jar generate -i test.yaml -l jaxrs-spec --api-package=api --model-package=model

Steps to reproduce

Execute command line above. Compile error occurs because of a unexpected line break.

image

following overloaded methods fixes the bug:

public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> schemas, Set<String> imports) {
        CodegenParameter codegenParameter = super.fromRequestBody(body, schemas, imports);
        codegenParameter.description = this.escapeText(codegenParameter.description);
        return codegenParameter;
    }

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 at DefaultCodeGenConfig and the jaxrs-spec generator's fromRequestBody entry point, then reproduce the provided command with the OpenAPI declaration. Verify how request-body descriptions are handled and ensure the generated model output no longer contains an unexpected line break or compilation error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.