Skip to content

Commit

Permalink
Fix bugs in annotatedWith
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesrosiers committed Jan 11, 2024
1 parent b6d11f6 commit 39989b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion annotations/annotated-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const annotate = (instance, keyword, value) => {
export const annotatedWith = (instance, keyword, dialectId = defaultDialectId) => {
const instances = [];

const keywordId = getKeywordId(dialectId, keyword);
const keywordId = getKeywordId(keyword, dialectId);
for (const instancePointer in instance.annotations) {
if (keywordId in instance.annotations[instancePointer]) {
instances.push(get(`#${instancePointer}`, instance));
Expand Down
9 changes: 8 additions & 1 deletion lib/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { toAbsoluteUri } from "./common.js";


const _keywords = {};
export const getKeyword = (id) => _keywords[toAbsoluteUri(id)];
export const getKeyword = (id) => {
if (id.indexOf("#") !== -1) {
const absoluteId = toAbsoluteUri(id);
return { ..._keywords[absoluteId], id };
}

return _keywords[id];
};

export const getKeywordByName = (keyword, dialectId) => {
const keywordId = getKeywordId(keyword, dialectId);
Expand Down
2 changes: 1 addition & 1 deletion lib/keywords/requireAllExcept.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const id = "https://json-schema.org/keyword/requireAllExcept";

const compile = async (schema, _ast, parentSchema) => {
const requireAllExcept = await Browser.value(schema);
const propertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/properties");
const propertiesKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/properties");
const propertiesSchema = await Browser.step(propertiesKeyword, parentSchema);
const propertyNames = Browser.typeOf(propertiesSchema) === "object" ? Browser.keys(propertiesSchema) : [];

Expand Down

0 comments on commit 39989b6

Please sign in to comment.