@nolwenture/formik-jsonschema-form 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.solveReferences = solveReferences;
|
|
4
4
|
const mergeSchemas_1 = require("./mergeSchemas");
|
|
5
|
+
const formik_1 = require("formik");
|
|
5
6
|
function solveReferences(schema, definitions, uiSchema, uiSchemaDefinitions) {
|
|
6
7
|
let solvedSchema = schema;
|
|
7
8
|
let solvedUiSchema = uiSchema;
|
|
8
9
|
if (typeof schema === "object" && schema["$ref"] && definitions) {
|
|
9
|
-
const
|
|
10
|
+
const pathParts = schema["$ref"].split("/");
|
|
11
|
+
if (pathParts[0] !== "#" || pathParts[1] !== "definitions") {
|
|
12
|
+
throw new Error("Only references to definitions are supported");
|
|
13
|
+
}
|
|
14
|
+
const path = pathParts.slice(2).join(".");
|
|
10
15
|
// TODO: Should we overwrite rather than merge? Maybe add a flag for choosing the behavior?
|
|
11
|
-
solvedSchema = (0, mergeSchemas_1.mergeSchemas)(definitions
|
|
16
|
+
solvedSchema = (0, mergeSchemas_1.mergeSchemas)((0, formik_1.getIn)(definitions, path) ?? {}, schema ?? {});
|
|
12
17
|
delete solvedSchema.$ref;
|
|
13
|
-
solvedUiSchema = (0, mergeSchemas_1.mergeSchemas)(uiSchemaDefinitions
|
|
18
|
+
solvedUiSchema = (0, mergeSchemas_1.mergeSchemas)((0, formik_1.getIn)(uiSchemaDefinitions, path) ?? {}, uiSchema ?? {});
|
|
14
19
|
}
|
|
15
20
|
return { schema: solvedSchema, uiSchema: solvedUiSchema };
|
|
16
21
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { mergeSchemas } from "./mergeSchemas";
|
|
2
|
+
import { getIn } from "formik";
|
|
2
3
|
export function solveReferences(schema, definitions, uiSchema, uiSchemaDefinitions) {
|
|
3
4
|
let solvedSchema = schema;
|
|
4
5
|
let solvedUiSchema = uiSchema;
|
|
5
6
|
if (typeof schema === "object" && schema["$ref"] && definitions) {
|
|
6
|
-
const
|
|
7
|
+
const pathParts = schema["$ref"].split("/");
|
|
8
|
+
if (pathParts[0] !== "#" || pathParts[1] !== "definitions") {
|
|
9
|
+
throw new Error("Only references to definitions are supported");
|
|
10
|
+
}
|
|
11
|
+
const path = pathParts.slice(2).join(".");
|
|
7
12
|
// TODO: Should we overwrite rather than merge? Maybe add a flag for choosing the behavior?
|
|
8
|
-
solvedSchema = mergeSchemas(definitions
|
|
13
|
+
solvedSchema = mergeSchemas(getIn(definitions, path) ?? {}, schema ?? {});
|
|
9
14
|
delete solvedSchema.$ref;
|
|
10
|
-
solvedUiSchema = mergeSchemas(uiSchemaDefinitions
|
|
15
|
+
solvedUiSchema = mergeSchemas(getIn(uiSchemaDefinitions, path) ?? {}, uiSchema ?? {});
|
|
11
16
|
}
|
|
12
17
|
return { schema: solvedSchema, uiSchema: solvedUiSchema };
|
|
13
18
|
}
|