|
| 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 | +}); |
0 commit comments