1 | /**
|
2 | * Module for defining a `JsonSchema` interface for use by other modules
|
3 | * in this repository e.g. generation of `*.json.schema` files by `./schema.ts`.
|
4 | */
|
5 | import { JSONSchema7 } from 'json-schema';
|
6 | /**
|
7 | * Interface for Stencila `JsonSchema` instances.
|
8 | *
|
9 | * The `JsonSchema` interface extends JSON Schema
|
10 | * with additional properties for:
|
11 | *
|
12 | * - defining inheritance,
|
13 | * - defining property aliases
|
14 | * - specifying codecs used in coercion
|
15 | * - categorizing node types
|
16 | *
|
17 | * For more details see the guidelines for authoring schemas.
|
18 | */
|
19 | export interface JsonSchema extends JSONSchema7 {
|
20 | /**
|
21 | * The id for the type or property schema to be used
|
22 | * when generating JSON-LD.
|
23 | */
|
24 | '@id'?: string;
|
25 | /**
|
26 | * The role that this schema has.
|
27 | */
|
28 | role?: 'base' | 'primary' | 'secondary' | 'tertiary';
|
29 | /**
|
30 | * The current status of this schema.
|
31 | */
|
32 | status?: 'experimental' | 'unstable' | 'stable';
|
33 | /**
|
34 | * The category of node that this schema belongs to.
|
35 | */
|
36 | category?: string;
|
37 | /**
|
38 | * The schema that this schema extends.
|
39 | */
|
40 | extends?: string;
|
41 | /**
|
42 | * The names of the child (direct descendants) schemas of this schema.
|
43 | * Added during schema processing.
|
44 | */
|
45 | children?: string[];
|
46 | /**
|
47 | * The descendant schemas of this schema.
|
48 | * Added during schema processing.
|
49 | */
|
50 | descendants?: string[];
|
51 | /**
|
52 | * The schema from which this property schema was inherited.
|
53 | * Only applies when used in a property of another schema.
|
54 | * Added during schema processing.
|
55 | */
|
56 | from?: string;
|
57 | /**
|
58 | * Is this property schema an override of a property inherited
|
59 | * from an ancestor. Examples of overrides include making an
|
60 | * optional property required, or changing the schema of the property.
|
61 | */
|
62 | isOverride?: boolean;
|
63 | /**
|
64 | * Is the property an array?
|
65 | */
|
66 | isArray?: boolean;
|
67 | /**
|
68 | * Is the property an array and have a pluralized name e.g. authors
|
69 | */
|
70 | isPlural?: boolean;
|
71 | /**
|
72 | * Aliases for this property schema.
|
73 | * Only applies when used in a property of another schema.
|
74 | */
|
75 | aliases?: string[];
|
76 | /**
|
77 | * A map of property aliases.
|
78 | * Added during schema processing based on the `aliases`
|
79 | * of properties.
|
80 | */
|
81 | propertyAliases?: {
|
82 | [key: string]: string;
|
83 | };
|
84 | /**
|
85 | * The name of a parser that can be used to decode
|
86 | * values for this schema.
|
87 | */
|
88 | parser?: string;
|
89 | /**
|
90 | * The file in which this schema is defined.
|
91 | * Added during schema processing.
|
92 | */
|
93 | file?: string;
|
94 | /**
|
95 | * The source file for this schema. A URL that can be used to
|
96 | * provide a link to view or edit the source.
|
97 | */
|
98 | source?: string;
|
99 | properties?: {
|
100 | [key: string]: JsonSchema;
|
101 | };
|
102 | allOf?: JsonSchema[];
|
103 | anyOf?: JsonSchema[];
|
104 | items?: JsonSchema[];
|
105 | enum?: (string | number)[];
|
106 | }
|