valentinpalkovic / prisma-json-schema-generator

A generator for Prisma 2 to generate a valid JSON Schema (v7)
MIT License
276 stars 31 forks source link

Optional enum fields do not correctly allow null values #1453

Open stevenvergenz opened 4 months ago

stevenvergenz commented 4 months ago
enum MyEnum{
  A
  B
  C
  D
}
model MyModel {
  enumValue MyEnum?
}

This becomes:

"enumValue": {
  "type": [
      "string",
      "null"
  ],
  "enum": [
      "A",
      "B",
      "C",
      "D"
  ]
}

The type allows a null value, but the enum does not, so { "enumValue": null } does not validate. The correct solution is to include null in the list of enum values here.

hongkongkiwi commented 4 months ago

Seems like a solid fix! @valentinpalkovic ?