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 2.0.0 to 2.1.0

fixtures/joi-obj-12.js

4

lib/parsers/json.js

@@ -205,7 +205,7 @@ /* eslint no-use-before-define: 'off' */

case 'greater':
fieldSchema.exclusiveMinimum = true
fieldSchema.exclusiveMinimum = value.limit
fieldSchema.minimum = value.limit
break
case 'less':
fieldSchema.exclusiveMaximum = true
fieldSchema.exclusiveMaximum = value.limit
fieldSchema.maximum = value.limit

@@ -212,0 +212,0 @@ break

@@ -43,3 +43,3 @@ const _ = require('lodash')

_.each(meta, (value, key) => {
if (key.startsWith('x-')) {
if (key.startsWith('x-') || key === 'deprecated') {
schema[key] = value

@@ -46,0 +46,0 @@ }

@@ -74,5 +74,5 @@ {

"type": "number",
"exclusiveMinimum": true,
"exclusiveMinimum": 0,
"minimum": 0,
"exclusiveMaximum": true,
"exclusiveMaximum": 200,
"maximum": 200

@@ -79,0 +79,0 @@ },

@@ -77,4 +77,4 @@ {

"height": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"exclusiveMaximum": 200,
"exclusiveMinimum": 0,
"maximum": 200,

@@ -81,0 +81,0 @@ "minimum": 0,

{
"name": "joi-to-json",
"version": "2.0.0",
"version": "2.1.0",
"description": "joi to JSON / OpenAPI Schema Converter",

@@ -30,2 +30,4 @@ "main": "index.js",

"devDependencies": {
"ajv": "^8.6.3",
"ajv-draft-04": "^1.0.0",
"eslint": "^7.32.0",

@@ -38,5 +40,4 @@ "jest": "^27.2.0",

"joi-16": "npm:@hapi/joi@^16.1.8",
"joi-17": "npm:@hapi/joi@^17.1.0",
"jsonschema": "^1.2.0"
"joi-17": "npm:joi@^17.4.2"
}
}

@@ -13,3 +13,3 @@ # joi-to-json

The intention of `joi-to-json` is to support converting different version's joi schema to [JSON Schema (draft-04)](https://json-schema.org/specification-links.html#draft-4) using `describe` api.
The intention of `joi-to-json` is to support converting different version's joi schema to [JSON Schema](https://json-schema.org) using `describe` api.

@@ -45,3 +45,4 @@ ## 2.0.0 is out

* 16.1.8
* 17.1.0
* joi
* 17.4.2

@@ -57,3 +58,7 @@ For all above versions, I have tested one complex joi object [fixtures](./fixtures) which covers most of the JSON schema attributes that can be described in joi schema.

Currently supported output types are `json` and `open-api`.
Currently supported output types:
* `json` - Default. Stands for JSON Schema Draft 07
* `open-api` - Stands for OpenAPI Schema
* `json-draft-04` - Stands for JSON Schema Draft 04
* `json-draft-2019-09` - Stands for JSON Schema Draft 2019-09

@@ -87,3 +92,4 @@ The output schema format are in [outputs](./outputs) under specific folders for different types.

retired: joi.boolean().truthy('yes').falsy('no').insensitive(false),
certificate: joi.binary().encoding('base64')
certificate: joi.binary().encoding('base64'),
notes: joi.any().meta({ 'x-supported-lang': ['zh-CN', 'en-US'], deprecated: true })
})

@@ -90,0 +96,0 @@

const _ = require('lodash')
const fs = require('fs')
const Validator = require('jsonschema').Validator
const Ajv = require('ajv')
const parse = require('../index')
function executeTests(outputType, jsonSchema) {
const v = new Validator()
if (!!jsonSchema) {
v.addSchema(jsonSchema)
}
function executeTests(outputType, ajv = new Ajv({ allErrors: true })) {
const outputs = fs.readdirSync(`./outputs/${outputType}`)

@@ -24,3 +18,3 @@ const outputMap = _.reduce(outputs, (map, filename) => {

if (file.indexOf(process.env.CASE_PATTERN || 'joi-obj-') === 0) {
test(`JSON Schema Parsing - ${file} `, () => {
test(`${outputType} schema parsing - ${file} `, () => {
const joiObj = require(`../fixtures/${file}`)

@@ -37,9 +31,7 @@ const destSchema = parse(joiObj, outputType)

// Safety net in case the expected output is not compatible to json schema
if (!!jsonSchema) {
const result = v.validate(destSchema, jsonSchema)
if (result.errors.length > 0) {
console.error(JSON.stringify(result.errors, null, 2))
}
expect(result.errors.length).toBe(0)
const validationResult = ajv.validateSchema(destSchema)
if (!validationResult) {
console.error(JSON.stringify(ajv.errors, null, 2))
}
expect(validationResult).toBeTruthy()
})

@@ -46,0 +38,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