textileio / community

Textile community repo. Includes a sub-project for documentation 📚 and a discussion board for ideas & questions.
https://docs.textile.io/
MIT License
101 stars 44 forks source link

Threads docs example fails due to exclusiveMaximum #282

Open jbowen93 opened 3 years ago

jbowen93 commented 3 years ago

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.