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.

Don't output intermediate aliases

See original GitHub issue
export interface Parent {
  a: A;
}
export type A = RealA;

export type RealA = { realA: string };
./node_modules/.bin/ts-json-schema-generator \
    --path 'test.ts' \
    --type 'Parent' \
    --expose 'export' \
    --jsDoc 'extended'

outputs

{
  "$ref": "#/definitions/Parent",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "definitions": {
    "A": {
      "$ref": "#/definitions/RealA"
    },
    "Parent": {
      "additionalProperties": false,
      "properties": {
        "a": {
          "$ref": "#/definitions/A"
        }
      },
      "required": [
        "a"
      ],
      "type": "object"
    },
    "RealA": {
      "additionalProperties": false,
      "properties": {
        "realA": {
          "type": "string"
        }
      },
      "required": [
        "realA"
      ],
      "type": "object"
    }
  }
}

However, if RealA is not referred elsewhere, it’s better to output:

{
  "$ref": "#/definitions/Parent",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "definitions": {
    "A": {
      "additionalProperties": false,
      "properties": {
        "realA": {
          "type": "string"
        }
      },
      "required": [
        "realA"
      ],
      "type": "object"
    },
    "Parent": {
      "additionalProperties": false,
      "properties": {
        "a": {
          "$ref": "#/definitions/A"
        }
      },
      "required": [
        "a"
      ],
      "type": "object"
    }
    
  }
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
domoritzcommented, Mar 25, 2019

So the idea is to never output something of the form

"XXXX": {
 "$ref": "#/definitions/YYYY"
}

and replace all occurrences of XXXX with YYYY

1reaction
kanitwcommented, Mar 10, 2019

Note that this is quite important to make the schema legible. (It will reduce number of stacks in JSON schema validation error.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I create an alias where the arguments go in the middle?
The workaround is to pass the arguments that alias accepts only at the end to a wrapper that will insert them in the...
Read more >
[Solved] Alias don't output with TAB and LF ? | Linux.org
The problem with your alias is that your quotes are mis-matched. Your double quote after printf= is NOT acting as an opening quote...
Read more >
In Bash, when to alias, when to script, and when to write a ...
Aliases and functions are executed by the current shell, i.e. they run within and affect the shell's current environment.² No separate process ...
Read more >
One weird trick for powerful Git aliases - Work Life by Atlassian
Normal aliases can't have parameters. You can't execute multiple git commands in a single alias. You can't use | (pipes) or ...
Read more >
mastering-zsh/aliases.md at master - GitHub
A good place to start is to list all of your shell aliases with the alias command. When passed no parameters it will...
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