swagger-api / swagger-api/swagger-codegen

[HTML] OAS3.0 code without components block throws 500

Open
#8,222 1 comment 0 reactions 1 assignee View on GitHub

@HugoMario is already working on this.

Since May 22, 2018.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

If your OAS3.0 YAML definition doesn't have a components block, the editor doesn't show any errors - but clicking generate client throws an HTTP 500 error in the Chrome Dev Console.

Swagger-codegen version

Whatever is running at generator3.swagger.io/v2/generate.json

Swagger declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
               properties:
                id:
                  type: integer
                  format: int64
                name:
                  type: string
                tag:
                  type: string
        default:
          description: unexpected error
          content:
            application/json:
              schema:
               properties:
                id:
                  type: integer
                  format: int64
                name:
                  type: string
                tag:
                  type: string
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
               properties:
                id:
                  type: integer
                  format: int64
                name:
                  type: string
                tag:
                  type: string
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
               properties:
                id:
                  type: integer
                  format: int64
                name:
                  type: string
                tag:
                  type: string
        default:
          description: unexpected error
          content:
            application/json:
              schema:
               properties:
                id:
                  type: integer
                  format: int64
                name:
                  type: string
                tag:
                  type: string
# components:
#   schemas:
#     Pet:
#       required:
#         - id
#         - name
#       properties:
#         id:
#           type: integer
#           format: int64
#         name:
#           type: string
#         tag:
#           type: string
#     Pets:
#       type: array
#       items:
#         $ref: "#/components/schemas/Pet"
#     Error:
#       required:
#         - code
#         - message
#       properties:
#         code:
#           type: integer
#           format: int32
#         message:
#           type: string
Command line used for generation

n/a

Steps to reproduce
  1. Paste above YAML in editor.swagger.io (use HTTP because of this: https://github.com/swagger-api/swagger-editor/issues/1762)
  2. Click generate client
  3. Observe 500 error in Chrome Dev Console

Note that the editor shows no errors with components commented out. If you un-comment the components section, it works.

Suggest a fix/enhancement

If the editor doesn't show an error, the generator should work. I'm not sure what is going wrong here to cause this problem.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.