valentinpalkovic / prisma-json-schema-generator

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

Non-primitive types not required #1511

Open ShaunSHamilton opened 1 month ago

ShaunSHamilton commented 1 month ago

This appears to be a bug, but if not, then a work around be be appreciated:

https://github.com/valentinpalkovic/prisma-json-schema-generator/blob/d2d6fba55bbe1caff0979be27e39a6ed5506452d/src/tests/generator.test.ts#L28

https://github.com/valentinpalkovic/prisma-json-schema-generator/blob/d2d6fba55bbe1caff0979be27e39a6ed5506452d/src/tests/generator.test.ts#L592-L595

https://github.com/valentinpalkovic/prisma-json-schema-generator/blob/d2d6fba55bbe1caff0979be27e39a6ed5506452d/src/tests/generator.test.ts#L619-L620

Surely Posts should be a required field?

In my case, I have the following type:

/// An exam as designed by the examiners
model A {
  config             Config
}
{
  "definitions": {
    "A": {
      "type": "object",
      "properties": {
        "config": {
          "$ref": "#/definitions/B"
        }
      },
      "required": []
    },
    "B": {
      "type": "object",
      "properties": {
        "tags": {
          "type": "array",
          "originalType": "TagConfig",
          "items": {
            "$ref": "#/definitions/TagConfig"
          }
        },
        "total_time": {
          "type": "integer",
          "originalType": "Int",
        },
        "question_types": {
          "type": "array",
          "originalType": "QuestionConfig",
          "items": {
            "$ref": "#/definitions/QuestionConfig"
          }
        }
      },
      "required": [
        "total_time"
      ]
    }
  }
}

Same goes for TagConfig and QuestionConfig - they are required, but do not get treated as such.

I am happy to contribute a fix, if this is unintentional

valentinpalkovic commented 2 weeks ago

More or less a duplicate of https://github.com/valentinpalkovic/prisma-json-schema-generator/issues/13

ShaunSHamilton commented 2 weeks ago

@valentinpalkovic Thank you. The added context does help. Here is what I am not understanding still:

As in the tests example mentioned above, why is the posts field "optional", but keywords and biography required? They have the same annotations (none).