-
Notifications
You must be signed in to change notification settings - Fork 202
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
fix: Go back to generating enums out of unions containing enums #2149
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e6723ff
Add test case for regressed enum generation
Twixes ff834ed
Run LiteralUnionTypeFormatter on unions including enum members
Twixes 09a9abb
Delete leftover schema.json
Twixes 5b71f3d
Add extra test cases
Twixes 680f2dc
Improve clarity of code branches
Twixes a84c527
Update src/TypeFormatter/LiteralUnionTypeFormatter.ts
arthurfiorette 38f7f3d
Update src/TypeFormatter/LiteralUnionTypeFormatter.ts
arthurfiorette eb67a52
fix: linting issues
arthurfiorette b88a151
fix: remove inplicit statement
arthurfiorette 6ae6379
feat: added exported test cases
arthurfiorette 351e144
refactor: sets and for loop
arthurfiorette 0d6d625
Merge remote-tracking branch 'origin/next' into enums-string-union
arthurfiorette 18fe097
style: lint
arthurfiorette 4365483
refactor: separate methods
arthurfiorette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
enum Alphabet { | ||
Alpha = "alpha", | ||
Beta = "beta", | ||
Omega = 666, | ||
} | ||
|
||
enum FileAccess { | ||
None, | ||
Read = 1 << 1, | ||
Write = 1 << 2, | ||
ReadWrite = Read | Write, | ||
} | ||
|
||
export type MyObject = { | ||
// All the members above should be output as enums, not anyOf | ||
enumMembers: Alphabet.Alpha | Alphabet.Beta; | ||
enumMemberWithLiteral: Alphabet.Alpha | "foo"; | ||
enumMemberWithLiteralAndNull: Alphabet.Alpha | "foo" | null; | ||
enumMemberWithInterface: Alphabet.Alpha | { abc: string }; | ||
enumMembersWithNumber: Alphabet.Alpha | Alphabet.Omega; | ||
wholeEnum: Alphabet; // Should output just all of Alphabet | ||
wholeEnumWithLiteral: Alphabet | "bar"; // Should output all of Alphabet members (2 strings, 1 number) and "bar" | ||
wholeEnumWithLiteralAndNull: Alphabet | "bar" | null; | ||
arthurfiorette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
twoDifferentEnumMembers: Alphabet.Alpha | FileAccess.Read; | ||
twoDifferentWholeEnums: Alphabet | FileAccess; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"enumMemberWithInterface": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"additionalProperties": false, | ||
"properties": { | ||
"abc": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"abc" | ||
], | ||
"type": "object" | ||
} | ||
] | ||
}, | ||
"enumMemberWithLiteral": { | ||
"enum": [ | ||
"alpha", | ||
"foo" | ||
], | ||
"type": "string" | ||
}, | ||
"enumMemberWithLiteralAndNull": { | ||
"enum": [ | ||
"alpha", | ||
"foo", | ||
null | ||
], | ||
"type": [ | ||
"string", | ||
"null" | ||
] | ||
}, | ||
"enumMembers": { | ||
"enum": [ | ||
"alpha", | ||
"beta" | ||
], | ||
"type": "string" | ||
}, | ||
"enumMembersWithNumber": { | ||
"enum": [ | ||
"alpha", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"twoDifferentEnumMembers": { | ||
"enum": [ | ||
"alpha", | ||
2 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"twoDifferentWholeEnums": { | ||
"enum": [ | ||
arthurfiorette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"alpha", | ||
"beta", | ||
666, | ||
0, | ||
2, | ||
4, | ||
6 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnum": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnumWithLiteral": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666, | ||
"bar" | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnumWithLiteralAndNull": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666, | ||
"bar", | ||
null | ||
], | ||
"type": [ | ||
"string", | ||
"number", | ||
"null" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"enumMembers", | ||
"enumMemberWithLiteral", | ||
"enumMemberWithLiteralAndNull", | ||
"enumMemberWithInterface", | ||
"enumMembersWithNumber", | ||
"wholeEnum", | ||
"wholeEnumWithLiteral", | ||
"wholeEnumWithLiteralAndNull", | ||
"twoDifferentEnumMembers", | ||
"twoDifferentWholeEnums" | ||
], | ||
"type": "object" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can probably become map again if we fix the thing below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it for us since i also need this PR :)
351e144