Hilzu / express-openapi-validate

Express middleware to validate requests based on an OpenAPI 3 document
Apache License 2.0
75 stars 12 forks source link

Doesn't support get parameters #41

Closed FallingSnow closed 5 years ago

FallingSnow commented 5 years ago

Request: GET /properties/5bd3d2ed73ffdf075808e70f

Ran console.debug(this._document, ["paths", path]) on dist/OpenApiValidator.js:171 and got:

paths:
   { '/': { get: [Object] },
     '/users': { post: [Object] },
     '/users/login': { post: [Object] },
     '/users/logout': { head: [Object] },
     '/properties': { post: [Object], patch: [Object] },
     '/properties/{id}': { get: [Object] },
     '/messages': { post: [Object] } },
  components:
   { securitySchemes: { BearerAuth: [Object] },
     schemas: { User: [Object], Message: [Object], Property: [Object] },
     responses: { BadRequest: [Object], InternalError: [Object] } } }

[ 'paths', '/properties/5bd3d2ed73ffdf075808e70f' ]

Stacktrace:

Error: Path=/properties/5bd3d2ed73ffdf075808e70f not found from OpenAPI document
    at OpenApiValidator._getPathItemObject ([redacted]/node_modules/express-openapi-validate/dist/OpenApiValidator.js:174:15)
    at OpenApiValidator.validate ([redacted]/node_modules/express-openapi-validate/dist/OpenApiValidator.js:76:37)
    at api.use.args ([redacted]/src/web.js:135:36)
    at Layer.handle [as handle_request] ([redacted]/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix ([redacted]/node_modules/express/lib/router/index.js:317:13)
    at [redacted]/node_modules/express/lib/router/index.js:284:7
    at Function.process_params ([redacted]/node_modules/express/lib/router/index.js:335:12)
    at next ([redacted]/node_modules/express/lib/router/index.js:275:10)
    at jsonParser ([redacted]/node_modules/body-parser/lib/types/json.js:109:7)
    at Layer.handle [as handle_request] ([redacted]/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix ([redacted]/node_modules/express/lib/router/index.js:317:13)
    at [redacted]/node_modules/express/lib/router/index.js:284:7
    at Function.process_params ([redacted]/node_modules/express/lib/router/index.js:335:12)
    at next ([redacted]/node_modules/express/lib/router/index.js:275:10)
    at multerMiddleware ([redacted]/node_modules/multer/lib/make-middleware.js:18:41)
    at Layer.handle [as handle_request] ([redacted]/node_modules/express/lib/router/layer.js:95:5)

From what it seems, this will never support any kind of get parameters. Does express-openapi-validate support some means of using get parameters or does this still need to be implemented?

Hilzu commented 5 years ago

Path parameters are supported. See for example the integration test app for how to use them: https://github.com/Hilzu/express-openapi-validate/blob/master/test/integration/app.ts#L43

FallingSnow commented 5 years ago

Your right, sorry about that. Thank you!