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

swagger-codegen-cli-2.4.21.jar -l html creates empty "examples"

Open Snipke opened this issue 3 years ago • 1 comments

Description
Swagger-codegen version

Generated correctly with 2.4.20, but no longer with 2.4.21

Swagger declaration file content or url
          "examples" : [ {
            "contentType" : "application/json",
            "example" : "{\"empty\": false}"
          } ],
Command line used for generation

-DdebugSupportingFiles -l html

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

Snipke avatar Sep 05 '22 13:09 Snipke

Looking at the changes in code, it's probably caused by replacing "m.modelJson = Json.pretty(model);" swagger-codegen\modules\swagger-codegen\src\main\java\io\swagger\codegen\DefaultCodegen.java by

    // NOTE: not using Json.pretty() to write out model, as it
    // can raise memory consumption (see comment in ExampleGenerator)
    try {
        m.modelJson = Json.mapper().writeValueAsString(model);
    } catch (Exception e) {
        m.modelJson = "{}";
    }

So maybe it needs to be reverted to

m.modelJson = Json.pretty(model);

See https://github.com/swagger-api/swagger-codegen/pull/11071

Snipke avatar Sep 05 '22 14:09 Snipke

I can confirm this. Generated examples are still serialized.

Warkdev avatar Nov 05 '22 16:11 Warkdev