10000 fix(resolver): avoid accessing properties of undefined or null parameters by glowcloud · Pull Request #3927 · swagger-api/swagger-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(resolver): avoid accessing properties of undefined or null parameters #3927

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

Merged
merged 2 commits into from
May 20, 2025

Conversation

glowcloud
Copy link
Contributor
@glowcloud glowcloud commented May 19, 2025

This PR fixes acessing properties of empty parameters during normalization, e.g.:

openapi: 3.0.4
paths:
  /test:
    parameters:
      - 
    get:
      parameters:
        - 

@@ -85,10 +85,12 @@ export default function normalize(parsedSpec) {
for (const param of inherits[inheritName]) {
const exists = operation[inheritName].some(
(opParam) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The business logic checks out. Maybe a more safer alternative of the code?

              if (!Array.isArray(operation[inheritName])) {
                operation[inheritName] = inherits[inheritName];
              } else if (inheritName === 'parameters') {
                // eslint-disable-next-line no-restricted-syntax
                for (const param of inherits[inheritName]) {
                  const exists = operation[inheritName].some((opParam) => {
                    if (!isPlainObject(opParam) && !isPlainObject(param)) return false;
                    if (opParam === param) return true;

                    return ['name', '$ref', '$$ref'].some(
                      (key) =>
                        typeof opParam[key] === 'string' &&
                        typeof param[key] === 'string' &&
                        opParam[key] === param[key]
                    );
                  });

                  if (!exists) {
                    operation[inheritName].push(param);
                  }
                }
              }

Copy link
Member
@char0n char0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with suggestion

@glowcloud glowcloud merged commit dc04c99 into master May 20, 2025
8 checks passed
@glowcloud glowcloud deleted the fix-accessing-undefined-variables branch May 20, 2025 09:22
swagger-bot pushed a commit that referenced this pull request May 20, 2025
## [3.35.2](v3.35.1...v3.35.2) (2025-05-20)

### Bug Fixes

* **resolver:** avoid accessing properties of undefined or null parameters ([#3927](#3927)) ([dc04c99](dc04c99))
@swagger-bot
Copy link
Contributor

🎉 This PR is included in version 3.35.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0