omissis/go-jsonschema

improvement: support format when the type is integer

luffyao opened this issue · 4 comments

Hi
I think we can support format when the type is integer.
In current version, we hard code the integer to "int" when the type is integer. but in fact. we have some others formats for integer, such as int8, uint8, int16 and so on.

such as following schema definition

           "attributeName": {
              "type": "integer",
              "format": "uint8",
              "default": "3"
            },

Are those standard formats in the JSON Schema RFC?

Hi
I think this is a valid definition. because the RFC described that it can support Custom format attributes. you can reference this http://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.7.

The spec also says:

Vocabularies do not support specifically declaring different value sets for keywords. Due to this limitation, and the historically uneven implementation of this keyword, it is RECOMMENDED to define additional keywords in a custom vocabulary rather than additional format attributes if interoperability is desired.

In this case, I think a custom field type is better. You can do this today with:

myField:
  type: integer
  goJSONSchema:
    type: uint8

Thanks for your reply, you are right, i saw it. but we are using the Draft-07 version, and used the above format that i said.
Anyway, if the spec is using the new way, then i will close this.