DZakh/rescript-json-schema

Possible bug with optional with default

Closed this issue · 2 comments

Darkle commented

Hi, with the following schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "page": {
      "type": "number",
      "minimum": 1,
      "default": 1
    },
    "limit": {
      "type": "number",
      "minimum": 1,
      "default": 100
    }
  },
  "additionalProperties": false
}

https://dzakh.github.io/rescript-json-schema/ outputs:

S.object(o =>
  {
    "page": o->S.field("page", S.option(S.float()->S.default(() => %raw(`1`)))),
    "limit": o->S.field("limit", S.option(S.float()->S.default(() => %raw(`100`)))),
  }
)->S.Object.strict

but I think it should instead be:

S.object(o =>
  {
    "page": o->S.field("page", S.option(S.float())->S.default(() => %raw(`1`))),
    "limit": o->S.field("limit", S.option(S.float())->S.default(() => %raw(`100`))),
  }
)->S.Object.strict

It seems to be putting the ->S.default inside the S.option() instead of after it.

DZakh commented

A good catch! This is an experimental feature that's going to be reworked and improved in the next major release. Let me know if you rely on it, so I do a hot fix. Otherwise, I'll postpone it a little bit.

DZakh commented

Fixed in the release https://github.com/DZakh/rescript-json-schema/releases/tag/v4.0.0. Thanks for reporting the issue.