valentinpalkovic/prisma-json-schema-generator

Json is represented as "type": "object"

capaj opened this issue ยท 8 comments

capaj commented

It should be generated as

{         
  "anyOf": [
        { "type": "object" },
        {
          "type": "array"
        }
      ]
}

it is generated as

{"type": "object"}

๐ŸŽ‰ This issue has been resolved in version 1.6.1 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

@capaj Thank you for reporting this! The Issue is resolved and should be fixed now :)

capaj commented

@valentinpalkovic oh thank you for being able to jump on this so fast.

I just wish I had realized sooner, that a valid JSON is also scalar values like string, null or a number, so the generated type here should really be:

 "type": ["number", "string", "boolean", "object", "array", "null"]

sorry for that. I mostly use graphql these days, so I forgot how to properly do any type in json schema.

@capaj No problem! :)

I just wanted to discuss with you, whether it makes sense to define the type without null for the case, that the JSON field is required!

Required case:

"type": ["number", "string", "boolean", "object", "array"]

Not required:

"type": ["number", "string", "boolean", "object", "array", "null"]

I know, that per definition the JSON type is allowed to also be null, but I would adjust this to conform to the user's expectation! If the user defines a JSON field as required, then null shouldn't be a valid value.

What do you think?

(See #305)

capaj commented

yes, I do think null is to be expected.
I mainly use postgre as my DB and postgre will happily accept null and indeed we do use nulls in our Json fields in our production DB. So the generated schema should accept it too.

Alright! I will adjust my MR tomorrow and I will release a new version afterwards! I will let you know.

๐ŸŽ‰ This issue has been resolved in version 1.6.2 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

capaj commented