Open vanntile opened 6 days ago
Hmm... this is a bug, the schema should bundled inline so there is no ref.
Actually. This is not a bug. Well kinda. but not..
#/components/schemas/Error
is a circular reference.
It cannot be rendered, so when it's passed to the validator, it remains as is..
{
"properties" : {
"code" : {
"type" : "string"
},
"details" : {
"items" : {
"$ref" : "#/components/schemas/Error"
},
"type" : "array"
}
},
"type" : "object"
}
This is what the validator gets. which is why it's failing.
The fix here is to either fail gracefully, warning of the circular reference.. or, determine it's a circular reference and then extract those circular references and add them to the schema validator one by one as resources, but this is a huge amount of work.
How come? It's at least missing proper validation. As any non-stdlib library, I don't think it should panic, at least
Sorry, pressed return too quickly.
The fix here is to either fail gracefully, warning of the circular reference.. or, determine it's a circular reference and then extract those circular references and add them to the schema validator one by one as resources, but this is a huge amount of work.
If you consider it non-critical, I could try to do that work myself. The original problem has been sidestepped in production, so I could just try to improve this for its own sake. PR allowed?
When you parse the document, it will warn you there are circular references
model, errs := document.BuildV3Model()
circ := model.Index.GetCircularReferences()
It will show you something like this:
If you consider it non-critical, I could try to do that work myself. The original problem has been sidestepped in production, so I could just try to improve this for its own sake. PR allowed?
All PRs are most welcome. I only have some many hours in the week to work on new stuff or upgrade existing stuff - so your contribution would be most welcome.
I consistently get a panic in a production use case. Here is a minimal reproduction:
This results in:
Considering that this library does not consider (non-required) circular references errors, and both building a model and validating it pass, I am wondering if this is just a bug or I am missing something.
Tracking down the error, I got to
https://github.com/pb33f/libopenapi-validator/blob/7b4e021e253dae5c215da2c29b5d2862190df7b0/responses/validate_response.go#L131-L132
Some error validation would be useful, don't know at the moment how to solve