Installations
npm install joi-to-json-schema
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.15.1
NPM Version
6.4.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
lightsofapollo
Download Statistics
Total Downloads
2,857,934
Last Day
1,127
Last Week
4,115
Last Month
18,083
Last Year
473,745
GitHub Statistics
140 Stars
134 Commits
37 Forks
3 Watching
11 Branches
18 Contributors
Package Meta Information
Latest Version
5.1.0
Package Id
joi-to-json-schema@5.1.0
Unpacked Size
120.74 kB
Size
28.55 kB
File Count
14
NPM Version
6.4.0
Node Version
8.15.1
Total Downloads
Cumulative downloads
Total Downloads
2,857,934
Last day
-10.4%
1,127
Compared to previous day
Last week
-22.5%
4,115
Compared to previous week
Last month
13.6%
18,083
Compared to previous month
Last year
-0.3%
473,745
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
joi-to-json-schema
The goal is to provide best effort conversion from Joi objects to JSON Schema (draft-04) with the understanding that only some of Joi's schematics can be converted directly. Primarily this module exists to convert Joi schema objects for existing tools which happen to currently consume JSON Schema.
Installation
npm install joi-to-json-schema
Usage
1var joi = require('joi'), 2 convert = require('joi-to-json-schema'), 3 joiSchema = joi.object({ 4 'name': joi.string().required().regex(/^\w+$/), 5 'description': joi.string().optional().default('no description provided'), 6 'a': joi.boolean().required().default(false), 7 'b': joi.alternatives().when('a', { 8 is: true, 9 then: joi.string().default('a is true'), 10 otherwise: joi.number().default(0) 11 }) 12 }); 13 14convert(joiSchema);
which will produce:
1{ type: 'object', 2 properties: 3 { name: { type: 'string', pattern: '^\\w+$' }, 4 description: { default: 'no description provided', type: 'string' }, 5 a: { type: 'boolean', default: false }, 6 b: { oneOf: [ { default: 'a is true', type: 'string' }, { type: 'number', default: 0 } ] } }, 7 additionalProperties: false, 8 required: [ 'name', 'a' ] }
JSDOC
1 /** 2 * Converts the supplied joi validation object into a JSON schema object, 3 * optionally applying a transformation. 4 * 5 * @param {JoiValidation} joi 6 * @param {TransformFunction} [transformer=null] 7 * @returns {JSONSchema} 8 */ 9 export default function convert(joi,transformer=null) { 10 // ... 11 }; 12 13 /** 14 * Joi Validation Object 15 * @typedef {object} JoiValidation 16 */ 17 18 /** 19 * Transformation Function - applied just before `convert()` returns and called as `function(object):object` 20 * @typedef {function} TransformFunction 21 */ 22 23 /** 24 * JSON Schema Object 25 * @typedef {object} JSONSchema 26 */
Notes
Joi's conditional form, i.e. .when('name',{is:cond,then:joi,otherwise:joi})
, is evaluated at runtime
and since, from the perspective of the schema, there is no way of knowing what the condition might resolve to, this
module takes the position that it should provide all possible resolutions in a JSON Schema oneOf:[]
clause.
Testing
All tests cases are first checked against expected results and then validated using Kris Zyp's excellent json-schema
References
- JSON Schema - Draft 4 from json-schema.org
- IETF Draft: JSON Schema: core definitions and terminology - draft-zyp-json-schema-04
- Understanding JSON Schema(pdf)
LICENSE
Copyright 2014, Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 7/13 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 24 are checked with a SAST tool
Reason
45 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More