Skip to content

Commit a08c563

Browse files
committed
Added $ref tests
1 parent 75c4d84 commit a08c563

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

packages/core/src/utils.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,10 @@ const resolveCondition = (schema, rootSchema, formdata) => {
676676

677677
if (conditionalSchema) {
678678
return retrieveSchema(
679-
mergeSchemas(conditionalSchema, resolvedSchemaLessConditional),
679+
mergeSchemas(
680+
retrieveSchema(conditionalSchema, rootSchema, formdata),
681+
resolvedSchemaLessConditional
682+
),
680683
rootSchema,
681684
formdata
682685
);

packages/core/test/utils_test.js

+68
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,74 @@ describe("utils", () => {
25122512
animal: "Cat",
25132513
};
25142514

2515+
expect(retrieveSchema(schema, { definitions }, formData)).eql({
2516+
type: "object",
2517+
properties: {
2518+
animal: {
2519+
enum: ["Cat", "Fish"],
2520+
},
2521+
food: { type: "string", enum: ["meat", "grass", "fish"] },
2522+
},
2523+
required: ["animal", "food"],
2524+
});
2525+
});
2526+
it.only("should resolve $ref", () => {
2527+
const schema = {
2528+
type: "object",
2529+
properties: {
2530+
animal: {
2531+
enum: ["Cat", "Fish"],
2532+
},
2533+
},
2534+
allOf: [
2535+
{
2536+
if: {
2537+
properties: { animal: { const: "Cat" } },
2538+
},
2539+
then: {
2540+
$ref: "#/definitions/cat",
2541+
},
2542+
required: ["food"],
2543+
},
2544+
{
2545+
if: {
2546+
properties: { animal: { const: "Fish" } },
2547+
},
2548+
then: {
2549+
$ref: "#/definitions/fish",
2550+
},
2551+
},
2552+
{
2553+
required: ["animal"],
2554+
},
2555+
],
2556+
};
2557+
2558+
const definitions = {
2559+
cat: {
2560+
properties: {
2561+
food: { type: "string", enum: ["meat", "grass", "fish"] },
2562+
},
2563+
},
2564+
fish: {
2565+
properties: {
2566+
food: {
2567+
type: "string",
2568+
enum: ["insect", "worms"],
2569+
},
2570+
water: {
2571+
type: "string",
2572+
enum: ["lake", "sea"],
2573+
},
2574+
},
2575+
required: ["food", "water"],
2576+
},
2577+
};
2578+
2579+
const formData = {
2580+
animal: "Cat",
2581+
};
2582+
25152583
expect(retrieveSchema(schema, { definitions }, formData)).eql({
25162584
type: "object",
25172585
properties: {

0 commit comments

Comments
 (0)