ts-json-schema-generator
ts-json-schema-generator copied to clipboard
feat: add Source FileName for DefinitionType, used by TopRefNodeParser and ExposeNodeParser.
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}`,
};
}
}

Why a new pull request? You can push to the branch you made your other pull request from and it'll update.
This is the same pull request now. Please dort force push next time since it makes it hard to review for me.
making as draft since there are open comments