Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Added entity types to schemas (fixes #6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed May 28, 2019
1 parent d18d59d commit 12a29b1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
38 changes: 31 additions & 7 deletions src/schema.tests.ts
Expand Up @@ -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`)
})
})
10 changes: 9 additions & 1 deletion 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#`,
Expand All @@ -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
}
}

Expand Down Expand Up @@ -46,4 +49,9 @@ export type Type = {
* localizations.
*/
readonly description: localizedString.Type

/**
* Maps entity type identifiers to schemas.
*/
readonly entityTypes: entityTypeSet.Type
}

0 comments on commit 12a29b1

Please sign in to comment.