everit-org / json-schema

JSON Schema validator for java, based on the org.json API
Apache License 2.0
864 stars 282 forks source link

Missing base64 validation #243

Open joeydh opened 5 years ago

joeydh commented 5 years ago

Dear Everit,

I am trying to put an image in data and validate it but the validations are not working and I think its missing.

When I look at the specification of draft-7(https://json-schema.org/draft-07/json-schema-validation.html) I see:

8.3. contentEncoding If the instance value is a string, this property defines that the string SHOULD be interpreted as binary data and decoded using the encoding named by this property. RFC 2045, Sec 6.1 [RFC2045] lists the possible values for this property.

The value of this property MUST be a string.

The value of this property SHOULD be ignored if the instance described is not a string.

8.4. contentMediaType The value of this property must be a media type, as defined by RFC 2046 [RFC2046]. This property defines the media type of instances which this schema defines.

The value of this property MUST be a string.

The value of this property SHOULD be ignored if the instance described is not a string.

If the "contentEncoding" property is not present, but the instance value is a string, then the value of this property SHOULD specify a text document type, and the character set SHOULD be the character set into which the JSON string value was decoded (for which the default is Unicode).

8.5. Example Here is an example schema, illustrating the use of "contentEncoding" and "contentMediaType":

{
    "type": "string",
    "contentEncoding": "base64",
    "contentMediaType": "image/png"
}

Instances described by this schema should be strings, and their values should be interpretable as base64-encoded PNG images.

Another example:

{
    "type": "string",
    "contentMediaType": "text/html"
}

Instances described by this schema should be strings containing HTML, using whatever character set the JSON string was decoded into (default is Unicode).

But If I put those validations in the JSONSchema nothing happens and it will just succeed, even if the base64 is not valid or not a base64 at all

sbaier1 commented 4 years ago

yeah the validation support for draft-07 is definitely not complete here still.

GracjanC commented 4 years ago

@erosb Hi! Any progress on this issue? Is there a possibility of fixing this in any of the future releases?

erosb commented 4 years ago

I'm happy to merge if someone implements it, but I don't plan to add this feature. Other implementations don't have much support for contentMediaType-based validation either.

GracjanC commented 4 years ago

Thanks for the quick reply. I'll try to dive into the project and see if I'm capable of implementing such feature.