twskj / pretty-swag

Pretty UI for Swagger spec
MIT License
122 stars 20 forks source link

$ in model description causes exception, html will not load #46

Closed DavidBiesack closed 6 years ago

DavidBiesack commented 6 years ago

Run the command

pretty-swag -i openapi.yaml -o /tmp/openapi.html

on the below openapi.yaml ; when viewing in the browser (Chrome on Mac OS X), the JavaScript gets an exception

Uncaught SyntaxError: Invalid or unexpected token

and the document is not rendered.

It looks like something is truncated:

                     "schema": "{\n   \"value\": \"string\"     /* Strings which follow the regular expression pattern: `-?\\d{1,15}\\.\\d{1,9}<!DOCTYPE html>

Here is the openapi.yaml:

swagger: '2.0'
info:
  title: pretty-swag-bug
  description: parse error in schema/javascript
  version: '1'
  termsOfService: Pending.
consumes:
  - application/json
produces:
  - application/json
paths:
  /:
    get:
      responses:
        '200' : 
          description: OK
          schema:
            $ref: '#/definitions/model'
definitions:
  model:
    properties:
      value: 
        description: "Strings which follow the regular expression pattern:
          `-?\\d{1,15}\\.\\d{1,9}$`
          such as 325.50 or -200.75."
        type: string
twskj commented 6 years ago

Thanks for reporting I'll make a patch this evening.

twskj commented 6 years ago

rolled out the patch. Check it out and let me know.

DavidBiesack commented 6 years ago

thanks - works for this test case.

The problem still shows up when I try this on my full openapi.yaml (which I can't post here) but that may be my npm environment.

twskj commented 6 years ago

The earlier problem was about templating that I use. Can you shrink your schema again and see if the problem is still around $ sign?

DavidBiesack commented 6 years ago

The schema I reported here was taken from my larger openapi.yaml file. Your patch works in the small case, but fails the same way on the larger file (same problem - the description string gets clipped at the dollar sign backtick combination.) If I can carve off time, I'll try to successively trim the file down to something that still exhibits the problem

twskj commented 6 years ago

I am able to reproduce the bug. Thanks for reporting!

twskj commented 6 years ago

I rolled out another patch. It should address this problem for good. Let me know!

twskj commented 6 years ago

Have you had a chance to try?

DavidBiesack commented 6 years ago

Yes, the latest update resolves the problem in my full test case. Thanks for the patches.

twskj commented 6 years ago

Thanks for reporting back 👍