Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

chore: update our fork with the latest upstream #3

Merged
merged 14 commits into from
Feb 27, 2020
Merged
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
Prev Previous commit
Next Next commit
Don't crash when schema property is a non-object - show an error inst…
…ead (rjsf-team#1582)

* don't throw TypeError: Cannot use 'in' operator to search for

* Update Form_test.js

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
estin and epicfaace authored Feb 25, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 81e806285e8871975db0888363f0b22a3fbd0f2e
8 changes: 6 additions & 2 deletions packages/core/src/utils.js
Original file line number Diff line number Diff line change
@@ -152,12 +152,13 @@ export function hasWidget(schema, widget, registeredWidgets = {}) {
}

function computeDefaults(
schema,
_schema,
parentDefaults,
definitions,
rawFormData = {},
includeUndefinedValues = false
) {
let schema = isObject(_schema) ? _schema : {};
const formData = isObject(rawFormData) ? rawFormData : {};
// Compute the defaults recursively: give highest priority to deepest nodes.
let defaults = parentDefaults;
@@ -655,6 +656,9 @@ function resolveReference(schema, definitions, formData) {
}

export function retrieveSchema(schema, definitions = {}, formData = {}) {
if (!isObject(schema)) {
return {};
}
let resolvedSchema = resolveSchema(schema, definitions, formData);
if ("allOf" in schema) {
try {
@@ -971,7 +975,7 @@ export function toIdSchema(
const field = schema.properties[name];
const fieldId = idSchema.$id + "_" + name;
idSchema[name] = toIdSchema(
field,
isObject(field) ? field : {},
fieldId,
definitions,
// It's possible that formData is not an object -- this can happen if an
29 changes: 29 additions & 0 deletions packages/core/test/Form_test.js
Original file line number Diff line number Diff line change
@@ -51,6 +51,35 @@ describeRepeated("Form common", createFormComponent => {
const node = findDOMNode(comp);
expect(node.querySelectorAll("button[type=submit]")).to.have.length.of(2);
});

it("should render errors if schema isn't object", () => {
const props = {
schema: {
type: "object",
title: "object",
properties: {
firstName: "some mame",
address: {
$ref: "#/definitions/address",
},
},
definitions: {
address: {
street: "some street",
},
},
},
};
const comp = renderIntoDocument(
<Form {...props}>
<button type="submit">Submit</button>
</Form>
);
const node = findDOMNode(comp);
expect(node.querySelector(".unsupported-field").textContent).to.contain(
"Unknown field type undefined"
);
});
});

describe("on component creation", () => {