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

Custom Vacuum rules that want resolved inputs not always resolved before running #441

Open
TristanSpeakEasy opened this issue Feb 2, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@TristanSpeakEasy
Copy link
Contributor

We have run into an issue in custom vacuum rules we write that if we set Resolved: true we expect the yaml we are walking through to be fully resolved (ie no $ref nodes).

And this does happen sometimes but is non-deterministic.

Ie somethings it seems the yaml is resolved before the rule is run other times it isn't.

@daveshanley
Copy link
Owner

How are you using vacuum in this use case? there are multiple code paths, based on if you're using by passing in a document, or raw bytes. A snippet of how you're applying the rules would be helpful.

@TristanSpeakEasy
Copy link
Contributor Author

We are passing in a document but will try and get a small reproducible together

@daveshanley
Copy link
Owner

There is also another mechanism used by the bundle command that will perform the same thing as resolving, but it uses a different technique to the resolver. There is a new feature in libopenapi that allows references to be resolved sequentially. Can you try setting the ExtractRefsSequemtially property to true and try again?

This invokes a different codepath and runs the index sequentially when extracting refs, vs async.

You can see it here: https://github.com/pb33f/libopenapi/blob/main/datamodel/document_config.go#L109

@TristanSpeakEasy
Copy link
Contributor Author

@daveshanley that does indeed seem to fix the issue, but is this just a work around for something that should be fixed elsewhere?

For example I would expect setting Resolved: true in a rule to ensure that I am always getting a resolved document into the rule? Should the rule wait to be executed until the document is fully resolved?

@TristanSpeakEasy
Copy link
Contributor Author

Also should I be setting ExtractRefsSequentially to true always? To make sure that for both validation and iterating through a document model that I am not going to start visiting something to early? Or is there some sort of channel etc I should be waiting on before the document is ready to traverse?

@daveshanley
Copy link
Owner

The cause of the issue of why sometimes async extraction of refs are fully resolved, and sometimes they are missing is currently unknown. It happens with super large, deeply nested specs. Which is why the sync option was made available to always ensure resolved nodes.

It's a bug honestly, so I'll keep this issue open until we figure it out.

@daveshanley daveshanley added bug Something isn't working and removed need more input labels Feb 5, 2024
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