-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for regressed enum generation
- Loading branch information
Showing
4 changed files
with
197 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"enumMemberWithLiteral": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": "foo", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"enumMemberWithLiteralAndNull": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": "foo", | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"enumMembers": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": "beta", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"enumMembers", | ||
"enumMemberWithLiteral", | ||
"enumMemberWithLiteralAndNull" | ||
], | ||
"type": "object" | ||
} | ||
} | ||
} |
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,16 @@ | ||
enum Alphabet { | ||
Alpha = "alpha", | ||
Beta = "beta", | ||
Omega = 666, | ||
} | ||
|
||
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; | ||
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; // Smae as above, but with null | ||
}; |
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,124 @@ | ||
{ | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"enumMemberWithLiteral": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": "foo", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"enumMemberWithLiteralAndNull": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": "foo", | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"enumMembers": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": "beta", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"enumMembersWithNumber": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"const": 666, | ||
"type": "number" | ||
} | ||
] | ||
}, | ||
"wholeEnum": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnumWithLiteral": { | ||
"anyOf": [ | ||
{ | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
{ | ||
"const": "bar", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"wholeEnumWithLiteralAndNull": { | ||
"anyOf": [ | ||
{ | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
{ | ||
"const": "bar", | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"enumMembers", | ||
"enumMemberWithLiteral", | ||
"enumMemberWithLiteralAndNull", | ||
"enumMembersWithNumber", | ||
"wholeEnum", | ||
"wholeEnumWithLiteral", | ||
"wholeEnumWithLiteralAndNull" | ||
], | ||
"type": "object" | ||
} | ||
} | ||
} |