@cypress/schema-tools
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -6,5 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify")); | ||
var json2md_1 = __importDefault(require("json2md")); | ||
var quote_1 = __importDefault(require("quote")); | ||
var ramda_1 = require("ramda"); | ||
@@ -14,3 +12,2 @@ var __1 = require(".."); | ||
var utils_1 = require("./utils"); | ||
var ticks = quote_1.default({ quotes: '`' }); | ||
var title = [{ h1: 'Schemas' }]; | ||
@@ -29,28 +26,8 @@ var titleLink = [{ p: '[🔝](#schemas)' }]; | ||
} | ||
var schemaDoc = utils_1.documentSchema(schema.schema, schemas, formats); | ||
var start = [{ h3: schemaName + "@" + version }]; | ||
if (schema.package) { | ||
start.push({ | ||
p: "Defined in " + ticks(schema.package), | ||
}); | ||
} | ||
if (schema.schema.description) { | ||
start.push({ p: schema.schema.description }); | ||
} | ||
var example = __1.getExample(schemas)(schemaName)(version); | ||
var exampleFragment = ramda_1.flatten([ | ||
schemaDoc, | ||
{ p: 'Example:' }, | ||
{ | ||
code: { | ||
language: 'json', | ||
content: json_stable_stringify_1.default(example, { space: ' ' }), | ||
}, | ||
}, | ||
titleLink, | ||
]); | ||
return ramda_1.flatten(start.concat(exampleFragment)); | ||
var schemaDoc = utils_1.documentObjectSchema(schema, schemas, formats); | ||
return ramda_1.flatten(schemaDoc.concat(titleLink)); | ||
}; | ||
var versionFragments = versions.map(documentSchemaVersion); | ||
return [{ h2: __1.normalizeName(schemaName) }].concat(ramda_1.flatten(versionFragments)); | ||
var start = [{ h2: __1.normalizeName(schemaName) }]; | ||
return start.concat(ramda_1.flatten(versionFragments)); | ||
}; | ||
@@ -57,0 +34,0 @@ var fragments = ramda_1.flatten(__1.schemaNames(schemas).map(toDoc)); |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify")); | ||
var quote_1 = __importDefault(require("quote")); | ||
@@ -71,2 +72,5 @@ var ramda_1 = require("ramda"); | ||
var typeText = function (type) { return (Array.isArray(type) ? type.join(' or ') : type); }; | ||
var deprecatedMessage = function (value) { | ||
return value.deprecated ? "**deprecated** " + value.deprecated : exports.emptyMark; | ||
}; | ||
return Object.keys(properties) | ||
@@ -83,2 +87,3 @@ .sort() | ||
description: value.description ? value.description : exports.emptyMark, | ||
deprecated: deprecatedMessage(value), | ||
}; | ||
@@ -98,2 +103,3 @@ }); | ||
'description', | ||
'deprecated', | ||
]; | ||
@@ -120,1 +126,36 @@ var usedHeaders = exports.findUsedColumns(headers, rows); | ||
}; | ||
var schemaNameHeading = function (name, version) { | ||
return name + "@" + version; | ||
}; | ||
exports.documentObjectSchema = function (schema, schemas, formats) { | ||
var schemaName = schema.schema.title; | ||
if (schemaName.includes(' ')) { | ||
throw new Error("Schema title contains spaces \"" + schemaName + "\"\n This can cause problems generating anchors!"); | ||
} | ||
var schemaVersion = __1.semverToString(schema.version); | ||
var start = [{ h3: schemaNameHeading(schemaName, schemaVersion) }]; | ||
if (schema.package) { | ||
start.push({ | ||
p: "Defined in " + ticks(schema.package), | ||
}); | ||
} | ||
if (schema.schema.description) { | ||
start.push({ p: schema.schema.description }); | ||
} | ||
if (schema.schema.deprecated) { | ||
start.push({ | ||
p: "**deprecated** " + schema.schema.deprecated, | ||
}); | ||
} | ||
var propertiesTable = exports.documentSchema(schema.schema, schemas, formats); | ||
var exampleFragment = ramda_1.flatten([ | ||
{ p: 'Example:' }, | ||
{ | ||
code: { | ||
language: 'json', | ||
content: json_stable_stringify_1.default(schema.example, { space: ' ' }), | ||
}, | ||
}, | ||
]); | ||
return ramda_1.flatten(start.concat(propertiesTable).concat(exampleFragment)); | ||
}; |
{ | ||
"name": "@cypress/schema-tools", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Validate, sanitize and document JSON schemas", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
// generates Markdown document with all schema information | ||
import stringify from 'json-stable-stringify' | ||
import json2md from 'json2md' | ||
import quote from 'quote' | ||
import { flatten } from 'ramda' | ||
import { | ||
getExample, | ||
getObjectSchema, | ||
@@ -17,5 +14,5 @@ getSchemaVersions, | ||
import { documentCustomFormats } from './doc-formats' | ||
import { anchor, documentSchema } from './utils' | ||
import { anchor, documentObjectSchema } from './utils' | ||
const ticks = quote({ quotes: '`' }) | ||
// const ticks = quote({ quotes: '`' }) | ||
const title = [{ h1: 'Schemas' }] | ||
@@ -50,27 +47,5 @@ const titleLink = [{ p: '[🔝](#schemas)' }] | ||
const schemaDoc = documentSchema(schema.schema, schemas, formats) | ||
const schemaDoc = documentObjectSchema(schema, schemas, formats) | ||
const start: any[] = [{ h3: `${schemaName}@${version}` }] | ||
if (schema.package) { | ||
start.push({ | ||
p: `Defined in ${ticks(schema.package)}`, | ||
}) | ||
} | ||
if (schema.schema.description) { | ||
start.push({ p: schema.schema.description }) | ||
} | ||
const example = getExample(schemas)(schemaName)(version) | ||
const exampleFragment = flatten([ | ||
schemaDoc, | ||
{ p: 'Example:' }, | ||
{ | ||
code: { | ||
language: 'json', | ||
content: stringify(example, { space: ' ' }), | ||
}, | ||
}, | ||
titleLink, | ||
]) | ||
return flatten(start.concat(exampleFragment)) | ||
return flatten(schemaDoc.concat(titleLink)) | ||
} | ||
@@ -80,3 +55,4 @@ | ||
return [{ h2: normalizeName(schemaName) }].concat(flatten(versionFragments)) | ||
const start: object[] = [{ h2: normalizeName(schemaName) }] | ||
return start.concat(flatten(versionFragments)) | ||
} | ||
@@ -104,6 +80,2 @@ | ||
// const extractH2 = map(prop('h2')) | ||
// const filterH2 = filter(has('h2')) | ||
// const headings = extractH2(filterH2(fragments)) | ||
const headings = schemaNames(schemas) | ||
@@ -110,0 +82,0 @@ const toc = [ |
@@ -0,3 +1,4 @@ | ||
import stringify from 'json-stable-stringify' | ||
import quote from 'quote' | ||
import { find, toLower } from 'ramda' | ||
import { find, flatten, toLower } from 'ramda' | ||
import { normalizeName, schemaNames, semverToString } from '..' | ||
@@ -109,2 +110,4 @@ import { CustomFormats } from '../formats' | ||
const typeText = type => (Array.isArray(type) ? type.join(' or ') : type) | ||
const deprecatedMessage = (value: JsonProperty) => | ||
value.deprecated ? `**deprecated** ${value.deprecated}` : emptyMark | ||
@@ -122,2 +125,3 @@ return Object.keys(properties) | ||
description: value.description ? value.description : emptyMark, | ||
deprecated: deprecatedMessage(value), | ||
} | ||
@@ -148,2 +152,3 @@ }) | ||
'description', | ||
'deprecated', | ||
] | ||
@@ -169,1 +174,49 @@ const usedHeaders = findUsedColumns(headers, rows) | ||
} | ||
const schemaNameHeading = (name: string, version: string) => | ||
`${name}@${version}` | ||
export const documentObjectSchema = ( | ||
schema: ObjectSchema, | ||
schemas?: SchemaCollection, | ||
formats?: CustomFormats, | ||
) => { | ||
const schemaName = schema.schema.title | ||
if (schemaName.includes(' ')) { | ||
throw new Error(`Schema title contains spaces "${schemaName}" | ||
This can cause problems generating anchors!`) | ||
} | ||
const schemaVersion = semverToString(schema.version) | ||
const start: object[] = [{ h3: schemaNameHeading(schemaName, schemaVersion) }] | ||
if (schema.package) { | ||
start.push({ | ||
p: `Defined in ${ticks(schema.package)}`, | ||
}) | ||
} | ||
if (schema.schema.description) { | ||
start.push({ p: schema.schema.description }) | ||
} | ||
if (schema.schema.deprecated) { | ||
start.push({ | ||
p: `**deprecated** ${schema.schema.deprecated}`, | ||
}) | ||
} | ||
const propertiesTable = documentSchema(schema.schema, schemas, formats) | ||
const exampleFragment = flatten([ | ||
{ p: 'Example:' }, | ||
{ | ||
code: { | ||
language: 'json', | ||
content: stringify(schema.example, { space: ' ' }), | ||
}, | ||
}, | ||
]) | ||
return flatten(start.concat(propertiesTable).concat(exampleFragment)) | ||
} |
@@ -55,2 +55,4 @@ /** | ||
enum?: string[] | ||
// if the property is deprecated show this message | ||
deprecated?: string | ||
} | ||
@@ -73,2 +75,3 @@ | ||
additionalProperties: boolean | ||
deprecated?: string | ||
} | ||
@@ -75,0 +78,0 @@ |
74030
1833