Skip to content

Commit

Permalink
chore: update types, update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Nov 26, 2019
1 parent 7a2b2df commit d96b9e1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 40 deletions.
28 changes: 24 additions & 4 deletions src/ValidationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,35 @@ const SPECIFICITY = {
absolutePath: 2,
};

/**
* @param {Schema | boolean} [schema]
* @returns {schema is Schema}
*/
function hasType(schema) {
return (schema && typeof schema !== 'boolean') || false;
}

/**
*
* @param {Schema} schema
* @return {(property: string) => string}
*/
function createPropertyFormatter(schema) {
const required = new Set(schema.required || []);
/** @type {(property: string) => string} */
const format = (property) => property + (required.has(property) ? '' : '?');

return function formatProperty(property) {
const { type } =
typeof schema.properties === 'object' && schema.properties !== null
? schema.properties[property] || {}
: {};
let type;

if (typeof schema.properties === 'object' && schema.properties !== null) {
const subSchema = schema.properties[property];

if (hasType(subSchema)) {
type = subSchema.type;
}
}

const name = format(property);

if (type) {
Expand Down
Loading

0 comments on commit d96b9e1

Please sign in to comment.