json-2-joi 1.1.0 → 2.0.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 2.0.0
2
+
3
+ * [BREAKING] Remove `useDefaults` and `strictMode` options
4
+
1
5
  ### 1.1.0
2
6
 
3
7
  - Support providing `joiOptions` for JOI default instance creation.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Converts a JSON schema to a Joi schema for object validation.
6
6
 
7
- ## Change based on the forked version (Json2Joi):
7
+ ## Change based on the forked version (Enjoi):
8
8
 
9
9
  - Provided `refineDescription(schema)`, `allowNull` options
10
10
  - Change cycle reference resovling without self-generating id and rely on $id if defined in JSON schema
@@ -15,6 +15,7 @@ Converts a JSON schema to a Joi schema for object validation.
15
15
  - Support providing `joiOptions` for JOI default instance creation.
16
16
  - Support directly passing a Joi instance for schema building.
17
17
  - Remove `defaults` API. Please refer to section **Reuse JOI Schema Resolver** for similar usage.
18
+ - Remove `strictMode` and `useDefaults` option.
18
19
  - **Big Change** on `$ref` and `subSchemas`. Please refer to [test/test-references.js](test/test-references.js) for detail usage. Currently, four format of `$ref` are supported:
19
20
  * id
20
21
  * [baseUri]#anchor
@@ -53,7 +54,6 @@ Please file issues for other unsupported features.
53
54
  - `refineSchema(joiSchema, jsonSchema)` - an (optional) function to call to apply to adjust Joi schema base on the original JSON schema. Primary use case is handling `nullable` flag in OpenAPI 3.0
54
55
  - `extensions` - an array of extensions to pass [joi.extend](https://github.com/hapijs/joi/blob/master/API.md#extendextension).
55
56
  - `allowNull` - Allows null value when the field is NOT required with a default value of `false`.
56
- - `strictMode` - make schemas `strict(value)` with a default value of `false`.
57
57
 
58
58
  Example:
59
59
 
@@ -89,9 +89,9 @@ schema.additionalProperties !== false
89
89
  When this option is provided, a Joi instance will be created as `joiInstance = Joi.defaults((schema) => schema.options(joiOptions));` for building Joi Schema.
90
90
 
91
91
  As a result:
92
- * `useDefaults` will take effect only if `noDefaults` is NOT true in `joiOptions`.
93
92
  * `unknown` setting (originally set by schema.additionalProperties !== false) of the schema will take effect only if `allowUnknown` is NOT provided in `joiOptions`.
94
-
93
+ * Original `useDefaults` option will be replaced by `noDefaults` in `joiOptions`.
94
+ * Original `strictMode` option will be replaced by `convert` in `joiOptions`.
95
95
 
96
96
  ### Sub Schemas
97
97
 
package/lib/resolver.js CHANGED
@@ -20,9 +20,7 @@ const optionsSchema = Joi.object({
20
20
  refineSchema: Joi.func().allow(null),
21
21
  refineDescription: Joi.func().allow(null),
22
22
  allowNull: Joi.boolean().default(false),
23
- joiOptions: Joi.object().unknown(true).default({}),
24
- strictMode: Joi.boolean().default(false),
25
- useDefaults: Joi.boolean().default(false)
23
+ joiOptions: Joi.object().unknown(true).default({})
26
24
  });
27
25
 
28
26
  function isNumber(value) {
@@ -99,14 +97,12 @@ class SchemaResolver {
99
97
 
100
98
  Hoek.assert(!validatedResult.error, validatedResult.error);
101
99
 
102
- const { subSchemas = {}, refineType, refineSchema, strictMode, useDefaults, extensions = [], allowNull = false, refineDescription, joiOptions } = validatedResult.value;
100
+ const { subSchemas = {}, refineType, refineSchema, extensions = [], allowNull = false, refineDescription, joiOptions } = validatedResult.value;
103
101
 
104
102
  this.subSchemas = subSchemas;
105
103
  this.refineType = refineType;
106
104
  this.refineDescription = refineDescription;
107
105
  this.refineSchema = refineSchema;
108
- this.strictMode = strictMode;
109
- this.useDefaults = useDefaults;
110
106
  this.allowNull = allowNull;
111
107
  this.joiOptions = joiOptions;
112
108
  this.joiSharedSchemas = new Map();
@@ -232,7 +228,7 @@ class SchemaResolver {
232
228
  resolvedSchema = this.refineSchema(resolvedSchema, schema);
233
229
  }
234
230
 
235
- if (this.joiOptions.noDefaults !== true && this.useDefaults && schema.default !== undefined) {
231
+ if (schema.default !== undefined) {
236
232
  resolvedSchema = resolvedSchema.default(schema.default)
237
233
  }
238
234
 
@@ -337,7 +333,7 @@ class SchemaResolver {
337
333
 
338
334
  Hoek.assert(joischema, 'Could not resolve type: ' + schema.type + '.');
339
335
 
340
- return joischema.strict(this.strictMode);
336
+ return joischema;
341
337
  }
342
338
 
343
339
  if (Array.isArray(schema.type)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-2-joi",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "license": "Apache 2.0",
5
5
  "description": "Converts json-schema to Joi schema.",
6
6
  "main": "./index.js",