@cypress/schema-tools
Advanced tools
Comparing version 4.1.0 to 4.1.1
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lodash_get_1 = __importDefault(require("lodash.get")); | ||
var ramda_1 = require("ramda"); | ||
@@ -58,9 +54,5 @@ var utils_1 = require("./utils"); | ||
} | ||
var required = lodash_get_1.default(schemaObj, 'schema.required'); | ||
if (required) { | ||
var existingRequired = lodash_get_1.default(from, 'schema.required', []); | ||
newSchema.schema.required = ramda_1.union(existingRequired, required); | ||
} | ||
utils_1.normalizeRequiredProperties(newSchema.schema); | ||
return newSchema; | ||
}; | ||
exports.extend = extend; |
@@ -8,2 +8,3 @@ "use strict"; | ||
var ramda_1 = require("ramda"); | ||
var lodash_reduce_1 = __importDefault(require("lodash.reduce")); | ||
exports.semverToString = function (s) { | ||
@@ -16,3 +17,9 @@ return s.major + "." + s.minor + "." + s.patch; | ||
if (schema.properties) { | ||
schema.required = Object.keys(schema.properties); | ||
var reducer = function (memo, obj, key) { | ||
if (obj.required !== false) { | ||
memo.push(key); | ||
} | ||
return memo; | ||
}; | ||
schema.required = lodash_reduce_1.default(schema.properties, reducer, []); | ||
} | ||
@@ -19,0 +26,0 @@ else { |
{ | ||
"name": "@cypress/schema-tools", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Validate, sanitize and document JSON schemas", | ||
@@ -36,11 +36,12 @@ "main": "dist", | ||
"@bahmutov/all-paths": "1.0.2", | ||
"@bahmutov/is-my-json-valid": "2.17.3", | ||
"debug": "3.1.0", | ||
"@bahmutov/is-my-json-valid": "2.17.3", | ||
"json-stable-stringify": "1.0.1", | ||
"json2md": "1.6.1", | ||
"lodash.camelcase": "4.3.0", | ||
"lodash.get": "4.4.2", | ||
"lodash.reduce": "^4.6.0", | ||
"lodash.set": "4.3.2", | ||
"ramda": "0.25.0", | ||
"json2md": "1.6.1", | ||
"quote": "0.4.0" | ||
"quote": "0.4.0", | ||
"ramda": "0.25.0" | ||
}, | ||
@@ -47,0 +48,0 @@ "devDependencies": { |
@@ -138,2 +138,3 @@ # @cypress/schema-tools [](https://circleci.com/gh/cypress-io/schema-tools) [![renovate-app badge][renovate-badge]][renovate-app] | ||
- [addProperty](#addproperty) | ||
- [extend](#extend) | ||
@@ -309,2 +310,14 @@ ### hasSchema | ||
### extend | ||
Rather than add a single property at a time, you can simply use `extend(existingSchema, newSchemaObj)`. | ||
The `existingSchema` will be deep cloned and have the `newSchemaObj` properties merged in. | ||
If `newSchemaObj.version` is not provided, then the previous schema's semver `minor` property will be bumped by one. | ||
Fields like `required` are automatically unioned. | ||
See [src/actions.ts](src/actions.ts) and [test/extend-schema-test.ts](test/extend-schema-test.ts) for examples. | ||
## Debugging | ||
@@ -311,0 +324,0 @@ |
@@ -1,9 +0,3 @@ | ||
import get from 'lodash.get' | ||
import { clone, equals, reject, mergeDeepRight, union } from 'ramda' | ||
import { | ||
JsonProperties, | ||
JsonPropertyTypes, | ||
ObjectSchema, | ||
PlainObject, | ||
} from './objects' | ||
import { clone, equals, reject, mergeDeepRight } from 'ramda' | ||
import { JsonProperties, JsonPropertyTypes, ObjectSchema } from './objects' | ||
import { normalizeRequiredProperties } from './utils' | ||
@@ -88,3 +82,3 @@ | ||
const extend = (from: ObjectSchema, schemaObj: PlainObject) => { | ||
const extend = (from: ObjectSchema, schemaObj) => { | ||
const newSchema: ObjectSchema = mergeDeepRight(clone(from), schemaObj) | ||
@@ -97,10 +91,4 @@ | ||
const required = get(schemaObj, 'schema.required') | ||
normalizeRequiredProperties(newSchema.schema) | ||
if (required) { | ||
const existingRequired = get(from, 'schema.required', []) | ||
newSchema.schema.required = union(existingRequired, required) | ||
} | ||
return newSchema | ||
@@ -107,0 +95,0 @@ } |
import camelCase from 'lodash.camelcase' | ||
import { map, path, uniq } from 'ramda' | ||
import reduce from 'lodash.reduce' | ||
import { | ||
JsonSchema, | ||
ObjectSchema, | ||
@@ -10,2 +10,3 @@ SchemaCollection, | ||
VersionedSchema, | ||
JsonSchema, | ||
} from './objects' | ||
@@ -30,3 +31,11 @@ | ||
if (schema.properties) { | ||
schema.required = Object.keys(schema.properties) | ||
const reducer = (memo, obj, key) => { | ||
if (obj.required !== false) { | ||
memo.push(key) | ||
} | ||
return memo | ||
} | ||
schema.required = reduce(schema.properties, reducer, []) | ||
} else { | ||
@@ -33,0 +42,0 @@ schema.required = [] |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
80944
348
0
11
1985
+ Addedlodash.reduce@^4.6.0
+ Addedlodash.reduce@4.6.0(transitive)