vega / ts-json-schema-generator

Generate JSON schema from your Typescript sources
MIT License
1.45k stars 193 forks source link

Definition Not Created When Properties Are Nullable #1419

Closed ThatOneAwkwardGuy closed 2 years ago

ThatOneAwkwardGuy commented 2 years ago

Hi, ran into an issue where if the properties of a schema are nullable, then the definition they refer to is not generated within the file.

e.g

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/CreateDivorceCaseAboutYouSurveyDTO",
  "definitions": {
    "residencyDocuments": {
      "type": ["array", "null"],
      "items": {
        "$ref": "#/definitions/SubDocument"
      }
    }
  }
}

Because the type for residencyDocuments contains null due to me using the @nullable decorator for the attribute, the definition for SubDocument is not generated.

I'd be happy to attempt a fix if someone could point me in the right direction, haven't made a change here before.

domoritz commented 2 years ago

Huh, interesting. I would recommend stepping through the parser and then formatter to see where the information is getting lost.