Closed miller79 closed 12 months ago
@miller79
till none of the object1 or object2 has required fields and additionnalProperties set to false
object2string can match object1 definition as additionnal properties
if you want need this difference , you may either set in object1 the fiels object1string as required , and / or set additionnalProperties to false
that s kind be tricket as additionnalProperties set to false may impact the extensibility ( depending your definition of breaking change)
so to me it is not a bug
@LasneF I'm not sure if I quite understand what you are proposing. Are you saying because both of the oneOf objects don't have required fields and additionalProperties is set to true that it's matching both objects? If so, that makes sense. I was always supposing that even if you have a schema with no required properties that its still restricted but as you mentioned extensibility may be why it cannot do that.
yes that s it
and object like { "status" : "happy" } in fact surprisingly will match both schema object1 and object2 , this is why when doing validation of your sample it throw this error your objec1 & object2 schema does not have enough "restriction" . As oneOf is strict ; it MUST match ONE and only ONE schema , it fails if you want to have oneOf you need more restriction in your schema (like introducing some fields required , or additionnalProperties to false) in fact in a oneOf statement , the schema need to be "kind of" incompatible each others
Thanks for the info! Just played with it and see that it works when doing it that way and makes perfect sense to me now. I'll close this and thanks for the quick education.
It appears that the
oas3-valid-media-example
has some kind of issue withoneOf
that I haven't be able to identify. I've created an OpenAPI spec that exposes the issue below.When running this with spectral, it throws the following error:
This appears to be a bug and wanted to see if I could get another eye on it to make sure for one I'm missing something and also to see if its easily fixable.