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(oas): account for deep $ref pointers when reducing an API def #926

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

erunion
Copy link
Member

@erunion erunion commented Jan 23, 2025

🚥 Resolves #925

🧰 Changes

This updates oas/reducer to account for deep $ref pointers like #/components/examples/event-min/value. Normally when we're running through components to remove we only look at #/components/examples/event-min, however when a schema like this is deeply referenced we won't pick up that it's used and end up removing event-min from the components block, resulting in a corrupted schema that will no longer validate.

@erunion erunion added the bug Something isn't working label Jan 23, 2025
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

smol comment below, potentially outside the scope of this PR

}
}

console.logx = (obj: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

lol wut

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 snuck in in a commit i made this morning where i added that skipped failing test. console.logx is a tool i use to dump full objects.

if (!$refs.has(`#/components/${componentType}/${component}`)) {
// If our `$ref` either is a full, or deep match, then we should preserve it.
const refIsUsed =
$refs.has(`#/components/${componentType}/${component}`) ||
Copy link
Member

Choose a reason for hiding this comment

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

(non-blocking) i feel like i've seen ref syntax that uses #components and not #/components — is that valid? should we account for that here?

Copy link
Member Author

Choose a reason for hiding this comment

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

i have also seen that before but it is not valid. our parser doesn't pick up on it now, but should at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

i had a note about this in one of my gitto PRs over the past two weeks but can't link those here.

@@ -39,6 +39,12 @@ function accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>,
}

getUsedRefs($refSchema).forEach(({ value: currRef }) => {
// Because it's possible to have a parameter named `$ref`, which our lookup would pick up as a
// false positive, we want to exclude that from `$ref` matching as it's not really a reference.
Copy link
Contributor

Choose a reason for hiding this comment

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

of course you can do that 🙃

Copy link
Member Author

Choose a reason for hiding this comment

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

we love it here, folks

@erunion erunion merged commit 84b7fe6 into main Jan 23, 2025
8 checks passed
@erunion erunion deleted the fix/reducer-deep-ref-matching branch January 23, 2025 22:13
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.

[oas/reducer] does not support deeply nested $refs
3 participants