Skip to content

Commit

Permalink
cleanup: minor addSchemasArrayToMap refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Oct 9, 2022
1 parent 2f70ef6 commit c968c16
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ const hasKeywords = (schema, keywords) =>
const addSchemasArrayToMap = (schemas, input, optional = false) => {
if (!Array.isArray(input)) throw new Error('Expected an array of schemas')
// schema ids are extracted from the schemas themselves
const cleanId = (id) =>
// # is allowed only as the last symbol here
id && typeof id === 'string' && !/#./.test(id) ? id.replace(/#$/, '') : null
for (const schema of input) {
traverse(schema, (sub) => {
const id = cleanId(sub.$id || sub.id)
if (id && id.includes('://')) {
const idRaw = sub.$id || sub.id
const id = idRaw && typeof idRaw === 'string' ? idRaw.replace(/#$/, '') : null // # is allowed only as the last symbol here
if (id && id.includes('://') && !id.includes('#')) {
safeSet(schemas, id, sub, "schema $id in 'schemas'")
} else if (sub === schema && !optional) {
throw new Error("Schema with missing or invalid $id in 'schemas'")
Expand Down

0 comments on commit c968c16

Please sign in to comment.