@cypress/schema-tools
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -12,2 +12,5 @@ "use strict"; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -20,16 +23,13 @@ if (mod && mod.__esModule) return mod; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils = __importStar(require("./utils")); | ||
var formats_1 = require("./formats"); | ||
var sanitize_1 = require("./sanitize"); | ||
var is_my_json_valid_1 = __importDefault(require("@bahmutov/is-my-json-valid")); | ||
var debug_1 = __importDefault(require("debug")); | ||
var is_my_json_valid_1 = __importDefault(require("@bahmutov/is-my-json-valid")); | ||
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify")); | ||
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
var lodash_get_1 = __importDefault(require("lodash.get")); | ||
var lodash_set_1 = __importDefault(require("lodash.set")); | ||
var lodash_get_1 = __importDefault(require("lodash.get")); | ||
var ramda_1 = require("ramda"); | ||
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify")); | ||
var formats_1 = require("./formats"); | ||
var sanitize_1 = require("./sanitize"); | ||
var utils = __importStar(require("./utils")); | ||
var debug = debug_1.default('schema-tools'); | ||
@@ -36,0 +36,0 @@ exports.getVersionedSchema = function (schemas) { return function (name) { |
@@ -6,4 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var quote_1 = __importDefault(require("quote")); | ||
var utils_1 = require("./utils"); | ||
var quote_1 = __importDefault(require("quote")); | ||
var ticks = quote_1.default({ quotes: '`' }); | ||
@@ -10,0 +10,0 @@ var escapedCode = function (s) { return ticks(s.replace(/\|/g, '`|`')); }; |
@@ -6,10 +6,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var __1 = require(".."); | ||
var utils_1 = require("./utils"); | ||
var doc_formats_1 = require("./doc-formats"); | ||
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify")); | ||
var json2md_1 = __importDefault(require("json2md")); | ||
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify")); | ||
var ramda_1 = require("ramda"); | ||
var lazy_ass_1 = __importDefault(require("lazy-ass")); | ||
var quote_1 = __importDefault(require("quote")); | ||
var ramda_1 = require("ramda"); | ||
var __1 = require(".."); | ||
var doc_formats_1 = require("./doc-formats"); | ||
var utils_1 = require("./utils"); | ||
var ticks = quote_1.default({ quotes: '`' }); | ||
@@ -16,0 +16,0 @@ var title = [{ h1: 'Schemas' }]; |
@@ -6,5 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var quote_1 = __importDefault(require("quote")); | ||
var ramda_1 = require("ramda"); | ||
var __1 = require(".."); | ||
var ramda_1 = require("ramda"); | ||
var quote_1 = __importDefault(require("quote")); | ||
var ticks = quote_1.default({ quotes: '`' }); | ||
@@ -11,0 +11,0 @@ exports.checkMark = '✔'; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var debug_1 = __importDefault(require("debug")); | ||
var ramda_1 = require("ramda"); | ||
var api_1 = require("./api"); | ||
var ramda_1 = require("ramda"); | ||
var debug = debug_1.default('schema-tools'); | ||
exports.isDynamicFormat = function (formatDefaults) { return function (format) { return (formatDefaults ? format in formatDefaults : false); }; }; | ||
@@ -10,3 +15,6 @@ var isString = function (s) { return typeof s === 'string'; }; | ||
}; | ||
var isArrayType = function (prop) { return prop.type === 'array' && prop.items; }; | ||
var canPropertyBeArray = function (type) { | ||
return type === 'array' || (Array.isArray(type) && type.includes('array')); | ||
}; | ||
var isArrayType = function (prop) { return canPropertyBeArray(prop.type) && prop.items; }; | ||
var isStringArray = function (prop) { | ||
@@ -31,8 +39,13 @@ return isArrayType(prop) && canPropertyBeString(prop.items.type); | ||
var prop = props[key]; | ||
debug('looking at property %j', prop); | ||
if (key in object && Array.isArray(object[key])) { | ||
debug('%s is present as an array', key); | ||
if (isStringArray(prop)) { | ||
debug('%s is a string array', key); | ||
var list = result[key]; | ||
if (prop.items && prop.items.format) { | ||
var itemFormat = prop.items.format; | ||
debug('items format %s', itemFormat); | ||
if (formatDefaults && isDynamic(itemFormat)) { | ||
debug('format %s is dynamic, need to replace with default value', itemFormat); | ||
var defaultValue = formatDefaults[itemFormat]; | ||
@@ -47,2 +60,3 @@ for (var k = 0; k < list.length; k += 1) { | ||
else if (isArrayType(prop) && hasPropertiesArray(prop)) { | ||
debug('property %s is array-like and has properties', key); | ||
var list = object[key]; | ||
@@ -49,0 +63,0 @@ var propSchema = prop.items; |
{ | ||
"name": "@cypress/schema-tools", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "Validate, sanitize and document JSON schemas", | ||
@@ -47,4 +47,4 @@ "main": "dist", | ||
"@types/lodash.camelcase": "4.3.3", | ||
"@types/node": "9.6.9", | ||
"@types/ramda": "0.25.24", | ||
"@types/node": "9.6.15", | ||
"@types/ramda": "0.25.28", | ||
"ava": "0.25.0", | ||
@@ -58,6 +58,6 @@ "ava-ts": "0.24.5", | ||
"quote": "0.4.0", | ||
"semantic-release": "15.2.0", | ||
"semantic-release": "15.4.0", | ||
"terminal-banner": "1.1.0", | ||
"ts-node": "6.0.2", | ||
"tslint": "5.9.1", | ||
"ts-node": "6.0.3", | ||
"tslint": "5.10.0", | ||
"typescript": "2.8.3" | ||
@@ -64,0 +64,0 @@ }, |
@@ -276,2 +276,6 @@ # @cypress/schema-tools [](https://circleci.com/gh/cypress-io/schema-tools) [![renovate-app badge][renovate-badge]][renovate-app] | ||
## Debugging | ||
To see log messages from this module, run with `DEBUG=schema-tools` | ||
## Testing | ||
@@ -278,0 +282,0 @@ |
@@ -1,37 +0,36 @@ | ||
import { | ||
ObjectSchema, | ||
SchemaCollection, | ||
SchemaVersion, | ||
PlainObject, | ||
JsonSchema, | ||
} from './objects' | ||
import * as utils from './utils' | ||
import { | ||
JsonSchemaFormats, | ||
CustomFormats, | ||
detectors, | ||
getDefaults, | ||
FormatDefaults, | ||
} from './formats' | ||
import { sanitize } from './sanitize' | ||
import validator from '@bahmutov/is-my-json-valid' | ||
import debugApi from 'debug' | ||
import validator from '@bahmutov/is-my-json-valid' | ||
import stringify from 'json-stable-stringify' | ||
import cloneDeep from 'lodash.clonedeep' | ||
import get from 'lodash.get' | ||
import set from 'lodash.set' | ||
import get from 'lodash.get' | ||
import { | ||
uniq, | ||
difference, | ||
filter, | ||
find, | ||
whereEq, | ||
difference, | ||
keys, | ||
uniqBy, | ||
map, | ||
mergeAll, | ||
mergeDeepLeft, | ||
prop, | ||
map, | ||
filter, | ||
mergeDeepLeft, | ||
uniq, | ||
uniqBy, | ||
whereEq, | ||
} from 'ramda' | ||
import stringify from 'json-stable-stringify' | ||
import { | ||
CustomFormats, | ||
FormatDefaults, | ||
JsonSchemaFormats, | ||
detectors, | ||
getDefaults, | ||
} from './formats' | ||
import { | ||
JsonSchema, | ||
ObjectSchema, | ||
PlainObject, | ||
SchemaCollection, | ||
SchemaVersion, | ||
} from './objects' | ||
import { sanitize } from './sanitize' | ||
import * as utils from './utils' | ||
@@ -38,0 +37,0 @@ const debug = debugApi('schema-tools') |
@@ -0,4 +1,4 @@ | ||
import quote from 'quote' | ||
import { CustomFormats } from '../formats' | ||
import { findUsedColumns, checkMark, emptyMark } from './utils' | ||
import quote from 'quote' | ||
import { checkMark, emptyMark, findUsedColumns } from './utils' | ||
@@ -5,0 +5,0 @@ const ticks = quote({ quotes: '`' }) |
// generates Markdown document with all schema information | ||
import stringify from 'json-stable-stringify' | ||
import json2md from 'json2md' | ||
import la from 'lazy-ass' | ||
import quote from 'quote' | ||
import { flatten, toLower } from 'ramda' | ||
import { | ||
getExample, | ||
getObjectSchema, | ||
getSchemaVersions, | ||
normalizeName, | ||
schemaNames, | ||
normalizeName, | ||
getSchemaVersions, | ||
getObjectSchema, | ||
getExample, | ||
} from '..' | ||
import { ObjectSchema } from '../objects' | ||
import { CustomFormats } from '../formats' | ||
import { ObjectSchema, SchemaCollection } from '../objects' | ||
import { documentCustomFormats } from './doc-formats' | ||
import { documentSchema } from './utils' | ||
import { documentCustomFormats } from './doc-formats' | ||
import json2md from 'json2md' | ||
import stringify from 'json-stable-stringify' | ||
import { flatten, toLower } from 'ramda' | ||
import { SchemaCollection } from '../objects' | ||
import { CustomFormats } from '../formats' | ||
import la from 'lazy-ass' | ||
import quote from 'quote' | ||
const ticks = quote({ quotes: '`' }) | ||
@@ -23,0 +21,0 @@ const title = [{ h1: 'Schemas' }] |
@@ -1,6 +0,6 @@ | ||
import { JsonSchema, JsonProperties, SchemaCollection } from '../objects' | ||
import { schemaNames, normalizeName } from '..' | ||
import quote from 'quote' | ||
import { find, toLower } from 'ramda' | ||
import { normalizeName, schemaNames } from '..' | ||
import { CustomFormats } from '../formats' | ||
import { toLower, find } from 'ramda' | ||
import quote from 'quote' | ||
import { JsonProperties, JsonSchema, SchemaCollection } from '../objects' | ||
@@ -7,0 +7,0 @@ const ticks = quote({ quotes: '`' }) |
@@ -1,6 +0,9 @@ | ||
import { PlainObject, JsonSchema, SchemaCollection } from './objects' | ||
import debugApi from 'debug' | ||
import { clone } from 'ramda' | ||
import { assertSchema, getObjectSchema } from './api' | ||
import { clone } from 'ramda' | ||
import { FormatDefaults } from './formats' | ||
import { JsonSchema, PlainObject, SchemaCollection } from './objects' | ||
const debug = debugApi('schema-tools') | ||
export const isDynamicFormat = (formatDefaults: FormatDefaults | undefined) => ( | ||
@@ -15,4 +18,7 @@ format: string, | ||
const isArrayType = prop => prop.type === 'array' && prop.items | ||
const canPropertyBeArray = type => | ||
type === 'array' || (Array.isArray(type) && type.includes('array')) | ||
const isArrayType = prop => canPropertyBeArray(prop.type) && prop.items | ||
const isStringArray = prop => | ||
@@ -49,5 +55,9 @@ isArrayType(prop) && canPropertyBeString(prop.items.type) | ||
const prop = props[key] | ||
debug('looking at property %j', prop) | ||
if (key in object && Array.isArray(object[key])) { | ||
debug('%s is present as an array', key) | ||
if (isStringArray(prop)) { | ||
debug('%s is a string array', key) | ||
// go through the items in the array and if the format is dynamic | ||
@@ -59,3 +69,9 @@ // set default values | ||
const itemFormat = prop.items.format | ||
debug('items format %s', itemFormat) | ||
if (formatDefaults && isDynamic(itemFormat)) { | ||
debug( | ||
'format %s is dynamic, need to replace with default value', | ||
itemFormat, | ||
) | ||
const defaultValue = formatDefaults[itemFormat] | ||
@@ -69,2 +85,4 @@ for (let k = 0; k < list.length; k += 1) { | ||
} else if (isArrayType(prop) && hasPropertiesArray(prop)) { | ||
debug('property %s is array-like and has properties', key) | ||
const list: PlainObject[] = object[key] as PlainObject[] | ||
@@ -71,0 +89,0 @@ const propSchema: JsonSchema = prop.items as JsonSchema |
68676
1686
303