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

fix(reducer): make sure $refs are actual pointers #753

Merged
merged 1 commit into from
Apr 19, 2023
Merged

Conversation

kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Apr 18, 2023

🧰 Changes

@andrew-rdme was seeing the following error when attempting to reduce a file:

$ref.substring is not a function

which is coming from this line:

const $refSchema = jsonPointer.get(schema, $ref.substring(1));

This is happening because of an edge case where a spec file might have an object definition with a property called $ref. In other words, say the object were to look something like this:

{
  "hello": "world",
  "$ref": "example"
}

then its schema definition would look something like:

{
  "type": "object",
  "properties": {
    "hello": {
      "type": "string",
      "description": "A property called `hello`"
    },
    "$ref": {
      "type": "string",
      "description": "A property called $ref to see what happens"
    }
  }
}

The reducer was looking blindly for $ref keys and assuming their values are always strings. This tweaks the logic ever-so-slightly to ensure that the value of the $ref is indeed a string before we attempt to load its $ref.

🧬 QA & Testing

Added a fixture and a test to confirm that the fix works as expected.

@kanadgupta kanadgupta added the bug Something isn't working label Apr 18, 2023
Comment on lines +853 to +856
"$ref": {
"type": "string",
"description": "A property called $ref to see what happens"
},
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is mostly just petstore, this is the only chunk that I added.

@kanadgupta kanadgupta requested a review from erunion April 18, 2023 23:24
@kanadgupta kanadgupta marked this pull request as ready for review April 18, 2023 23:24
Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

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

Ill tag a release tomorrow

@erunion erunion merged commit 4cfc237 into main Apr 19, 2023
@erunion erunion deleted the ref-fixes branch April 19, 2023 04:16
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

Successfully merging this pull request may close these issues.

2 participants