diff --git a/package-lock.json b/package-lock.json index 3ea3068..c60762e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1926,8 +1926,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -1948,14 +1947,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1970,20 +1967,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -2100,8 +2094,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -2113,7 +2106,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2128,7 +2120,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2136,14 +2127,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2162,7 +2151,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2243,8 +2231,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -2256,7 +2243,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2342,8 +2328,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -2379,7 +2364,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2399,7 +2383,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2443,14 +2426,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/src/JSONSchema/JSONSchema.test.tsx b/src/JSONSchema/JSONSchema.test.tsx index 64f74f7..067ac57 100644 --- a/src/JSONSchema/JSONSchema.test.tsx +++ b/src/JSONSchema/JSONSchema.test.tsx @@ -16,3 +16,43 @@ it("renders empty with empty schema", () => { expect(div.innerHTML).toBe(""); ReactDOM.unmountComponentAtNode(div); }); + +it("renders oneOf schema", () => { + const div = document.createElement("div"); + const s = { + oneOf: [ + { + type: "string", + }, + { + type: "number", + }, + ], + } as JSONSchema4; + ReactDOM.render(, div); + expect(div.innerHTML.includes("string")).toBe(true); + expect(div.innerHTML.includes("number")).toBe(true); + ReactDOM.unmountComponentAtNode(div); +}); + +it("renders with a nested schema object", () => { + const div = document.createElement("div"); + const schema = { + properties: { + name: { + properties: { + foo: { + type: "string", + }, + }, + type: "object", + }, + }, + type: "object", + } as JSONSchema4; + ReactDOM.render(, div); + expect(div.innerHTML.includes("foo")).toBe(true); + expect(div.innerHTML.includes("string")).toBe(true); + expect(div.innerHTML.includes("object")).toBe(true); + ReactDOM.unmountComponentAtNode(div); +}); diff --git a/src/JSONSchema/JSONSchema.tsx b/src/JSONSchema/JSONSchema.tsx index 57a9109..9daafc1 100644 --- a/src/JSONSchema/JSONSchema.tsx +++ b/src/JSONSchema/JSONSchema.tsx @@ -14,15 +14,15 @@ class JSONSchema extends Component { const { schema } = this.props; if (!schema) { return null; } if (_.isEmpty(schema)) { return null; } - if (schema && schema.type && !schema.properties && schema.oneOf) { + if (schema && !schema.properties && schema.oneOf) { return ( <> {schema.oneOf && <> - One Of} + one of {schema.oneOf.map((item) => { return ( - + ); })} @@ -35,11 +35,11 @@ class JSONSchema extends Component { arrayWithItems = _.isArray(arrayWithItems) ? arrayWithItems : [arrayWithItems]; return ( <> - Array Of + array of {arrayWithItems.map((item: JSONSchema4) => { return ( - + ); })} diff --git a/src/JSONSchema/fields/JSONSchemaFields.test.tsx b/src/JSONSchema/fields/JSONSchemaFields.test.tsx index 80f8c5a..7dc093a 100644 --- a/src/JSONSchema/fields/JSONSchemaFields.test.tsx +++ b/src/JSONSchema/fields/JSONSchemaFields.test.tsx @@ -75,3 +75,25 @@ it("renders with a schema without required", () => { ReactDOM.unmountComponentAtNode(div); }); + +it("renders with a nested schema object", () => { + const div = document.createElement("div"); + const schema = { + properties: { + name: { + type: "object", + properties: { + foo: { + type: "string" + } + } + }, + }, + } as JSONSchema4; + ReactDOM.render(, div); + console.log('div', div.innerHTML); + expect(div.innerHTML.includes("foo")).toBe(true); + expect(div.innerHTML.includes("string")).toBe(true); + expect(div.innerHTML.includes("object")).toBe(true); + ReactDOM.unmountComponentAtNode(div); +}); \ No newline at end of file diff --git a/src/JSONSchema/fields/JSONSchemaFields.tsx b/src/JSONSchema/fields/JSONSchemaFields.tsx index 4a16aea..e7f4a80 100644 --- a/src/JSONSchema/fields/JSONSchemaFields.tsx +++ b/src/JSONSchema/fields/JSONSchemaFields.tsx @@ -41,6 +41,22 @@ class JSONSchemaFields extends Component { {schema.properties && _.map(schema.properties, (prop, name) => { + // support nested objects + if (prop.type === "object") { + return ( + + + {name} + + + object + + + + + + ); + } if (prop.oneOf) { return ( @@ -77,5 +93,6 @@ class JSONSchemaFields extends Component { ); } } +const WrappedJSONSchemaFields = withStyles(styles)(JSONSchemaFields); -export default withStyles(styles)(JSONSchemaFields); +export default WrappedJSONSchemaFields;