Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
quinncomendant opened this issue Mar 16, 2019 · 7 comments

Comments

@quinncomendant
Copy link

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

@auto-labeler
Copy link

auto-labeler bot commented Mar 16, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@bmstanley
Copy link

Were you able to find a work-around for this issue? I am running into this as well and I don't see an easy fix for this.

@Araevin
Copy link

Araevin commented Jul 22, 2019

I ran into the same issue. I didn't fix it generator-side, but changing every instance of the line:
var schema = schemaWrapper.schema to
var schema = schemaWrapper.content['application/json'].schema;
in my generated index.html worked for me.

In the generated document, the schemaWrapper variable was formatted like this:

var schemaWrapper = {
  "description" : "An example object with schema",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/example"
      }
    }
  }
};

So it makes sense schemaWrapper.schema is undefined

Edit: I forgot, I also had to change each instance of:
schemaWrapper.definitions = Object.assign({}, defs);
to:

schemaWrapper.definitions = Object.assign({}, defs);
schemaWrapper.components = {};
schemaWrapper.components.schemas = Object.assign({}, defs);

@martijnpolak
Copy link

We have the same problem, making it unusable for us. Is there a previous version we could fall back to which doesn't have this issue?

@lagebaue
Copy link

I switched to a different generator tool chain: https://github.com/tobilg/api2html

@martijnpolak
Copy link

I switched to a different generator tool chain: https://github.com/tobilg/api2html

Nice thanks! We've opted for https://sourcey.com/spectacle for the time being, will have a look at that one too.

@den-ligin
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants