@nolwenture/formik-jsonschema-form 0.9.0 → 0.9.2

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.
@@ -7,12 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { ageFieldDefinition } from "../../sampleData/ageFieldDefinition";
10
11
  import { createInitialValues } from "../createInitialValues";
11
12
  const exampleSchema = {
12
13
  title: "TITLE",
13
14
  required: ["lastName", "requiredNestedObject", "requiredArray"],
14
15
  properties: {
15
16
  name: { type: "string", title: "Full name" },
17
+ age: { $ref: "#/definitions/age" },
16
18
  number: { type: "number", title: "Phone number" },
17
19
  feeling: { type: "boolean", title: "Feeling happy today?" },
18
20
  arrayOfObject: {
@@ -53,12 +55,16 @@ const exampleSchema = {
53
55
  },
54
56
  },
55
57
  },
58
+ definitions: {
59
+ age: ageFieldDefinition,
60
+ },
56
61
  };
57
62
  describe("Create Initial Values", () => {
58
63
  it("creates for an object type", () => __awaiter(void 0, void 0, void 0, function* () {
59
64
  const result = createInitialValues(exampleSchema);
60
65
  const expected = {
61
66
  name: "",
67
+ age: 0,
62
68
  number: 0,
63
69
  feeling: false,
64
70
  arrayOfObject: [],
@@ -1,12 +1,18 @@
1
+ import { solveReferences } from "./solveReferences";
2
+ let schemaDefinitions = {};
1
3
  export function createInitialValues(schema) {
2
4
  if (!schema) {
3
5
  return {};
4
6
  }
7
+ if (schema.definitions) {
8
+ schemaDefinitions = schema.definitions;
9
+ }
5
10
  if (schema.properties) {
6
11
  return Object.keys(schema === null || schema === void 0 ? void 0 : schema.properties).reduce((acc, key) => {
7
12
  var _a;
8
13
  const value = (_a = schema === null || schema === void 0 ? void 0 : schema.properties) === null || _a === void 0 ? void 0 : _a[key];
9
- return Object.assign(Object.assign({}, acc), { [key]: createInitialValues(value) });
14
+ const solvedValue = solveReferences(value, schemaDefinitions);
15
+ return Object.assign(Object.assign({}, acc), { [key]: createInitialValues(solvedValue) });
10
16
  }, {});
11
17
  }
12
18
  const type = schema.type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "Antti Vikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [