libopenapi-validator icon indicating copy to clipboard operation
libopenapi-validator copied to clipboard

Can't have my model and eat it too :)

Open SJrX opened this issue 1 year ago • 1 comments

If you call NewValidator() the resulting validator has the v.document field set. However if I want you call NewValidatorFromV3Model() it doesn't. Without this being set you get a panic when you call ValidateDocument(). I eventually dug into the code, and I found that the v3 Model is cached in the document, so just did that.

It's possible that I'm just missing something obvious with Go, but due to the private access, you can't actually repair the invariant if you try and build it from the model, because the document field is private (as is the type).

SJrX avatar Jun 27 '24 20:06 SJrX

There may be a gap in the API here, I will look into this.

daveshanley avatar Aug 02 '24 11:08 daveshanley

There is a a new SetDocument method (https://github.com/pb33f/libopenapi-validator/blob/main/validator.go#L66)

And the panic is now caught correctly.

daveshanley avatar May 22 '25 02:05 daveshanley