Gathering detailed insights and metrics for joi-to-json-schema
Gathering detailed insights and metrics for joi-to-json-schema
npm install joi-to-json-schema
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
2,857,934
Last Day
1,127
Last Week
4,115
Last Month
18,083
Last Year
473,745
140 Stars
134 Commits
37 Forks
3 Watching
11 Branches
18 Contributors
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
Cumulative downloads
Total Downloads
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
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.
npm install joi-to-json-schema
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' ] }
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 */
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.
All tests cases are first checked against expected results and then validated using Kris Zyp's excellent json-schema
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
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
45 existing vulnerabilities detected
Details
Score
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