heswell wrote:
> Hi,
> I have a requirement for fairly complex json schema validation, and
> have implemented my own variant of json-schema. It is so close to the
> JSON-schema specification described here that it seems a shame not to
> simply adopt the 'standard' version. There are a couple of features
> that I use, one of which I think I'm right in saying isn't supported
> bu JSON-schema (please correct me if I'm wrong about this), the other
> I'm not sure about...
> I need to be able to specify that an array type may contain items that
> conform to any one of a list of declared types (similar to the way
> that the 'type' attribute may reference an array of types). Currently,
> declaring an array of types for the items attribute of an array type
> (confusing, but bear with me) is interpreted as a tuple-typing
> declaration. I find it hard to see the potential usage of 'tuple-
> typing' though I suppose others must have a use for it.
> Would it be possible to introduce an extra attribute on array type
> declarations, that tells the validator to interpret an aray of types
> in the 'items' attribute as alternative possible types, not tuple
> types ?
>
I think you are describing union typing, and that is indeed supported.
For example, you could indicate an array of items where each item can be
a string or an object with a name property:
{
type:"array",
items:{
type:[{type:"string"}, {type:"object", properties:{name:{}}]
}
}
> Secondly, I want to be able to use the inheritance mechanism to
> declare a property to be of type 'A', and have the validator allow any
> valid subtype of 'A' - ie polymorphism. From my experiments, I believe
> this doesn't work with JSON-schema, but I'm not 100% sure, has anyone
> else tried this? If it isn't currently possible, would people consider
> introducing such a possibility?
>
That certainly should work. If it doesn't, it would be a bug in the
validator.
Kris
I'm using the following simple example, pretty much as you posted earlier ...
var schema = {
type:"array",
items:{
type:[{type:"string"}, {type:"object", properties:{name:{type:"string"}}}]
}
};
but if I attempt to validate the following instance, which clearly
does not conform to that schema...
var instance = ["blah","vleh",{undeclared_property:23},34,[]]
The validator doesn't flag any errors.
I'm using the javascript validator for this
Is this a bug, or am I still misundestanding somethinhg?
steve