Apply remove on properties which contains "$ref" doesn't work
jeremyraffin opened this issue · 2 comments
Hello @mavarazy,
Thanks for this useful project.
I'm trying to remove a schema property which contains "$ref" but the schema returned by the function fetchSchema
(https://github.com/RxNT/react-jsonschema-form-conditionals/blob/master/src/utils.js#L40) is the "$ref" definition object.
So, the function doRemove
(https://github.com/RxNT/react-jsonschema-form-conditionals/blob/master/src/actions/remove.js#L10), breaks.
You can reproduce the error by adding the test in remove.test.js
(https://github.com/RxNT/react-jsonschema-form-conditionals/blob/master/test/actions/remove.test.js)
let origSchemaWithRef = {
definitions: {
address: {
properties: {
street: { type: "string" },
zip: { type: "string" },
},
},
},
properties: {
title: { type: "string" },
firstName: { type: "string" },
address: { $ref: "#/definitions/address" },
},
};
let originUiSchemaWithRef = {
title: {},
firstName: {},
address: {},
};
test("remove field which contains ref", () => {
let schemaWithRef = deepcopy(origSchemaWithRef);
let uiSchemaWithRef = deepcopy(originUiSchemaWithRef);
remove({ field: ["address"] }, schemaWithRef, uiSchemaWithRef);
let schemaWithoutAddress = {
definitions: {
address: {
properties: {
street: { type: "string" },
zip: { type: "string" },
},
},
},
properties: {
title: { type: "string" },
firstName: { type: "string" },
},
};
expect(schemaWithRef).toEqual(schemaWithoutAddress);
let uiSchemaWithoutAddress = {
title: {},
firstName: {},
};
expect(uiSchemaWithRef).toEqual(uiSchemaWithoutAddress);
});
Tell me if you need more informations.
@jeremyraffin thank you for an exemplary issue example.
I've fixed the problem and it's in a new release.
@mavarazy It works, thank you for your reactivity.