ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Ability to find out where the scheme came from
Hi, while using your library, came across a case. I specify expose: 'none' in the settings to get the generator to not share types between types. But because of that, if I forget to set export to the right type that we want to handle, the library can generate a scheme for a completely left-handed type. I want to be able to find out where the scheme came from and warn the me about the error.
Here's the line that caused us problems. https://github.com/vega/ts-json-schema-generator/blob/next/src/SchemaGenerator.ts#L163
When the library calls ts.getSourceFiles(), it gets a list of files, and at the end of that list is the file from which we started the parsing process. If among all these files are types with the same name, the original file would overwrite them with its own, and this most often worked. But if I forgot to specify export, then the original file did not overwrite the previous type with the same name and the schema generator returned the schema from another file.
Here's an example:
// layout.ts
export interface IPublicProps {
prop1: 'value'
}
// original-file.ts
import { IPublicProps as ILayoutPublicProps } from 'layout.ts'
interface IPublicProps { // Here we forgot to put export
layoutProp: ILayoutPublicProps
}
As a result, the condition here is triggered by IPublicProps from layout.ts and I get the wrong layout. So my only hope of solving this problem is to check where the schema came from and report the error if it didn't come from the expected place.