swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

HTML2 Generated Examples Bad Lines

Open PeaceInColour opened this issue 8 years ago • 1 comments

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"

PeaceInColour avatar Apr 09 '18 21:04 PeaceInColour

The issues are with the data being passed to the HTML2 templates. For the BodyObjectDataType bodyObject= ; // bodyObject | Parameter description. line there is no data being provided for the example parameter in the HTML2 template. For the bodyObject result = apiInstance.somePostMethod(bodyObject); line the returnType parameter has the wrong data (bodyObject instead of BodyObjectDataType)

PeaceInColour avatar Apr 12 '18 19:04 PeaceInColour