-
Notifications
You must be signed in to change notification settings - Fork 406
Schema $ref to standalone type results in generation of type in generated typescript interface. #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @AndyDBell! You can avoid declaring externally referenced types by setting the Let me know if that works for your use case! |
Hi Boris, Thanks for your response. I have tried setting declareExternallyReferenced to false in the compileFromFile options but the output did not change! This is my options object: const options: any = {
cwd: './src/models/jsonschema',
declareExternallyReferenced: false,
unreachableDefinitions: false,
style: {
semi: false,
singleQuote: true,
}
} The generated typescript is the same as with declareExternallyReferenced set to true. |
Hmm could you upload a self-contained repro case? This does seem like a bug. In the meantime, generating multiple copies of a type should be fine - TypeScript will merge them for you as best it can. |
Zipped self contained repro code shared on onedrive at https://1drv.ms/u/s!ArpiIInQBexRhZY9b-gSPf3z1QxXTQ. |
Thanks for the repro case @AndyDBell. What's happening here is that I maintain this project in my spare time, and won't have time to fix this soon. Sorry about the inconvenience. Also, contributions are welcome! In the meantime, you have 3 options for workarounds: (1) remove the type alias from your JSON-Schema, (2) manually edit the outputted file, or (3) combine your schemas into one. |
Hi Boris,
Understood. I thought that the problem was as you described and tried to trace through your code to find a solution but it got a bit complex.
Thanks for creating this project in your spare time. We are flat out on our own project but, if I find a spare moment, I will try to look further into this problem for you.
We intend to use our json schema to generate mongoose schema, swagger definitions etc so we have written a pre-processor to replace references to simple types with the type prior to passing to your code.
Once again, thanks for creating this useful package.
Andy
From: Boris Cherny [mailto:[email protected]]
Sent: Wednesday, 17 January 2018 7:35 PM
To: bcherny/json-schema-to-typescript <[email protected]>
Cc: Andrew Bell <[email protected]>; Mention <[email protected]>
Subject: Re: [bcherny/json-schema-to-typescript] Schema $ref to standalone type results in generation of type in generated typescript interface. (#141)
Thanks for the repro case @AndyDBell <https://github.com/andydbell> .
What's happening here is that declareExternallyReferenced isn't working as expected for primitive types (as opposed to interfaces).
I maintain this project in my spare time, and won't have time to fix this soon. Sorry about the inconvenience. Also, contributions are welcome!
In the meantime, you have 3 options for workarounds: (1) remove the type alias from your JSON-Schema, (2) manually edit the outputted file, or (3) combine your schemas into one.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#141 (comment)> , or mute the thread <https://github.com/notifications/unsubscribe-auth/ACq49DgIPGHl706BrirBxNoYFl03G8RUks5tLZR6gaJpZM4Rgt5S> .
|
@AndyDBell A workaround I'm currently using is to use the the |
I fixed this problem in my repo with this code: (its not ready solution but work for me) read json:
and filtred existing interfaces
|
|
Merging into #258 |
I am not sure whether this is a configuration problem, expected behaviour or a bug but...
I declare a json schema file id.schema.json containing:
Running json-schema-to-typescript.compileFromFile( id.schema.json ) generates:
I create a second json schema file example.schema.json referencing id.schema.json and containing:
Running json-schema-to-typescript.compileFromFile( example.schema.json ) generates:
Here the type TId is generated in addition to the interface IExample. i.e. TId is defined twice, once in each file.
This makes it impossible to use the generated code in a typescript program with out manual editing to remove the second definition of TId.
The text was updated successfully, but these errors were encountered: