From 12a29b15068f70f815db3f68282df4e49338e3ce Mon Sep 17 00:00:00 2001 From: jameswilddev Date: Tue, 28 May 2019 01:18:37 +0100 Subject: [PATCH] Added entity types to schemas (fixes #6). --- src/schema.tests.ts | 38 +++++++++++++++++++++++++++++++------- src/schema.ts | 10 +++++++++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/schema.tests.ts b/src/schema.tests.ts index a1fb992..f3b2b47 100644 --- a/src/schema.tests.ts +++ b/src/schema.tests.ts @@ -9,58 +9,82 @@ describe(`schema`, () => { localizationName: {}, title: {}, description: {}, + entityTypes: {}, unexpected: {} }, `instance`, `additionalProperty "unexpected" exists in instance when not allowed`)) describe(`localizations`, () => { describe(`missing`, () => shared.rejects(schema.schema, { localizationName: {}, title: {}, - description: {} + description: {}, + entityTypes: {} }, `instance`, `requires property "localizations"`)) shared.testIdentifierSet(schema.schema, instance => ({ localizations: instance, localizationName: {}, title: {}, - description: {} + description: {}, + entityTypes: {} }), `instance.localizations`) }) describe(`localizationName`, () => { describe(`missing`, () => shared.rejects(schema.schema, { localizations: [], title: {}, - description: {} + description: {}, + entityTypes: {} }, `instance`, `requires property "localizationName"`)) shared.testLocalizedString(schema.schema, instance => ({ localizations: [], localizationName: instance, title: {}, - description: {} + description: {}, + entityTypes: {} }), `instance.localizationName`) }) describe(`title`, () => { describe(`missing`, () => shared.rejects(schema.schema, { localizations: [], localizationName: {}, - description: {} + description: {}, + entityTypes: {} }, `instance`, `requires property "title"`)) shared.testLocalizedString(schema.schema, instance => ({ localizations: [], localizationName: {}, title: instance, - description: {} + description: {}, + entityTypes: {} }), `instance.title`) }) describe(`description`, () => { describe(`missing`, () => shared.rejects(schema.schema, { localizations: [], localizationName: {}, - title: {} + title: {}, + entityTypes: {} }, `instance`, `requires property "description"`)) shared.testLocalizedString(schema.schema, instance => ({ localizations: [], localizationName: {}, title: {}, + entityTypes: {}, description: instance }), `instance.description`) }) + describe(`entityTypes`, () => { + describe(`missing`, () => shared.rejects(schema.schema, { + localizations: [], + localizationName: {}, + title: {}, + description: {} + }, `instance`, `requires property "entityTypes"`)) + shared.testEntityTypeSet(schema.schema, instance => ({ + localizations: [], + localizationName: {}, + title: {}, + description: {}, + entityTypes: instance + }), `instance.entityTypes`) + }) }) diff --git a/src/schema.ts b/src/schema.ts index 278df17..1afe382 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1,6 +1,7 @@ import * as jsonschema from "jsonschema" import * as identifierSet from "./identifier-set" import * as localizedString from "./localized-string" +import * as entityTypeSet from "./entity-type-set" export const schema: jsonschema.Schema = { $schema: `http://json-schema.org/draft-04/schema#`, @@ -12,12 +13,14 @@ export const schema: jsonschema.Schema = { `localizationName`, `title`, `description`, + `entityTypes` ], properties: { localizations: identifierSet.schema, localizationName: localizedString.schema, title: localizedString.schema, - description: localizedString.schema + description: localizedString.schema, + entityTypes: entityTypeSet.schema } } @@ -46,4 +49,9 @@ export type Type = { * localizations. */ readonly description: localizedString.Type + + /** + * Maps entity type identifiers to schemas. + */ + readonly entityTypes: entityTypeSet.Type }