joi-to-json 3.1.0 → 3.1.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.
- package/CHANGELOG.md +4 -0
- package/README.md +18 -2
- package/index.d.ts +32 -14
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -242,6 +242,10 @@ properties:
|
|
|
242
242
|
additionalProperties: true
|
|
243
243
|
```
|
|
244
244
|
|
|
245
|
+
## Special Joi Operator Support
|
|
246
|
+
|
|
247
|
+
* [Logical Relation Operator](./docs/logical_rel_support.md)
|
|
248
|
+
|
|
245
249
|
## Browser support
|
|
246
250
|
For generating JSON Schema in a browser you should use below import syntax for `joi` library in order to work because the `joi` browser minimized build does not have `describe` api which the `joi-to-json` relies on.
|
|
247
251
|
|
|
@@ -249,9 +253,21 @@ For generating JSON Schema in a browser you should use below import syntax for `
|
|
|
249
253
|
import Joi from 'joi/lib/index';
|
|
250
254
|
```
|
|
251
255
|
|
|
252
|
-
##
|
|
256
|
+
## TypeScript support
|
|
253
257
|
|
|
254
|
-
|
|
258
|
+
```typescript
|
|
259
|
+
import joi from 'joi';
|
|
260
|
+
import * as Joi2Json from 'joi-to-json';
|
|
261
|
+
import parse from 'joi-to-json';
|
|
262
|
+
|
|
263
|
+
const logicalOpParser: Joi2Json.LogicalOpParserOpts = {
|
|
264
|
+
with: function (a) {}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
parse(joi.string()); // Default call
|
|
268
|
+
parse(joi.string(), 'json', {}, false); // Completely disable Logical Relation Operator
|
|
269
|
+
parse(joi.string(), 'open-api', {}, { logicalOpParser }); // Partially override Logical Relation Operator
|
|
270
|
+
```
|
|
255
271
|
|
|
256
272
|
## Test
|
|
257
273
|
|
package/index.d.ts
CHANGED
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import Joi from 'joi-17';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type Mode = 'json' | 'open-api' | 'json-draft-2019-09' | 'json-draft-04';
|
|
3
|
+
/**
|
|
4
|
+
* @type {string}
|
|
5
|
+
*/
|
|
6
|
+
export type Mode = 'json' | 'open-api' | 'json-draft-2019-09' | 'json-draft-04';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export function parse(joi: Joi.Schema, mode?: Mode, sharedSchema?: Record<string, any>): any;
|
|
16
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* The parser function modifies the schema in-place.
|
|
10
|
+
* @param {any} schema - JSON schema object
|
|
11
|
+
* @param {any} dependency - JOI dependency object
|
|
12
|
+
*/
|
|
13
|
+
export type LogicalOpParserFn = (schema, dependency) => void;
|
|
17
14
|
|
|
18
|
-
export
|
|
15
|
+
export interface LogicalOpParserOpts {
|
|
16
|
+
and?: LogicalOpParserFn,
|
|
17
|
+
nand?: LogicalOpParserFn,
|
|
18
|
+
or?: LogicalOpParserFn,
|
|
19
|
+
xor?: LogicalOpParserFn,
|
|
20
|
+
oxor?: LogicalOpParserFn,
|
|
21
|
+
with?: LogicalOpParserFn,
|
|
22
|
+
without?: LogicalOpParserFn
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type ParserOptions = false | { logicalOpParser?: LogicalOpParserOpts };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Joi.Schema} joi - A Joi schema.
|
|
29
|
+
* @param {string} [mode='json'] - json / open-api / json-draft-2019-09 / json-draft-04
|
|
30
|
+
* @param {Record} [sharedSchema={}] - Passed-in object storing shared schemas
|
|
31
|
+
* @param {ParserOptions} [parserOptions={}] - Passed-in options for parser
|
|
32
|
+
* @returns {any} Converted JSON schema object.
|
|
33
|
+
*/
|
|
34
|
+
export function parse(joi: typeof Joi.Schema, mode?: Mode, sharedSchema?: Record<string, any>, parserOptions?: ParserOptions): any;
|
|
35
|
+
|
|
36
|
+
export default parse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joi-to-json",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "joi to JSON / OpenAPI Schema Converter",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"semver-compare": "^1.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"ajv": "^8.
|
|
31
|
+
"ajv": "^8.12.0",
|
|
32
32
|
"ajv-draft-04": "^1.0.0",
|
|
33
|
-
"eslint": "^8.
|
|
34
|
-
"jest": "^
|
|
33
|
+
"eslint": "^8.31.0",
|
|
34
|
+
"jest": "^29.3.1",
|
|
35
35
|
"joi-12": "npm:@commercial/joi@^12.1.0",
|
|
36
36
|
"joi-13": "npm:joi@^13.7.0",
|
|
37
37
|
"joi-14": "npm:joi@^14.3.1",
|