Skip to content

Commit 9a74993

Browse files
Azzam1503jdesrosiers
authored andcommitted
Updated test, documentation and keyword.js
1 parent 1828e8f commit 9a74993

File tree

5 files changed

+74
-5
lines changed

5 files changed

+74
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ These are available from the `@hyperjump/json-schema/experimental` export.
565565
566566
Remove a dialect. You shouldn't need to use this function. It's called for
567567
you when you call `unregisterSchema`.
568+
* **getDialectIds**
569+
570+
This function retrieves the identifiers of all loaded JSON Schema dialects.
568571
* **Validation**: Keyword
569572
570573
A Keyword object that represents a "validate" operation. You would use this

lib/experimental.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const defineVocabulary: (id: string, keywords: { [keyword: string]: strin
6363
export const loadDialect: (dialectId: string, dialect: { [vocabularyId: string]: boolean }, allowUnknownKeywords?: boolean) => void;
6464
export const unloadDialect: (dialectId: string) => void;
6565
export const hasDialect: (dialectId: string) => boolean;
66-
export const loadSchemaDialects: () => string[];
66+
export const getDialectIds: () => string[];
6767

6868
export type Keyword<A> = {
6969
id: string;

lib/experimental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export { compile, interpret, BASIC } from "./core.js";
22
export {
33
addKeyword, getKeyword, getKeywordByName, getKeywordName, getKeywordId,
44
defineVocabulary,
5-
loadDialect, unloadDialect, hasDialect, loadSchemaDialects
5+
loadDialect, unloadDialect, hasDialect, getDialectIds
66
} from "./keywords.js";
77
export { getSchema, toSchema, canonicalUri, buildSchemaDocument } from "./schema.js";
88
export { default as Validation } from "./keywords/validation.js";

lib/get-dialect-ids.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { test, expect, describe } from "vitest";
2+
import { getDialectIds, loadDialect } from "./keywords.js";
3+
import "../draft-2020-12";
4+
import "../draft-2019-09";
5+
import "../draft-04";
6+
import "../draft-06";
7+
import "../draft-07";
8+
import "../openapi-3-0";
9+
import "../openapi-3-1";
10+
import "../stable";
11+
12+
13+
describe("getDialectIds function", () => {
14+
test("should return only imported schema in the array if no custom dialects are loaded", () => {
15+
const dialectIds = getDialectIds();
16+
expect(dialectIds).toEqual([
17+
"https://json-schema.org/draft/2020-12/schema",
18+
"https://json-schema.org/draft/2019-09/schema",
19+
"http://json-schema.org/draft-04/schema",
20+
"http://json-schema.org/draft-06/schema",
21+
"http://json-schema.org/draft-07/schema",
22+
"https://spec.openapis.org/oas/3.0/dialect",
23+
"https://spec.openapis.org/oas/3.0/schema",
24+
"https://spec.openapis.org/oas/3.1/dialect/base",
25+
"https://spec.openapis.org/oas/3.1/schema-base",
26+
"https://spec.openapis.org/oas/3.1/schema-base/latest",
27+
"https://spec.openapis.org/oas/3.1/schema-draft-2020-12",
28+
"https://spec.openapis.org/oas/3.1/schema-draft-2019-09",
29+
"https://spec.openapis.org/oas/3.1/schema-draft-07",
30+
"https://spec.openapis.org/oas/3.1/schema-draft-06",
31+
"https://spec.openapis.org/oas/3.1/schema-draft-04",
32+
"https://json-schema.org/validation"
33+
]);
34+
});
35+
36+
test("returns an array of dialect identifiers that are either imported in the file or loaded as custom dialects", () => {
37+
//Load some dialects before each test
38+
loadDialect("http://example.com/dialect1", {
39+
"https://json-schema.org/draft/2020-12/vocab/core": true,
40+
"https://json-schema.org/draft/2020-12/vocab/applicator": true
41+
});
42+
loadDialect("http://example.com/dialect2", {
43+
"https://json-schema.org/draft/2020-12/vocab/core": true,
44+
"https://json-schema.org/draft/2020-12/vocab/applicator": true
45+
});
46+
const dialectIds = getDialectIds();
47+
expect(dialectIds).toEqual([
48+
"https://json-schema.org/draft/2020-12/schema",
49+
"https://json-schema.org/draft/2019-09/schema",
50+
"http://json-schema.org/draft-04/schema",
51+
"http://json-schema.org/draft-06/schema",
52+
"http://json-schema.org/draft-07/schema",
53+
"https://spec.openapis.org/oas/3.0/dialect",
54+
"https://spec.openapis.org/oas/3.0/schema",
55+
"https://spec.openapis.org/oas/3.1/dialect/base",
56+
"https://spec.openapis.org/oas/3.1/schema-base",
57+
"https://spec.openapis.org/oas/3.1/schema-base/latest",
58+
"https://spec.openapis.org/oas/3.1/schema-draft-2020-12",
59+
"https://spec.openapis.org/oas/3.1/schema-draft-2019-09",
60+
"https://spec.openapis.org/oas/3.1/schema-draft-07",
61+
"https://spec.openapis.org/oas/3.1/schema-draft-06",
62+
"https://spec.openapis.org/oas/3.1/schema-draft-04",
63+
"https://json-schema.org/validation",
64+
"http://example.com/dialect1",
65+
"http://example.com/dialect2"
66+
]);
67+
});
68+
});

lib/keywords.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,4 @@ export const unloadDialect = (dialectId) => {
8787
delete _dialects[dialectId];
8888
};
8989

90-
export const loadSchemaDialects = () => {
91-
return Object.keys(_dialects).filter((key) => hasDialect(key));
92-
};
90+
export const getDialectIds = () => Object.keys(_dialects);

0 commit comments

Comments
 (0)