Defining a `format` registry

Common jsonschema tends to use format registries that goes beyond date and date-time.
Can we extend the format registry used by jsonforms.io with some other entries like int32 int64? This is essential for reusing existing schemas.

[original thread by Roberto Polli]

Hi @ioggstream, int32 and int64 are custom formats as they are not part of the JSON Schema specification. To support them you don’t need to do any changes to JSON Forms itself. Just model them as type: ‘integer’ and you’ll get a number input for them. To support proper validation you can create your own Ajv instance (instead of relying on the default one from JSON Forms) and add the int32 and int64 formats to it. So the code would look something like this:

const schema = {
  // [..]
  myint: {
    type: 'integer',
    format: 'int32'
  }
};
// [...]
const myAjv = createAjv(); // import { createAjv } from @jsonforms/core
myAjv.addFormat('int32', {
  type: 'number',
  validate: (int) => {
    return int >= -2147483648 && int <= 2147483647;
  },
});
// [...] somewhere in render()
<JsonForms
  schema={schema}
  uischema={uischema}
  // etc.
  ajv={myAjv}
/>

[Roberto Polli]

I’ll take a look, thanks!