APIDevTools / swagger-parser

Swagger 2.0 and OpenAPI 3.0 parser/validator
https://apitools.dev/swagger-parser
MIT License
1.1k stars 155 forks source link

Error message has no line number or hint #116

Open AlexHolly opened 5 years ago

AlexHolly commented 5 years ago

Is there a way to show which key is wrong, in the following example line 2 "should not have additionalProperty: inf" or any line number would be good.

Tested with: https://apidevtools.org/swagger-parser/online/

API

openapi: 3.0.0
inf:
  description: Example Api
  version: 1.0.0
  title: Mini Example
servers:
  - url: 'https://petstore.swagger.io/v2'
paths: {}
[object Object] is not a valid Openapi API definition

Error: [object Object] is not a valid Openapi API definition
    at https://apidevtools.org/swagger-parser/online/js/bundle.js:1143:27

SyntaxError: [object Object] is not a valid Openapi API definition
    at Function.syntax (https://apidevtools.org/swagger-parser/dist/swagger-parser.min.js:25:95937)
    at https://apidevtools.org/swagger-parser/dist/swagger-parser.min.js:9:2484
AlexHolly commented 5 years ago

Removing these lines helps. https://github.com/APIDevTools/swagger-parser/blob/c77ae7dfa9d0b7fa0f118f32f705effdf9542592/lib/index.js#L64-L66 https://github.com/APIDevTools/swagger-parser/blob/c77ae7dfa9d0b7fa0f118f32f705effdf9542592/lib/index.js#L83-L85

Also need to add some checks for info schema.info && https://github.com/APIDevTools/swagger-parser/blob/c77ae7dfa9d0b7fa0f118f32f705effdf9542592/lib/index.js#L71 https://github.com/APIDevTools/swagger-parser/blob/c77ae7dfa9d0b7fa0f118f32f705effdf9542592/lib/index.js#L90