ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

feat: add Source FileName for DefinitionType, used by TopRefNodeParser and ExposeNodeParser.

Open charlzyx opened this issue 3 years ago • 3 comments

For this idea #1018

This is same PR with #1019 , but cause by my Incorrect operation, i have to resbumit this one. #1019 discuss at the bottom.

And here is custome DefinitionTypeFormatter example

import {
  BaseType,
  Definition,
  DefinitionType,
  SubTypeFormatter,
  TypeFormatter,
  uniqueArray,
} from 'ts-json-schema-generator';

export class DefinitionTypeFormatter implements SubTypeFormatter {
  public constructor(
    private childTypeFormatter: TypeFormatter,
    private encodeRefs: boolean,
  ) {}

  public supportsType(type: DefinitionType): boolean {
    return type instanceof DefinitionType;
  }
  public getDefinition(type: DefinitionType): Definition {
    // so that you can see the name here.
    console.log(type.sourceFileName);
    return {
      $ref: `#/definitions/${this.encodeRefs ? encodeURIComponent(type) : type}`,
    };
  }

}

github com_vega_ts-json-schema-generator_pull_1019_files

charlzyx avatar Dec 07 '21 06:12 charlzyx

Why a new pull request? You can push to the branch you made your other pull request from and it'll update.

domoritz avatar Dec 07 '21 13:12 domoritz

This is the same pull request now. Please dort force push next time since it makes it hard to review for me.

domoritz avatar Dec 07 '21 13:12 domoritz

making as draft since there are open comments

domoritz avatar Dec 09 '21 14:12 domoritz