twskj / pretty-swag

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

Updating from 0.1.149 to 0.1.150 throws a TypeError when attempting to generate html #55

Closed bteng22 closed 6 years ago

bteng22 commented 6 years ago

Generating the HTML documentation works fine on 0.1.149 but when updating to 0.1.150 pretty-swag throws a TypeError as shown below:

> pretty-swag -m -i docs/api.json -o docs/api.html

Source: docs/papi-openapi.json
Dest: docs/papi-api.html
Format:  singleFile
MarkDown:  Enable
Nav Bar:  Normal
Auto tags:  Enable
Initial Collapse [Path: false, Method: false, Tool :true]
Theme: blue
Error: TypeError: Cannot convert undefined or null to object
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! papi@1.4.0 docs:gen-html: `pretty-swag -m -i docs/api.json -o docs/api.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the papi@1.4.0 docs:gen-html script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
twskj commented 6 years ago

Thanks for reporting. Do you have an input file I can use to reproduce this?

kumardevendra26 commented 6 years ago

Hi @bteng22 You can find the similar issue in https://github.com/syroegkin/swagger-markdown/issues/64 It has a good solution which is given by @adrienjoly. Pretty-swag expects a definitions object in root path. Just add below object in swagger json. "definitions": { "Streams": { "type": "object", "allOf": [ { "properties": {} } ] } } In place of 'Streams' you can add your own key. It will solve your issue.. Thanks

twskj commented 6 years ago

@kumardevendra26 thanks for a workaround. @bteng22 let us know if this fixes your issue.

kumardevendra26 commented 6 years ago

Yes, I resolved the same issue which I was facing today. After doing lots of circus I find above solution. Please provide your sample json file, if you are still facing the same. I will try to help you as early. Cheers,

twskj commented 6 years ago

Finally got time to look at this. Rolled out a patch on 0.1.154 Feel free to reopen if you still experience the problem

bteng22 commented 6 years ago

Sorry for the delayed response on this but @kumardevendra26 workaround worked for us. Thanks for all the help folks 👍

ghost commented 5 years ago

Hi @bteng22, I am also getting same error while running this command in cli. Version: pretty-swag version "0.1.154" Command: pretty-swag -i openapi.json -o output.html Error: Source: openapi.json Dest: output.html Format: singleFile MarkDown: Disable Nav Bar: Normal Auto tags: Enable Initial Collapse [Path: false, Method: false, Tool :true] Theme: blue Error: TypeError: Cannot convert undefined or null to object

Attaching the JSON below:

{ "openapi" : "3.0.0", "info" : { "title" : "Sun Exp Restful API", "description" : "Sun expo API", "version" : "1.0.0-oas3" }, "servers" : [ { "url" : "https://virtserver.swaggerhub.com/mrinalbarua/bearer-test/1.0.0-oas3", "description" : "SwaggerHub API Auto Mocking" }, { "url" : "https://virtserver.swaggerhub.com/tinto88/sun-expo-api/1.0.0" } ], "security" : [ { "bearerAuth" : [] } ], "paths" : { "/get-course-catalog" : { "get" : { "tags" : [ "Product Catalog" ], "summary" : "Product Catalog", "operationId" : "productList", "responses" : { "200" : { "description" : "Success", "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/inline_response_200" } } } }, "204" : { "description" : "Success", "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/inline_response_204" } } } }, "400" : { "description" : "Failed", "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/inline_response_400" } } } }, "401" : { "description" : "Failed", "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/inline_response_401" } } } }, "500" : { "description" : "Failed", "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/inline_response_500" } } } } } } } }, "components" : { "schemas" : { "enquiryitems" : { "required" : [ "category", "course_id", "course_name", "course_type", "course_url", "description", "duration", "image_url", "intro_url", "keywords", "price" ], "type" : "object", "properties" : { "category" : { "type" : "string", "format" : "uuid" }, "course_id" : { "type" : "string", "example" : "1748" }, "course_name" : { "type" : "string", "format" : "int32", "example" : "PMI-PgMP" }, "description" : { "type" : "string", "format" : "int32", "example" : "Program Management Professional (PgMP)® is a credential that is offered by the Project Management Institute (PMI) to individuals who successfully qualify the PgMP® exam." }, "course_type" : { "type" : "string", "format" : "int32", "example" : "OSL" }, "duration" : { "type" : "string", "format" : "int32", "example" : "30 seconds" }, "image_url" : { "type" : "string", "format" : "int32", "example" : "https://www.domain.com/banners/course_page_banners/1280x160/1_Project_management/yellow_1.svgz" }, "course_url" : { "type" : "string", "format" : "int32" }, "intro_url" : { "type" : "string", "format" : "int32", "example" : "http://cfs3.cdn.net/sample_course_videos/Project_Management/PgMP/Lesson_01_Overview_of_PMI_PgMP_Certification_Course.mp4" }, "price" : { "type" : "string", "format" : "int32" }, "keywords" : { "type" : "string", "format" : "int32", "example" : "PGMP, Certification, training, Online, Course" } } }, "inline_response_200" : { "type" : "object", "properties" : { "code" : { "type" : "integer", "format" : "int32", "example" : 200 }, "message" : { "type" : "string", "example" : "OK" }, "data" : { "type" : "array", "items" : { "$ref" : "#/components/schemas/enquiryitems" } } } }, "inline_response_400" : { "type" : "object", "properties" : { "code" : { "type" : "integer", "format" : "int32", "example" : 400 }, "message" : { "type" : "string", "example" : "Bad request" } } }, "inline_response_401" : { "type" : "object", "properties" : { "code" : { "type" : "integer", "format" : "int32", "example" : 401 }, "message" : { "type" : "string", "example" : "Unauthorized" } } }, "inline_response_500" : { "type" : "object", "properties" : { "code" : { "type" : "integer", "format" : "int32", "example" : 500 }, "message" : { "type" : "string", "example" : "Internal Server Error" } } }, "inline_response_204" : { "type" : "object", "properties" : { "code" : { "type" : "integer", "format" : "int32", "example" : 204 }, "message" : { "type" : "string", "example" : "No content" } } } }, "securitySchemes" : { "bearerAuth" : { "type" : "http", "scheme" : "bearer", "bearerFormat" : "JWT" } } } }

Can you please help here.

Thanks in advance.

twskj commented 5 years ago

I'll look into this shortly

twskj commented 5 years ago

@mrianl Your schema is V3 which I don't have a code for it yet :-) Your option is to convert your schema to V2. Any further help please feel free to open a new issue.