swagger-api / swagger-api/swagger-codegen

HTML2 Generated Examples Bad Lines

Open
#7,993 1 comment 1 reaction 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

For HTML2 the generated examples for the various languages has 3 lines which are incorrect. The line for creating what would normally be the body object in a REST API, the line for calling the SDK method, and the print error lines may contain errors. Multiple languages contain these bugs.

For example in Java the template is:

{{{classname}}} apiInstance = new {{{classname}}}();
{{#allParams}}
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{unescapedDescription}}}
{{/allParams}}
try {
            {{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}} {{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
            System.out.println(result);{{/returnType}}
} catch (ApiException e) {
            System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
            e.printStackTrace();
}

which results in an output like:

PackageClassApi apiInstance = new PackageClassApi();
BodyObjectDataType bodyObject= ; // bodyObject | Parameter description. //Bad declaration
try {
            bodyObject result = apiInstance.somePostMethod(bodyObject); //No data type used
            System.out.println(result);
} catch (ApiException e) {
            System.err.println("Exception when calling PackageClassAPI#somePostMethod"); //# instead of .
            e.printStackTrace();
}

instead of the desired:

PackageClassApi apiInstance = new PackageClassApi();
BodyObjectDataType bodyObject= new BodyObjectDataType(); // bodyObject | Parameter description. //Declaration is complete
try {
            BodyObjectDataType result = apiInstance.somePostMethod(bodyObject); //Correct data type
            System.out.println(result);
} catch (ApiException e) {
            System.err.println("Exception when calling PackageClassAPI.somePostMethod"); //A . is used
            e.printStackTrace();
}
Swagger-codegen version

2.3.1

Swagger declaration file content or url
post:
      tags:
      - "PackageClass"
      operationId: "somePostMethod"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "someBodyObject"
        schema:
          $ref: "#/definitions/BodyObjectDataType"

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

Locate the HTML2 templates that produce the shown Java example, then compare their output using the supplied OpenAPI YAML declaration. Done means the generated body-object declaration includes its example value, the call includes the return type, and the exception message uses a dot instead of a hash across the affected language templates.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.