swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.78k stars 6.02k forks source link

[html2] Example Object is Rendered as "example: [object Object]" #10579

Open emmercm opened 3 years ago

emmercm commented 3 years ago

Description

When generating language = html2 with the below example, the response schema gets rendered as:

{
  title: string
  body: string
}
example: [object Object]

But this should be supported per: https://swagger.io/docs/specification/adding-examples/#schemas

Swagger-codegen version

v3.0.14 - v3.0.23

Swagger declaration file content or url

openapi: 3.0.0
info:
  title: example
  version: 0.0.0
paths:
  /example:
    get:
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  title:
                    type: string
                  body:
                    type: string
                example:
                  title: example title
                  body: example body

Command line used for generation

The Maven plugin: https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-maven-plugin

Steps to reproduce

See above.

Related issues/PRs

Possibly https://github.com/swagger-api/swagger-codegen/issues/4896.

Suggest a fix/enhancement

The example could instead be rendered similar to:

{
  title: string
  body: string
}
example: {
  "title": "example title",
  "body": "example body"
}
anishsatalkar commented 3 years ago

Faced this issue while using swagger-codegen-cli-3.0.24.jar. However, when the same JSON / YAML is fed to https://editor.swagger.io/, the output shows examples correctly even though it internally uses codegen. Maybe it has its own additional implementation.