Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export function getSchemaType(schema) {
return "string";
}

if ((!type && schema.properties) || schema.additionalProperties) {
Comment thread
domharrington marked this conversation as resolved.
Outdated
return "object";
}

if (type instanceof Array && type.length === 2 && type.includes("null")) {
return type.find(type => type !== "null");
}
Expand Down
13 changes: 12 additions & 1 deletion test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
});
});
Expand Down