swagger-api / swagger-api/swagger-codegen

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

Open
#10,579 1 comment 0 reactions 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

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"
}

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 by reproducing the issue with the html2 generator through the Maven plugin and trace how the response schema's example is rendered. Compare the object example with the existing scalar rendering; done means the generated output shows the example's title and body values instead of [object Object].

Written by the indexing model from the issue text.

Assessment

Tech stack
html
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.