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

unhandledRejection: TypeError: Cannot read property 'push' of undefined #415

Closed
ex1st opened this issue Oct 26, 2020 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@ex1st
Copy link
Contributor

ex1st commented Oct 26, 2020

Describe the bug
Regression appears after #414

// request.schema.preprocessor.js

preprocessPathLevelParameters(pathItemKey, pathItem) {
        var _a, _b, _c;
        const parameters = (_a = pathItem.parameters) !== null && _a !== void 0 ? _a : [];
        if (parameters.length === 0)
            return;
        const v = pathItem[pathItemKey];
        if (v === parameters)
            return;
        const ref = (_b = v === null || v === void 0 ? void 0 : v.parmeters) === null || _b === void 0 ? void 0 : _b.$ref;
        const operationParameters = (ref ? (_c = this.ajv.getSchema(ref)) === null || _c === void 0 ? void 0 : _c.schema : v.parameters);
        for (const param of parameters) {
            operationParameters.push(param); // <-- this place
        }
    }

Actual behavior
Error throws if parameters property exists in path but doesn't exists in pathItem

Expected behavior
pathItem can be without parameters property

Examples and context

{
  "openapi": "3.0.0",
  "paths": {
    "/product/{productId}/prices": {
      "parameters": [{
        "in": "path",
        "name": "productId",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/DualID"
        }
      }],
      "patch": {
        "summary": "Update price values.",
        "tags": ["Price"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
              }
            }
          }
        }
      }
    }
  },
  "schemas": {
    "UniqID": {
      "type": "string",
      "pattern": "^([a-f0-9]){24}$",
      "description": "Hexadecimal unique identifier",
      "example": "5dee464910450609ca7ea2d7"
    },

    "InternalID": {
      "type": "string",
      "pattern": "^([A-Z0-9]){5,6}$",
      "description": "Short identifier that uniq for certain entity",
      "example": "XQ02F"
    },

    "DualID": {
      "oneOf": [{
          "$ref": "#/components/schemas/UniqID"
        },
        {
          "$ref": "#/components/schemas/InternalID"
        }
      ],
      "description": "Dual unique identifier, accepts long and short identifiers transparently"
    }
  }
}
@cdimascio cdimascio added the bug Something isn't working label Oct 26, 2020
@cdimascio
Copy link
Owner

cdimascio commented Oct 26, 2020

typo is fixed in v4.3.3. thanks @krizzje for the pr. though may not solve this one

@cdimascio cdimascio reopened this Oct 26, 2020
ex1st added a commit to ex1st/express-openapi-validator that referenced this issue Oct 26, 2020
ex1st added a commit to ex1st/express-openapi-validator that referenced this issue Oct 26, 2020
ex1st added a commit to ex1st/express-openapi-validator that referenced this issue Oct 26, 2020
cdimascio pushed a commit that referenced this issue Oct 26, 2020
Co-authored-by: Ilya Shatokhin <ilyas@pushok.com>
@cdimascio
Copy link
Owner

fixed and in v4.3.4. thanks @ex1st for the fix!

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