Skip to content

added getAllSchema function #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getSchema: (uri: string, browser?: Browser) => Promise<Browser<Sche
export const buildSchemaDocument: (schema: SchemaObject | boolean, retrievalUri?: string, contextDialectId?: string) => SchemaDocument;
export const canonicalUri: (browser: Browser<SchemaDocument>) => string;
export const toSchema: (browser: Browser<SchemaDocument>, options?: ToSchemaOptions) => SchemaObject;
export const getAllSchemas: () => string[];

export type ToSchemaOptions = {
contextDialectId?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export {
defineVocabulary,
loadDialect, unloadDialect, hasDialect
} from "./keywords.js";
export { getSchema, toSchema, canonicalUri, buildSchemaDocument } from "./schema.js";
export { getSchema, toSchema, canonicalUri, buildSchemaDocument, getAllSchemas } from "./schema.js";
export { default as Validation } from "./keywords/validation.js";
115 changes: 115 additions & 0 deletions lib/get-all-schemas.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { test, expect, describe } from "vitest";
import { getAllSchemas } from "./experimental.js";
import { registerSchema } from "./schema.js";
import "../draft-2020-12/index.js";
import "../draft-2019-09/index.js";
import "../draft-04/index.js";
import "../draft-06/index.js";
import "../draft-07/index.js";
import "../openapi-3-0/index.js";
import "../openapi-3-1/index.js";
import "../stable/index.js";

Check failure on line 11 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected 2 empty lines after import statement not followed by another import

Check failure on line 11 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected 2 empty lines after import statement not followed by another import

describe("getAllSchemas function", () => {
test("should return all registered schema URIs", () => {
const schemaUris = getAllSchemas();
expect(schemaUris).toEqual([
"https://json-schema.org/draft/2020-12/schema",
"https://json-schema.org/draft/2020-12/meta/core",
"https://json-schema.org/draft/2020-12/meta/applicator",
"https://json-schema.org/draft/2020-12/meta/validation",
"https://json-schema.org/draft/2020-12/meta/meta-data",
"https://json-schema.org/draft/2020-12/meta/format-annotation",
"https://json-schema.org/draft/2020-12/meta/format-assertion",
"https://json-schema.org/draft/2020-12/meta/content",
"https://json-schema.org/draft/2020-12/meta/unevaluated",
"https://json-schema.org/draft/2019-09/schema",
"https://json-schema.org/draft/2019-09/meta/core",
"https://json-schema.org/draft/2019-09/meta/applicator",
"https://json-schema.org/draft/2019-09/meta/validation",
"https://json-schema.org/draft/2019-09/meta/meta-data",
"https://json-schema.org/draft/2019-09/meta/format",
"https://json-schema.org/draft/2019-09/meta/content",
"http://json-schema.org/draft-04/schema",
"http://json-schema.org/draft-06/schema",
"http://json-schema.org/draft-07/schema",
"https://spec.openapis.org/oas/3.0/dialect",
"https://spec.openapis.org/oas/3.0/schema",
"https://spec.openapis.org/oas/3.0/schema/latest",
"https://spec.openapis.org/oas/3.1/meta/base",
"https://spec.openapis.org/oas/3.1/dialect/base",
"https://spec.openapis.org/oas/3.1/schema",
"https://spec.openapis.org/oas/3.1/schema/latest",
"https://spec.openapis.org/oas/3.1/schema-base",
"https://spec.openapis.org/oas/3.1/schema-base/latest",
"https://spec.openapis.org/oas/3.1/schema-draft-2020-12",
"https://spec.openapis.org/oas/3.1/schema-draft-2019-09",
"https://spec.openapis.org/oas/3.1/schema-draft-07",
"https://spec.openapis.org/oas/3.1/schema-draft-06",
"https://spec.openapis.org/oas/3.1/schema-draft-04",
"https://json-schema.org/validation",
"https://json-schema.org/meta/core",
"https://json-schema.org/meta/applicator",
"https://json-schema.org/meta/validation",
"https://json-schema.org/meta/meta-data",
"https://json-schema.org/meta/format-annotation",
"https://json-schema.org/meta/format-assertion",
"https://json-schema.org/meta/content",
"https://json-schema.org/meta/unevaluated",

Check failure on line 58 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected trailing comma

Check failure on line 58 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected trailing comma
]);
});

test("should return all schemas along with custom registered schemas", () => {
registerSchema({
"$id": "http://example.com/custom-schema",
"$schema": "https://json-schema.org/draft/2020-12/schema"
});

const schemaUris = getAllSchemas();
expect(schemaUris).toEqual([
"https://json-schema.org/draft/2020-12/schema",

Check failure on line 70 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 70 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/core",

Check failure on line 71 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 71 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/applicator",

Check failure on line 72 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 72 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/validation",

Check failure on line 73 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 73 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/meta-data",

Check failure on line 74 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 74 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/format-annotation",

Check failure on line 75 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 75 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/format-assertion",

Check failure on line 76 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 76 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/content",

Check failure on line 77 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 6 spaces but found 8

Check failure on line 77 in lib/get-all-schemas.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 6 spaces but found 8
"https://json-schema.org/draft/2020-12/meta/unevaluated",
"https://json-schema.org/draft/2019-09/schema",
"https://json-schema.org/draft/2019-09/meta/core",
"https://json-schema.org/draft/2019-09/meta/applicator",
"https://json-schema.org/draft/2019-09/meta/validation",
"https://json-schema.org/draft/2019-09/meta/meta-data",
"https://json-schema.org/draft/2019-09/meta/format",
"https://json-schema.org/draft/2019-09/meta/content",
"http://json-schema.org/draft-04/schema",
"http://json-schema.org/draft-06/schema",
"http://json-schema.org/draft-07/schema",
"https://spec.openapis.org/oas/3.0/dialect",
"https://spec.openapis.org/oas/3.0/schema",
"https://spec.openapis.org/oas/3.0/schema/latest",
"https://spec.openapis.org/oas/3.1/meta/base",
"https://spec.openapis.org/oas/3.1/dialect/base",
"https://spec.openapis.org/oas/3.1/schema",
"https://spec.openapis.org/oas/3.1/schema/latest",
"https://spec.openapis.org/oas/3.1/schema-base",
"https://spec.openapis.org/oas/3.1/schema-base/latest",
"https://spec.openapis.org/oas/3.1/schema-draft-2020-12",
"https://spec.openapis.org/oas/3.1/schema-draft-2019-09",
"https://spec.openapis.org/oas/3.1/schema-draft-07",
"https://spec.openapis.org/oas/3.1/schema-draft-06",
"https://spec.openapis.org/oas/3.1/schema-draft-04",
"https://json-schema.org/validation",
"https://json-schema.org/meta/core",
"https://json-schema.org/meta/applicator",
"https://json-schema.org/meta/validation",
"https://json-schema.org/meta/meta-data",
"https://json-schema.org/meta/format-annotation",
"https://json-schema.org/meta/format-assertion",
"https://json-schema.org/meta/content",
"https://json-schema.org/meta/unevaluated",
"http://example.com/custom-schema"
]);
});
});
5 changes: 5 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,8 @@ export const toSchema = (browser, options = {}) => {

return schema;
};

export const getAllSchemas = () => {
const schemaUris = Object.keys(schemaRegistry);
return schemaUris;
}
Loading