swagger-api / swagger-codegen-generators

Apache License 2.0
283 stars 423 forks source link

Bug: Content-Type of responces examples (html generator) #965

Open 4n70w4 opened 3 years ago

4n70w4 commented 3 years ago

Hi! I get code from example of docs: https://swagger.io/docs/specification/adding-examples/

image

and

image

and see:

image

Why Ron and Jessica is content type? The documentation doesn't have it.

src\main\resources\handlebars\htmlDocs\index.mustache image

Reproduce:

openapi: 3.0.1

info:
  title:
  description:
  version:

paths:
  /users:
    post:
      summary: Adds a new user
      requestBody:
        content:
          application/json:     # Media type
            schema:             # Request body contents
              $ref: '#/components/schemas/User'   # Reference to an object
            examples:    # Child of media type
              Jessica:   # Example 1
                value:
                  id: 10
                  name: Jessica Smith
              Ron:       # Example 2
                value:
                  id: 11
                  name: Ron Stewart
      responses:
        '200':
          description: A user object.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'   # Reference to an object
              examples:
                Jessica:
                  value:
                    id: 10
                    name: Jessica Smith
                Ron:
                  value:
                    id: 20
                    name: Ron Stewart

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 1
        name:
          type: string
          example: New order

and run generation:

docker run --rm \
    -v $PWD:/local \
    swaggerapi/swagger-codegen-cli-v3:3.0.27 \
    generate \
        -i /local/openapi.yaml \
        -o /local/html \
        -l html
4n70w4 commented 3 years ago

May be this behavior from v2?

https://swagger.io/docs/specification/2-0/adding-examples/

image