How to specify contentEncoding and contentMediaType keywords of JSON Schema #412
-
Hello I am stuck trying to implement a schema with typebox, that allow me to set an image as an input. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@jmartinacu Hi, For images, you will most likely want to use These are options available on const T = Type.String({ contentMediaType: 'image/png', contentEncoding: 'base64' }) Additional information on these options can be found at the link below https://json-schema.org/understanding-json-schema/reference/non_json_data.html#id1 As noted in this documentation, validators are not likely to validate for specific media types encoded in JSON, so you may need to manually validate the image data yourself. Additionally, you may also need to handle encoding and decoding the images to and from base64 (some infrastructure may handle this for you, although I can't think of any off hand). Just a few things to keep in mind. Hope this helps! |
Beta Was this translation helpful? Give feedback.
@jmartinacu Hi,
For images, you will most likely want to use
contentMediaType: 'image/png'
(or other mime type) andcontentEncoding: 'base64'
.These are options available on
Type.String()
Additional information on these options can be found at the link below
https://json-schema.org/understanding-json-schema/reference/non_json_data.html#id1
As noted in this documentation, validators are not likely to validate for specific media types encoded in JSON, so you may need to manually validate the image data yourself. Additionally, you may also need to handle encoding and decoding the images to and from base64 (so…