question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing '"nullable": true' in resulting jsonschema

See original GitHub issue

I am using https://www.graphql-code-generator.com/ to generate types from graphql schemas. I am generating json schemas from those types, but fields that are nullable does not come out as nullable.

test.ts:

export type Maybe<T> = T | null;

export type Scalars = {
    String: string;
};

export type CreateTransactionInput = {
    readonly brokerTradeId?: Maybe<Scalars["String"]>;
};
> npx typescript-json-schema --noExtraProps test.ts CreateTransactionInput
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "additionalProperties": false,
    "properties": {
        "brokerTradeId": {
            "type": "string"
        }
    },
    "type": "object"
}

In my mind, the result is missing below on property brokerTradeId

"nullable": true,

What am I doing wrong?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:5

github_iconTop GitHub Comments

8reactions
frontendphilcommented, May 7, 2021

Came here for exactly that.

Some more of my context. I’ve defined a type:

type A = string | null

I know that when I set --strictNullCheck I get a type: ['string', 'null'] in the resulting schema. However, the typescript support of ajv complains that this is not valid JSON schema syntax and that the property should rather have nullable: true set.

So, I have no idea who is right on this one 😄

1reaction
CloudPower97commented, Jul 17, 2021

I have the same exact problem as described by @frontendphil Did you manage to resolve this issue somehow?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ruby JSON Schema Validator Not Returning Expected Result
I am using the JSON schema validator gem to verify a response is coming back ... An expected True result would have the...
Read more >
Solved: Parse JSON - validation failed for null values - h...
I am attempting to parse the JSON, which mostly works... except when null values ... Then I created the JSON Schema by pasting...
Read more >
Notes about json schema handling in Spark SQL - Medium
The nullability of inferred fields will always be True even in case where the column has no null values. If you set the...
Read more >
Understanding JSON Schema
string: "This is a string". • boolean: true false. • null: ... Missing the required “email” property makes the JSON document invalid:.
Read more >
How to allow None (null) for fields in JSON Schema?
this is probably a little late but for consistency. I think you have a typo in your last schema. Instead of just `null`...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found