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

UnhandledPromiseRejectionWarning: TypeError: Cannot create property 'parameters' on string 'Description' #440

Closed
sergebesson opened this issue Nov 5, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@sergebesson
Copy link

Describe the bug
expressOpenapiValidator.middleware generates an error UnhandledPromiseRejectionWarning

To Reproduce
Here is an example that systematically reproduces the bug from version 4.3.1 to version 4.4.0 of ʻexpress-openapi-validator`.
The bug does not occur in version 4.3.0

const expressOpenapiValidator = require("express-openapi-validator");
const apiSpec = {
  "openapi": "3.0.0",
  "info": { "title": "Api test", "version": "1.0.0" },
  "servers": [{ "url": "/api" }],
  "paths": {
    "/test/{id}": {
      "description": "Description",
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" }}],
      "get": {
        "responses": {
          "200": {
            "description": "response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "id": { "type": "string" }, "label": { "type": "string" }}
                }
              }
            }
          }
        }
      }
    }
  }
};

expressOpenapiValidator.middleware({
  apiSpec: apiSpec,
  validateRequests: true,
  validateResponses: true,
});

Here is the result when we run this small example with ʻexpress-openapi-validator` in version 4.4.0

node test.js 
(node:25275) UnhandledPromiseRejectionWarning: TypeError: Cannot create property 'parameters' on string 'Description'
    at RequestSchemaPreprocessor.preprocessPathLevelParameters (/DISKS/sdb1/serge-1604/tmp/test/node_modules/express-openapi-validator/dist/middlewares/parsers/request.schema.preprocessor.js:47:22)
    at paths.forEach (/DISKS/sdb1/serge-1604/tmp/test/node_modules/express-openapi-validator/dist/middlewares/parsers/request.schema.preprocessor.js:19:22)
    at Array.forEach (<anonymous>)
    at RequestSchemaPreprocessor.preProcess (/DISKS/sdb1/serge-1604/tmp/test/node_modules/express-openapi-validator/dist/middlewares/parsers/request.schema.preprocessor.js:12:15)
    at spec.then (/DISKS/sdb1/serge-1604/tmp/test/node_modules/express-openapi-validator/dist/openapi.validator.js:86:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
(node:25275) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25275) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

node version : v10.16.0

@cdimascio cdimascio added the bug Something isn't working label Nov 5, 2020
cdimascio added a commit that referenced this issue Nov 5, 2020
@cdimascio
Copy link
Owner

@sergebesson thanks for the issue. this is fixed in 4v.4.1

@sergebesson
Copy link
Author

Thanks for the fix :-)

ex1st pushed a commit to ex1st/express-openapi-validator that referenced this issue Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants