diff --git a/src/utils.js b/src/utils.js index 22f08e1863..cf9600d5f4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -76,6 +76,10 @@ export function getSchemaType(schema) { return "string"; } + if (!type && (schema.properties || schema.additionalProperties)) { + return "object"; + } + if (type instanceof Array && type.length === 2 && type.includes("null")) { return type.find(type => type !== "null"); } diff --git a/test/utils_test.js b/test/utils_test.js index 5acfcc229d..8b69e58b22 100644 --- a/test/utils_test.js +++ b/test/utils_test.js @@ -1544,11 +1544,22 @@ describe("utils", () => { schema: { type: ["integer", "null"] }, expected: "integer", }, + { + schema: { properties: {} }, + expected: "object", + }, + { + schema: { additionalProperties: {} }, + expected: "object", + }, ]; it("should correctly guess the type of a schema", () => { for (const test of cases) { - expect(getSchemaType(test.schema)).eql(test.expected); + expect(getSchemaType(test.schema)).eql( + test.expected, + `${JSON.stringify(test.schema)} should guess type of ${test.expected}` + ); } }); });