-
Notifications
You must be signed in to change notification settings - Fork 325
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
New TJS.PartialArgs setting sortEnums #574
Comments
Hmm, I would be okay with even removing the sort. It may be there for de-duplication so we need to be careful. The tricky thing is that sometimes the enum may be the result of multiple types being combined. We definitely don't want different orders when files are moved around for example. |
How could the sorting enable deduplication? If I use the same key in an enum it is invalid typescript and if I use the same value, I get the duplicated value in the resulting JSON schema. And can you share or describe the scenario you are thinking of and I can try testing it to see how the lib behaves currently? |
I don't recall how we store the enum set. If we store it as a sorted list, the deduplication code would be different than for an unsorted list. I'm thinking of having something where a type is the combination of two other types which are enums. |
Is this how you would combine two enums? I get a runtime error TypeError: Unsupported type: never
|
Something like that. See https://stackoverflow.com/questions/48478361/how-to-merge-two-enums-in-typescript |
thanks, got that working now, appreciate your patience here.
Produces this schema:
But I'm still struggling to reproduce any deduplication, the two enums appear as different objects within an |
I probably misremembered then. I also work on https://github.com/vega/ts-json-schema-generator so maybe that was there. In either way, let's try to remove the sort. Can you send a pull request? |
here is the PR: #576 |
I have a use case where I need the order of enums defined in a type to be preserved in the resulting JSON schema.
I was wondering if you would be open to a new property in
TJS.PartialArgs
calledsortEnums
. This would default to true to ensure backwards compatibility and setting it to false would bypass the sorting done here:https://github.com/YousefED/typescript-json-schema/blob/655d7741a6e0514855b36f94cc1a517d23159f19/typescript-json-schema.ts#L929C28-L929C28
The text was updated successfully, but these errors were encountered: