New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

joi-to-json

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-to-json - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

outputs/base.json

5

fixtures/joi-obj-12.1.0.js

@@ -18,2 +18,7 @@ const joi = require('joi-12')

gender: joi.string().valid('Male', 'Female', '').default('Male'),
genderSpecific: joi.when('gender', {
is: 'Female',
then: joi.number().required(),
otherwise: joi.string()
}),
height: joi.number().precision(2).positive().greater(0).less(200),

@@ -20,0 +25,0 @@ birthday: joi.date().iso(),

@@ -18,2 +18,7 @@ const joi = require('joi-13')

gender: joi.string().valid('Male', 'Female', '').default('Male'),
genderSpecific: joi.when('gender', {
is: 'Female',
then: joi.number().required(),
otherwise: joi.string()
}),
height: joi.number().precision(2).positive().greater(0).less(200),

@@ -20,0 +25,0 @@ birthday: joi.date().iso(),

@@ -18,2 +18,7 @@ const joi = require('joi-14')

gender: joi.string().valid('Male', 'Female', '').default('Male'),
genderSpecific: joi.when('gender', {
is: 'Female',
then: joi.number().required(),
otherwise: joi.string()
}),
height: joi.number().precision(2).positive().greater(0).less(200),

@@ -20,0 +25,0 @@ birthday: joi.date().iso(),

@@ -18,2 +18,7 @@ const joi = require('joi-15')

gender: joi.string().valid('Male', 'Female', '').default('Male'),
genderSpecific: joi.when('gender', {
is: 'Female',
then: joi.number().required(),
otherwise: joi.string()
}),
height: joi.number().precision(2).positive().greater(0).less(200),

@@ -20,0 +25,0 @@ birthday: joi.date().iso(),

@@ -18,3 +18,15 @@ const joi = require('joi-16')

gender: joi.string().valid('Male', 'Female', '').default('Male'),
genderSpecific: joi.when('gender', {
is: 'Female',
then: joi.number().required(),
otherwise: joi.string()
}),
height: joi.number().precision(2).positive().greater(0).less(200),
heightRank: joi.alternatives().conditional('height', {
switch: [
{ is: 0, then: joi.string() },
{ is: joi.number().greater(160), then: joi.number() },
{ is: joi.number().greater(300), then: joi.object().keys({ name: joi.string(), level: joi.number() }) }
]
}),
birthday: joi.date().iso(),

@@ -21,0 +33,0 @@ birthTime: joi.date().timestamp('unix'),

@@ -18,3 +18,15 @@ const joi = require('joi-17')

gender: joi.string().valid('Male', 'Female', '').default('Male'),
genderSpecific: joi.when('gender', {
is: 'Female',
then: joi.number().required(),
otherwise: joi.string()
}),
height: joi.number().precision(2).positive().greater(0).less(200),
heightRank: joi.alternatives().conditional('height', {
switch: [
{ is: 0, then: joi.string() },
{ is: joi.number().greater(160), then: joi.number() },
{ is: joi.number().greater(300), then: joi.object().keys({ name: joi.string(), level: joi.number() }) }
]
}),
birthday: joi.date().iso(),

@@ -21,0 +33,0 @@ birthTime: joi.date().timestamp('unix'),

14

lib/parser_base.js

@@ -353,3 +353,15 @@ /* eslint no-use-before-define: 'off' */

schema.oneOf = _.map(joiDescribe.alternatives, this._convertSchema.bind(this))
const item = joiDescribe.alternatives[0]
if (joiDescribe.alternatives.length === 1 && (item.is || item.then || item.otherwise)) {
schema.oneOf = []
if (item.then) {
schema.oneOf.push(this._convertSchema(item.then))
}
if (item.otherwise) {
schema.oneOf.push(this._convertSchema(item.otherwise))
}
} else {
schema.oneOf = _.map(joiDescribe.alternatives, this._convertSchema.bind(this))
}
delete schema.type

@@ -356,0 +368,0 @@ }

@@ -205,10 +205,44 @@ const _ = require('lodash')

const that = this
schema.oneOf = _.map(joiDescribe.matches, (match) => {
return that._convertSchema(match.schema)
})
if (joiDescribe.matches.length === 1 && joiDescribe.matches[0].switch) {
schema.oneOf = _.map(joiDescribe.matches[0].switch, (condition) => {
return that._convertSchema(condition.then || condition.otherwise)
})
} else {
schema.oneOf = _.map(joiDescribe.matches, (match) => {
return that._convertSchema(match.schema)
})
}
delete schema.type
}
_setAnyProperties(schema, joiDescribe) {
if (schema.type !== 'any') {
return
}
if (joiDescribe.whens) {
const condition = joiDescribe.whens[0]
schema.oneOf = []
if (condition.then) {
schema.oneOf.push(this._convertSchema(condition.then))
}
if (condition.otherwise) {
schema.oneOf.push(this._convertSchema(condition.otherwise))
}
delete schema.type
return
}
schema.type = [
'array',
'boolean',
'number',
'object',
'string',
'null'
]
}
}
module.exports = JoiJsonSchemaParser

4

package.json
{
"name": "joi-to-json",
"version": "1.3.1",
"version": "1.4.0",
"description": "joi to JSON Schema Converter",

@@ -28,3 +28,3 @@ "main": "index.js",

"eslint": "^6.8.0",
"jest": "^25.1.0",
"jest": "^25.2.4",
"jest-expect-message": "^1.0.2",

@@ -31,0 +31,0 @@ "joi-12": "npm:@commercial/joi@^12.1.0",

@@ -0,5 +1,5 @@

const _ = require('lodash')
const fs = require('fs')
const Validator = require('jsonschema').Validator
const convert = require('../index')
const expected = require('../fixtures/output.json')
const jsonSchemaDraft = require('../schemas/json-schema-draft04')

@@ -10,2 +10,10 @@

const isDebug = process.env.DEBUG === 'true'
const outputs = fs.readdirSync('./outputs')
const outputMap = _.reduce(outputs, (map, filename) => {
const name = filename.replace('.json', '')
map[name] = require(`../outputs/${filename}`)
return map
}, {})
const files = fs.readdirSync('./fixtures')

@@ -17,3 +25,11 @@

const joiObj = require(`../fixtures/${file}`)
const jsonSchema = convert(joiObj, process.env.DEBUG === 'true')
const jsonSchema = convert(joiObj, isDebug)
if (isDebug) {
console.debug(`Converted schema for fixture ${file}`, JSON.stringify(jsonSchema, null, 2))
}
let expected = outputMap[file.replace('.js', '')]
if (!expected) {
expected = outputMap.base
}
expect(jsonSchema).toEqual(expected)

@@ -20,0 +36,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc