Skip to content

Commit d96b9e1

Browse files
committed
chore: update types, update snapshot
1 parent 7a2b2df commit d96b9e1

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

src/ValidationError.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,35 @@ const SPECIFICITY = {
4444
absolutePath: 2,
4545
};
4646

47+
/**
48+
* @param {Schema | boolean} [schema]
49+
* @returns {schema is Schema}
50+
*/
51+
function hasType(schema) {
52+
return (schema && typeof schema !== 'boolean') || false;
53+
}
54+
55+
/**
56+
*
57+
* @param {Schema} schema
58+
* @return {(property: string) => string}
59+
*/
4760
function createPropertyFormatter(schema) {
4861
const required = new Set(schema.required || []);
62+
/** @type {(property: string) => string} */
4963
const format = (property) => property + (required.has(property) ? '' : '?');
5064

5165
return function formatProperty(property) {
52-
const { type } =
53-
typeof schema.properties === 'object' && schema.properties !== null
54-
? schema.properties[property] || {}
55-
: {};
66+
let type;
67+
68+
if (typeof schema.properties === 'object' && schema.properties !== null) {
69+
const subSchema = schema.properties[property];
70+
71+
if (hasType(subSchema)) {
72+
type = subSchema.type;
73+
}
74+
}
75+
5676
const name = format(property);
5777

5878
if (type) {

0 commit comments

Comments
 (0)