@nolwenture/formik-jsonschema-form 2.0.0 → 2.0.1
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.
package/README.md
CHANGED
|
@@ -211,8 +211,10 @@ The `createValidationSchema` function generates a Yup validation schema from you
|
|
|
211
211
|
```tsx
|
|
212
212
|
createValidationSchema(
|
|
213
213
|
{ schema, uiSchema }, // Schema and optional UI schema
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
{ // Optional options object
|
|
215
|
+
localize, // Localization function i18next t compatible
|
|
216
|
+
definitions, // Use these definitions instead of definitions in schema
|
|
217
|
+
}
|
|
216
218
|
)
|
|
217
219
|
```
|
|
218
220
|
|
|
@@ -244,7 +246,6 @@ import { useTranslation } from 'react-i18next';
|
|
|
244
246
|
const { t } = useTranslation();
|
|
245
247
|
const validationSchema = createValidationSchema(
|
|
246
248
|
{ schema, uiSchema },
|
|
247
|
-
{},
|
|
248
249
|
{ localize: t }
|
|
249
250
|
);
|
|
250
251
|
```
|
|
@@ -173,9 +173,9 @@ function getYupType(schema) {
|
|
|
173
173
|
throw new Error(`createValidationSchema: Unsupported schema type: ${type}`);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
function createValidationSchema(schemas,
|
|
176
|
+
function createValidationSchema(schemas, options) {
|
|
177
177
|
const { schema, uiSchema = {} } = schemas;
|
|
178
|
-
const { localize, conditionsContext = {}, condition } = options ?? {};
|
|
178
|
+
const { localize, definitions, conditionsContext = {}, condition } = options ?? {};
|
|
179
179
|
if (!schema?.properties) {
|
|
180
180
|
return Yup.object().shape({});
|
|
181
181
|
}
|
|
@@ -189,10 +189,7 @@ function createValidationSchema(schemas, definitions = {}, options) {
|
|
|
189
189
|
const defaultMsg = DEFAULT_ERROR_MESSAGES[key];
|
|
190
190
|
return typeof defaultMsg === "function" ? defaultMsg(params) : defaultMsg;
|
|
191
191
|
};
|
|
192
|
-
const schemaDefinitions = {
|
|
193
|
-
...definitions,
|
|
194
|
-
...(schema.definitions ?? {}),
|
|
195
|
-
};
|
|
192
|
+
const schemaDefinitions = (definitions ?? schema.definitions ?? {});
|
|
196
193
|
const requiredFields = schema.required;
|
|
197
194
|
function getValue(givenSchema, key, required) {
|
|
198
195
|
const { schema } = (0, solveReferences_1.solveReferences)(givenSchema, schemaDefinitions, {}, {});
|
|
@@ -204,8 +201,9 @@ function createValidationSchema(schemas, definitions = {}, options) {
|
|
|
204
201
|
yupSchema = createValidationSchema({
|
|
205
202
|
schema,
|
|
206
203
|
uiSchema: fieldUiSchema
|
|
207
|
-
},
|
|
204
|
+
}, {
|
|
208
205
|
localize,
|
|
206
|
+
definitions: schemaDefinitions,
|
|
209
207
|
conditionsContext,
|
|
210
208
|
});
|
|
211
209
|
type = type ?? "object";
|
|
@@ -389,8 +387,9 @@ function createValidationSchema(schemas, definitions = {}, options) {
|
|
|
389
387
|
return validationSchema.concat(createValidationSchema({
|
|
390
388
|
schema: solvedSchemas.schema,
|
|
391
389
|
uiSchema
|
|
392
|
-
},
|
|
390
|
+
}, {
|
|
393
391
|
localize,
|
|
392
|
+
definitions: schemaDefinitions,
|
|
394
393
|
conditionsContext,
|
|
395
394
|
condition: conditionalValidation.condition
|
|
396
395
|
}));
|
|
@@ -137,9 +137,9 @@ function getYupType(schema) {
|
|
|
137
137
|
throw new Error(`createValidationSchema: Unsupported schema type: ${type}`);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
export function createValidationSchema(schemas,
|
|
140
|
+
export function createValidationSchema(schemas, options) {
|
|
141
141
|
const { schema, uiSchema = {} } = schemas;
|
|
142
|
-
const { localize, conditionsContext = {}, condition } = options ?? {};
|
|
142
|
+
const { localize, definitions, conditionsContext = {}, condition } = options ?? {};
|
|
143
143
|
if (!schema?.properties) {
|
|
144
144
|
return Yup.object().shape({});
|
|
145
145
|
}
|
|
@@ -153,10 +153,7 @@ export function createValidationSchema(schemas, definitions = {}, options) {
|
|
|
153
153
|
const defaultMsg = DEFAULT_ERROR_MESSAGES[key];
|
|
154
154
|
return typeof defaultMsg === "function" ? defaultMsg(params) : defaultMsg;
|
|
155
155
|
};
|
|
156
|
-
const schemaDefinitions = {
|
|
157
|
-
...definitions,
|
|
158
|
-
...(schema.definitions ?? {}),
|
|
159
|
-
};
|
|
156
|
+
const schemaDefinitions = (definitions ?? schema.definitions ?? {});
|
|
160
157
|
const requiredFields = schema.required;
|
|
161
158
|
function getValue(givenSchema, key, required) {
|
|
162
159
|
const { schema } = solveReferences(givenSchema, schemaDefinitions, {}, {});
|
|
@@ -168,8 +165,9 @@ export function createValidationSchema(schemas, definitions = {}, options) {
|
|
|
168
165
|
yupSchema = createValidationSchema({
|
|
169
166
|
schema,
|
|
170
167
|
uiSchema: fieldUiSchema
|
|
171
|
-
},
|
|
168
|
+
}, {
|
|
172
169
|
localize,
|
|
170
|
+
definitions: schemaDefinitions,
|
|
173
171
|
conditionsContext,
|
|
174
172
|
});
|
|
175
173
|
type = type ?? "object";
|
|
@@ -353,8 +351,9 @@ export function createValidationSchema(schemas, definitions = {}, options) {
|
|
|
353
351
|
return validationSchema.concat(createValidationSchema({
|
|
354
352
|
schema: solvedSchemas.schema,
|
|
355
353
|
uiSchema
|
|
356
|
-
},
|
|
354
|
+
}, {
|
|
357
355
|
localize,
|
|
356
|
+
definitions: schemaDefinitions,
|
|
358
357
|
conditionsContext,
|
|
359
358
|
condition: conditionalValidation.condition
|
|
360
359
|
}));
|
|
@@ -22,8 +22,9 @@ type ConditionsContext = {
|
|
|
22
22
|
export declare function createValidationSchema(schemas: {
|
|
23
23
|
schema: Schema;
|
|
24
24
|
uiSchema?: UiSchema;
|
|
25
|
-
},
|
|
25
|
+
}, options?: {
|
|
26
26
|
localize?: LocalizeType;
|
|
27
|
+
definitions?: Schema;
|
|
27
28
|
conditionsContext?: Record<string, ConditionsContext[]>;
|
|
28
29
|
condition?: Condition;
|
|
29
30
|
}): Yup.ObjectSchema<{}, Yup.AnyObject, {}, "">;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nolwenture/formik-jsonschema-form",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Formik form generation from json schema",
|
|
5
5
|
"author": "anttivikman <antti.vikman@nolwenture.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -122,4 +122,4 @@
|
|
|
122
122
|
"last 1 safari version"
|
|
123
123
|
]
|
|
124
124
|
}
|
|
125
|
-
}
|
|
125
|
+
}
|