OpenAPITools / OpenAPITools/openapi-generator

[BUG] html2 generator JS error: "Cannot read property '$ref' of undefined"

Open
#2,427 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: HTML Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

The HTML output by the html2 generator gives this error when run in Chrome:

index.html:11 Uncaught TypeError: Cannot read property '$ref' of undefined
at HTMLDocument.<anonymous> (index.html:1288)
openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url

The below yaml is valid as per:

[q@local] docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli validate -i /local/api.yaml
Validating spec (/local/api.yaml)
No validation issues detected.
openapi: 3.0.0
info:
  title: Anchor-ResMan adaptor
  description: A RESTful API for retrieval of property data cached by the Anchor-ResMan adapter background service.
  version: "1.0.0"
servers:
  - description: SwaggerHub API Auto Mocking
    url: https://virtserver.swaggerhub.com/strangecode/AnchorNW/1.0.0
paths:
  /properties:
    get:
      summary: get a list of properties
      operationId: searchProperties
      description: |
        Get a list of all properties, filtered by search criteria.
      parameters:
        - in: query
          name: searchString
          description: pass an optional search string for looking up inventory
          required: false
          schema:
            type: string
        - in: query
          name: skip
          description: number of records to skip for pagination
          schema:
            type: integer
            format: int32
            minimum: 0
        - in: query
          name: limit
          description: maximum number of records to return
          schema:
            type: integer
            format: int32
            minimum: 0
            maximum: 50
      responses:
        '200':
          description: properties results matching criteria
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Property'
        '400':
          description: bad input parameter
components:
  schemas:
    Property:
      type: object
      properties:
        propertyID:
          type: string
          format: uuid
          example: '31ed6cca-b03a-4fbd-a65f-0e8c5e578e34'
        name:
          type: string
          example: 'x UDG Everett LLC'
        streetAddress:
          type: string
          example: '316 NE 28th Avenue'
        city:
          type: string
          example: 'Portland'
        state:
          type: string
          example: 'OR'
        zip:
          type: string
          example: '97232'
        phone:
          type: string
          example: '(503) 726-7220'
        email:
          type: string
          example: 'info@anchornw.com'
        manager:
          type: string
          example: 'Mylisa Giroski'
        currentPeriodStart:
          type: string
          format: date
          example: '2019-01-01'
        currentPeriodEnd:
          type: string
          format: date
          example: '2019-01-31'
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -g html2 -i /local/api.yaml -o /local
Steps to reproduce
  1. Generate html2 from the above YAML file.
  2. Open in Chrome
  3. See the errors in Chrome DevTools
Screen Shot 2019-03-16 at 13 32 10

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 running the documented Docker generation command with the provided api.yaml, then inspect the generated index.html around the reported line 1288 and reproduce the error in Chrome. Trace the undefined $ref access in the generated HTML/JavaScript and confirm that the same specification opens without a console error when done.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript, openapi
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.