Skip to content

Commit 3f68c8e

Browse files
straxdomoritz
authored andcommitted
Add support for object type (YousefED#153)
* Add support for `object` type * Apply changes to master
1 parent bb7c2e4 commit 3f68c8e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

test/programs/type-primitives/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ class MyObject {
2020

2121
object1: any = null;
2222
object2: {} = null;
23+
object3: object = null;
2324

2425
}

test/programs/type-primitives/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
},
4040
"type": "object"
4141
},
42+
"object3": {
43+
"default": null,
44+
"properties": {
45+
},
46+
"additionalProperties": true,
47+
"type": "object"
48+
},
4249
"string1": {
4350
"default": "defaultValue",
4451
"type": "string"
@@ -53,6 +60,7 @@
5360
"number1",
5461
"object1",
5562
"object2",
63+
"object3",
5664
"string1"
5765
],
5866
"type": "object"

typescript-json-schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ export class JsonSchemaGenerator {
379379
} else if (propertyTypeString === "Date") {
380380
definition.type = "string";
381381
definition.format = "date-time";
382+
} else if (propertyTypeString === "object") {
383+
definition.type = "object";
384+
definition.properties = {};
385+
definition.additionalProperties = true;
382386
} else {
383387
const value = extractLiteralValue(propertyType);
384388
if (value !== undefined) {

0 commit comments

Comments
 (0)