-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add null to enums when necessary, cleaner enums with string literals. F…
- Loading branch information
Showing
16 changed files
with
167 additions
and
67 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
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
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,27 @@ | ||
import { assert } from "chai"; | ||
import { makeNullable } from "../../src/TypeFormatter/AnnotatedTypeFormatter"; | ||
|
||
describe("makeNullable", () => { | ||
it("makes number nullable", () => { | ||
const n = makeNullable({type: "number"}); | ||
assert.deepEqual(n, { | ||
type: ["number", "null"], | ||
}); | ||
}); | ||
|
||
it("makes enum nullable", () => { | ||
const n = makeNullable({ | ||
enum: ["foo"], | ||
type: "string", | ||
}); | ||
assert.deepEqual(n, { | ||
enum: ["foo", null], | ||
type: ["string", "null"], | ||
}); | ||
}); | ||
|
||
it("makes anyOf nullable", () => { | ||
const n = makeNullable({anyOf: [{type: "number"}, {type: "string"}]}); | ||
assert.deepEqual(n, {anyOf: [{type: "number"}, {type: "string"}, {type: "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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class MyObject { | ||
export interface MyObject { | ||
foo: "ok" | "fail" | "abort"; | ||
bar: "ok" | "fail" | "abort" | string; | ||
} |
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 |
---|---|---|
@@ -1,21 +1,27 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "string", | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"bar": { | ||
"type": "string" | ||
}, | ||
"foo": { | ||
"enum": [ | ||
"abort", | ||
"fail", | ||
"ok" | ||
] | ||
}, | ||
"bar": { | ||
"ok", | ||
"fail", | ||
"abort" | ||
], | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"foo", | ||
"bar" | ||
], | ||
"$schema": "http://json-schema.org/draft-04/schema#" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"foo", | ||
"bar" | ||
], | ||
"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,5 @@ | ||
export interface MyObject { | ||
enum1: "a" | "b" | null; | ||
enum2: "a" | "b"; | ||
} | ||
|
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,34 @@ | ||
{ | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"enum1": { | ||
"enum": [ | ||
"a", | ||
"b", | ||
null | ||
], | ||
"type": [ | ||
"string", | ||
"null" | ||
] | ||
}, | ||
"enum2": { | ||
"enum": [ | ||
"a", | ||
"b" | ||
], | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"enum1", | ||
"enum2" | ||
], | ||
"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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
type result = "ok" | "fail" | "abort"; | ||
|
||
class MyObject { | ||
export interface MyObject { | ||
foo: result; | ||
bar: result | string; | ||
} |
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"$ref": "#/definitions/result" | ||
}, | ||
"bar": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"foo", | ||
"bar" | ||
], | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"result": { | ||
"type": "string", | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"bar": { | ||
"type": "string" | ||
}, | ||
"foo": { | ||
"enum": [ | ||
"abort", | ||
"fail", | ||
"ok" | ||
] | ||
} | ||
}, | ||
"$schema": "http://json-schema.org/draft-04/schema#" | ||
} | ||
"ok", | ||
"fail", | ||
"abort" | ||
], | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"foo", | ||
"bar" | ||
], | ||
"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