fsprojects / FSharp.Data.JsonSchema

MIT License
49 stars 6 forks source link

DUs with decimals cause the 'Decimal' type to get redefined #18

Closed blakeSaucier closed 1 year ago

blakeSaucier commented 1 year ago

Hello,

Consider the following DU type:

type Promo =
    | Percent of decimal

type Pricing =
    | Nothing
    | Amount of decimal

type Price =
    { Pricing: Pricing
      Promo: Promo
      Total: decimal }

This will result in the following shema:

schema ```json { "properties": { "pricing": { "$ref": "#/definitions/Pricing" }, "promo": { "$ref": "#/definitions/Promo/definitions/Percent" }, "total": { "type": "number", "format": "decimal" } }, "definitions": { "Pricing": { "definitions": { "Nothing": { "type": "string", "default": "Nothing", "additionalProperties": false, "x-enumNames": [ "Nothing" ], "enum": [ "Nothing" ] }, "Amount": { "type": "object", "additionalProperties": false, "required": [ "kind", "item" ], "properties": { "kind": { "type": "string", "default": "Amount", "x-enumNames": [ "Amount" ], "enum": [ "Amount" ] }, "item": { "$ref": "#/definitions/Decimal" } } } }, "anyOf": [ { "$ref": "#/definitions/Pricing/definitions/Nothing" }, { "$ref": "#/definitions/Pricing/definitions/Amount" } ] }, "Decimal": { "title": "Decimal", "type": "number", "format": "decimal" }, "Promo": { "definitions": { "Percent": { "type": "object", "additionalProperties": false, "required": [ "kind", "item" ], "properties": { "kind": { "type": "string", "default": "Percent", "x-enumNames": [ "Percent" ], "enum": [ "Percent" ] }, "item": { "$ref": "#/definitions/Decimal2" } } } }, "anyOf": [ { "$ref": "#/definitions/Promo/definitions/Percent" } ] }, "Decimal2": { "title": "Decimal", "type": "number", "format": "decimal" } } } ```

Notice that Decimal and Decimal2 show up as definitions.

I think this is a rather small fix and can work on an pr.