community icon indicating copy to clipboard operation
community copied to clipboard

Threads docs example fails due to exclusiveMaximum

Open jbowen93 opened this issue 3 years ago • 0 comments

The example docs for threads here gives the example schema:

const schema = {
  $schema: 'http://json-schema.org/draft-07/schema#',
  title: 'Person',
  type: 'object',
  properties: {
    _id: { type: 'string' },
    name: { type: 'string' },
    missions: {
      type: 'number',
      minimum: 0,
      exclusiveMaximum: 100,
    },
  },
}

This example returns the following error:

json: cannot unmarshal number into Go struct field Type.properties.exclusiveMaximum of type bool

because the json.Marshal(config.Schema) call here uses the CollectionConfig type here which uses https://github.com/alecthomas/jsonschema which has this schema type where both exclusiveMaximum and exclusiveMinimum are of type Bool, matching http://json-schema.org/draft-04/schema#.

There is an issue from January 2020 requesting draft-07 support here.

Modifying the Schema to:

...
missions: {
      type: 'number',
      minimum: 0,
      maximum: 100,
      exclusiveMaximum: true,
}

results in a different error:

Invalid type. Expected: number, given: exclusiveMaximum

removing exclusiveMaximum entirely works as expected.

The easiest fix is probably to remove any usage of exclusiveMaximum or exclusiveMinimum from the docs and perhaps adding a note that the JSON schema should match draft-04.

jbowen93 avatar Apr 16 '21 17:04 jbowen93