@loopback/repository-json-schema 4.0.0-alpha.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -10
  3. package/dist/build-schema.d.ts +137 -0
  4. package/dist/build-schema.js +445 -0
  5. package/dist/build-schema.js.map +1 -0
  6. package/dist/filter-json-schema.d.ts +54 -0
  7. package/dist/filter-json-schema.js +198 -0
  8. package/dist/filter-json-schema.js.map +1 -0
  9. package/dist/index.d.ts +36 -1
  10. package/dist/index.js +18 -7
  11. package/dist/index.js.map +1 -0
  12. package/dist/keys.d.ts +8 -0
  13. package/dist/keys.js +13 -0
  14. package/dist/keys.js.map +1 -0
  15. package/package.json +42 -33
  16. package/src/build-schema.ts +491 -79
  17. package/src/filter-json-schema.ts +237 -0
  18. package/src/index.ts +42 -1
  19. package/src/keys.ts +15 -0
  20. package/CHANGELOG.md +0 -83
  21. package/api-docs/apple-touch-icon-114x114-precomposed.png +0 -0
  22. package/api-docs/apple-touch-icon-144x144-precomposed.png +0 -0
  23. package/api-docs/apple-touch-icon-57x57-precomposed.png +0 -0
  24. package/api-docs/apple-touch-icon-72x72-precomposed.png +0 -0
  25. package/api-docs/apple-touch-icon-precomposed.png +0 -0
  26. package/api-docs/apple-touch-icon.png +0 -0
  27. package/api-docs/css/bootstrap.min.css +0 -9
  28. package/api-docs/css/code-themes/arta.css +0 -158
  29. package/api-docs/css/code-themes/ascetic.css +0 -50
  30. package/api-docs/css/code-themes/brown_paper.css +0 -104
  31. package/api-docs/css/code-themes/brown_papersq.png +0 -0
  32. package/api-docs/css/code-themes/dark.css +0 -103
  33. package/api-docs/css/code-themes/default.css +0 -135
  34. package/api-docs/css/code-themes/far.css +0 -111
  35. package/api-docs/css/code-themes/github.css +0 -127
  36. package/api-docs/css/code-themes/googlecode.css +0 -144
  37. package/api-docs/css/code-themes/idea.css +0 -121
  38. package/api-docs/css/code-themes/ir_black.css +0 -104
  39. package/api-docs/css/code-themes/magula.css +0 -121
  40. package/api-docs/css/code-themes/monokai.css +0 -114
  41. package/api-docs/css/code-themes/pojoaque.css +0 -104
  42. package/api-docs/css/code-themes/pojoaque.jpg +0 -0
  43. package/api-docs/css/code-themes/rainbow.css +0 -114
  44. package/api-docs/css/code-themes/school_book.css +0 -111
  45. package/api-docs/css/code-themes/school_book.png +0 -0
  46. package/api-docs/css/code-themes/sl-theme.css +0 -45
  47. package/api-docs/css/code-themes/solarized_dark.css +0 -88
  48. package/api-docs/css/code-themes/solarized_light.css +0 -88
  49. package/api-docs/css/code-themes/sunburst.css +0 -158
  50. package/api-docs/css/code-themes/tomorrow-night-blue.css +0 -52
  51. package/api-docs/css/code-themes/tomorrow-night-bright.css +0 -51
  52. package/api-docs/css/code-themes/tomorrow-night-eighties.css +0 -51
  53. package/api-docs/css/code-themes/tomorrow-night.css +0 -52
  54. package/api-docs/css/code-themes/tomorrow.css +0 -49
  55. package/api-docs/css/code-themes/vs.css +0 -86
  56. package/api-docs/css/code-themes/xcode.css +0 -154
  57. package/api-docs/css/code-themes/zenburn.css +0 -115
  58. package/api-docs/css/main.css +0 -139
  59. package/api-docs/favicon.ico +0 -0
  60. package/api-docs/fonts/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  61. package/api-docs/fonts/OsJ2DjdpjqFRVUSto6IffLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  62. package/api-docs/fonts/_aijTyevf54tkVDLy-dlnLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
  63. package/api-docs/index.html +0 -717
  64. package/api-docs/js/main.js +0 -19
  65. package/api-docs/js/vendor/bootstrap.min.js +0 -6
  66. package/api-docs/js/vendor/jquery-1.10.1.min.js +0 -6
  67. package/api-docs/js/vendor/jquery.scrollTo-1.4.3.1.js +0 -218
  68. package/api-docs/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js +0 -11
  69. package/dist/src/build-schema.d.ts +0 -50
  70. package/dist/src/build-schema.js +0 -143
  71. package/dist/src/build-schema.js.map +0 -1
  72. package/dist/src/index.d.ts +0 -1
  73. package/dist/src/index.js +0 -11
  74. package/dist/src/index.js.map +0 -1
  75. package/index.d.ts +0 -6
  76. package/index.js +0 -6
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) IBM Corp. 2018. All Rights Reserved.
1
+ Copyright (c) IBM Corp. 2018,2019.
2
2
  Node module: @loopback/repository-json-schema
3
3
  This project is licensed under the MIT License, full text below.
4
4
 
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # @loopback/repository-json-schema
2
2
 
3
- Convert a TypeScript class/model to a JSON Schema for users, leveraging LoopBack4's decorators, metadata, and reflection system.
3
+ Convert a TypeScript class/model to a JSON Schema for users, leveraging
4
+ LoopBack4's decorators, metadata, and reflection system.
4
5
 
5
6
  ## Overview
6
7
 
7
- This package provides modules to easily convert LoopBack4 models that have been decorated with `@model` and `@property` to a matching JSON Schema Definition.
8
+ This package provides modules to easily convert LoopBack4 models that have been
9
+ decorated with `@model` and `@property` to a matching JSON Schema Definition.
8
10
 
9
11
  ## Installation
10
12
 
@@ -19,8 +21,9 @@ import {getJsonSchema} from '@loopback/repository-json-schema';
19
21
  import {model, property} from '@loopback/repository';
20
22
 
21
23
  @model()
22
- MyModel {
23
- @property() name: string;
24
+ class MyModel {
25
+ @property()
26
+ name: string;
24
27
  }
25
28
 
26
29
  const jsonSchema = getJsonSchema(MyModel);
@@ -41,16 +44,18 @@ The value of `jsonSchema` will be:
41
44
 
42
45
  ## Contributions
43
46
 
44
- IBM/StrongLoop is an active supporter of open source and welcomes contributions to our projects as well as those of the Node.js community in general. For more information on how to contribute please refer to the [Contribution Guide](https://loopback.io/doc/en/contrib/index.html).
47
+ - [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
48
+ - [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
45
49
 
46
- # Tests
50
+ ## Tests
47
51
 
48
- run `npm test` from the root folder.
52
+ Run `npm test` from the root folder.
49
53
 
50
- # Contributors
54
+ ## Contributors
51
55
 
52
- See [all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).
56
+ See
57
+ [all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
53
58
 
54
- # License
59
+ ## License
55
60
 
56
61
  MIT
@@ -0,0 +1,137 @@
1
+ import { PropertyDefinition, PropertyType, RelationMetadata } from '@loopback/repository';
2
+ import { JsonSchema } from './index';
3
+ export interface JsonSchemaOptions<T extends object> {
4
+ /**
5
+ * The title to use in the generated schema.
6
+ *
7
+ * When using options like `exclude`, the auto-generated title can be
8
+ * difficult to read for humans. Use this option to change the title to
9
+ * a more meaningful value.
10
+ */
11
+ title?: string;
12
+ /**
13
+ * Set this flag if you want the schema to define navigational properties
14
+ * for model relations.
15
+ */
16
+ includeRelations?: boolean;
17
+ /**
18
+ * Set this flag to mark all model properties as optional. This is typically
19
+ * used to describe request body of PATCH endpoints. This option will be
20
+ * overridden by the "optional" option if it is set and non-empty.
21
+ *
22
+ * The flag also applies to nested model instances if its value is set to
23
+ * 'deep', such as:
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * @model()
28
+ * class Address {
29
+ * @property()
30
+ * street: string;
31
+ * @property()
32
+ * city: string;
33
+ * @property()
34
+ * state: string;
35
+ * @property()
36
+ * zipCode: string;
37
+ * }
38
+ *
39
+ * @model()
40
+ * class Customer {
41
+ * @property()
42
+ * address: Address;
43
+ * }
44
+ *
45
+ * // The following schema allows properties of `customer` optional, but not
46
+ * // `customer.address`
47
+ * const schemaRef1 = getModelSchemaRef(Customer, {partial: true});
48
+ *
49
+ * // The following schema allows properties of `customer` and
50
+ * // `customer.address` optional
51
+ * const schemaRef2 = getModelSchemaRef(Customer, {partial: 'deep'});
52
+ * ```
53
+ */
54
+ partial?: boolean | 'deep';
55
+ /**
56
+ * List of model properties to exclude from the schema.
57
+ */
58
+ exclude?: (keyof T)[];
59
+ /**
60
+ * List of model properties to mark as optional. Overrides the "partial"
61
+ * option if it is not empty.
62
+ */
63
+ optional?: (keyof T)[];
64
+ /**
65
+ * @internal
66
+ */
67
+ visited?: {
68
+ [key: string]: JsonSchema;
69
+ };
70
+ }
71
+ /**
72
+ * @internal
73
+ */
74
+ export declare function buildModelCacheKey<T extends object>(options?: JsonSchemaOptions<T>): string;
75
+ /**
76
+ * Gets the JSON Schema of a TypeScript model/class by seeing if one exists
77
+ * in a cache. If not, one is generated and then cached.
78
+ * @param ctor - Constructor of class to get JSON Schema from
79
+ */
80
+ export declare function getJsonSchema<T extends object>(ctor: Function & {
81
+ prototype: T;
82
+ }, options?: JsonSchemaOptions<T>): JsonSchema;
83
+ /**
84
+ * Describe the provided Model as a reference to a definition shared by multiple
85
+ * endpoints. The definition is included in the returned schema.
86
+ *
87
+ * @example
88
+ *
89
+ * ```ts
90
+ * const schema = {
91
+ * $ref: '/definitions/Product',
92
+ * definitions: {
93
+ * Product: {
94
+ * title: 'Product',
95
+ * properties: {
96
+ * // etc.
97
+ * }
98
+ * }
99
+ * }
100
+ * }
101
+ * ```
102
+ *
103
+ * @param modelCtor - The model constructor (e.g. `Product`)
104
+ * @param options - Additional options
105
+ */
106
+ export declare function getJsonSchemaRef<T extends object>(modelCtor: Function & {
107
+ prototype: T;
108
+ }, options?: JsonSchemaOptions<T>): JsonSchema;
109
+ /**
110
+ * Gets the wrapper function of primitives string, number, and boolean
111
+ * @param type - Name of type
112
+ */
113
+ export declare function stringTypeToWrapper(type: string | Function): Function;
114
+ /**
115
+ * Determines whether a given string or constructor is array type or not
116
+ * @param type - Type as string or wrapper
117
+ */
118
+ export declare function isArrayType(type: string | Function | PropertyType): boolean;
119
+ /**
120
+ * Converts property metadata into a JSON property definition
121
+ * @param meta
122
+ */
123
+ export declare function metaToJsonProperty(meta: PropertyDefinition): JsonSchema;
124
+ /**
125
+ * Checks and return navigational property definition for the relation
126
+ * @param relMeta Relation metadata object
127
+ * @param targetRef Schema definition for the target model
128
+ */
129
+ export declare function getNavigationalPropertyForRelation(relMeta: RelationMetadata, targetRef: JsonSchema): JsonSchema;
130
+ /**
131
+ * Converts a TypeScript class into a JSON Schema using TypeScript's
132
+ * reflection API
133
+ * @param ctor - Constructor of class to convert from
134
+ */
135
+ export declare function modelToJsonSchema<T extends object>(ctor: Function & {
136
+ prototype: T;
137
+ }, jsonSchemaOptions?: JsonSchemaOptions<T>): JsonSchema;
@@ -0,0 +1,445 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2018,2020. All Rights Reserved.
3
+ // Node module: @loopback/repository-json-schema
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.modelToJsonSchema = exports.getNavigationalPropertyForRelation = exports.metaToJsonProperty = exports.isArrayType = exports.stringTypeToWrapper = exports.getJsonSchemaRef = exports.getJsonSchema = exports.buildModelCacheKey = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const core_1 = require("@loopback/core");
10
+ const repository_1 = require("@loopback/repository");
11
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
12
+ const util_1 = require("util");
13
+ const keys_1 = require("./keys");
14
+ const debug = (0, debug_1.default)('loopback:repository-json-schema:build-schema');
15
+ /**
16
+ * @internal
17
+ */
18
+ function buildModelCacheKey(options = {}) {
19
+ var _a;
20
+ // Backwards compatibility: preserve cache key "modelOnly"
21
+ if (Object.keys(options).length === 0) {
22
+ return 'modelOnly';
23
+ }
24
+ // New key schema: use the same suffix as we use for schema title
25
+ // For example: "modelPartialWithRelations"
26
+ // Note this new key schema preserves the old key "modelWithRelations"
27
+ return 'model' + ((_a = options.title) !== null && _a !== void 0 ? _a : '') + getTitleSuffix(options);
28
+ }
29
+ exports.buildModelCacheKey = buildModelCacheKey;
30
+ /**
31
+ * Gets the JSON Schema of a TypeScript model/class by seeing if one exists
32
+ * in a cache. If not, one is generated and then cached.
33
+ * @param ctor - Constructor of class to get JSON Schema from
34
+ */
35
+ function getJsonSchema(ctor, options) {
36
+ // In the near future the metadata will be an object with
37
+ // different titles as keys
38
+ const cached = core_1.MetadataInspector.getClassMetadata(keys_1.JSON_SCHEMA_KEY, ctor, {
39
+ ownMetadataOnly: true,
40
+ });
41
+ const key = buildModelCacheKey(options);
42
+ let schema = cached === null || cached === void 0 ? void 0 : cached[key];
43
+ if (!schema) {
44
+ // Create new json schema from model
45
+ // if not found in cache for specific key
46
+ schema = modelToJsonSchema(ctor, options);
47
+ if (cached) {
48
+ // Add a new key to the cached schema of the model
49
+ cached[key] = schema;
50
+ }
51
+ else {
52
+ // Define new metadata and set in cache
53
+ core_1.MetadataInspector.defineMetadata(keys_1.JSON_SCHEMA_KEY.key, { [key]: schema }, ctor);
54
+ }
55
+ }
56
+ return schema;
57
+ }
58
+ exports.getJsonSchema = getJsonSchema;
59
+ /**
60
+ * Describe the provided Model as a reference to a definition shared by multiple
61
+ * endpoints. The definition is included in the returned schema.
62
+ *
63
+ * @example
64
+ *
65
+ * ```ts
66
+ * const schema = {
67
+ * $ref: '/definitions/Product',
68
+ * definitions: {
69
+ * Product: {
70
+ * title: 'Product',
71
+ * properties: {
72
+ * // etc.
73
+ * }
74
+ * }
75
+ * }
76
+ * }
77
+ * ```
78
+ *
79
+ * @param modelCtor - The model constructor (e.g. `Product`)
80
+ * @param options - Additional options
81
+ */
82
+ function getJsonSchemaRef(modelCtor, options) {
83
+ const schemaWithDefinitions = getJsonSchema(modelCtor, options);
84
+ const key = schemaWithDefinitions.title;
85
+ // ctor is not a model
86
+ if (!key)
87
+ return schemaWithDefinitions;
88
+ const definitions = Object.assign({}, schemaWithDefinitions.definitions);
89
+ const schema = Object.assign({}, schemaWithDefinitions);
90
+ delete schema.definitions;
91
+ definitions[key] = schema;
92
+ return {
93
+ $ref: `#/definitions/${key}`,
94
+ definitions,
95
+ };
96
+ }
97
+ exports.getJsonSchemaRef = getJsonSchemaRef;
98
+ /**
99
+ * Gets the wrapper function of primitives string, number, and boolean
100
+ * @param type - Name of type
101
+ */
102
+ function stringTypeToWrapper(type) {
103
+ if (typeof type === 'function') {
104
+ return type;
105
+ }
106
+ type = type.toLowerCase();
107
+ let wrapper;
108
+ switch (type) {
109
+ case 'number': {
110
+ wrapper = Number;
111
+ break;
112
+ }
113
+ case 'string': {
114
+ wrapper = String;
115
+ break;
116
+ }
117
+ case 'boolean': {
118
+ wrapper = Boolean;
119
+ break;
120
+ }
121
+ case 'array': {
122
+ wrapper = Array;
123
+ break;
124
+ }
125
+ case 'object':
126
+ case 'any': {
127
+ wrapper = Object;
128
+ break;
129
+ }
130
+ case 'date': {
131
+ wrapper = Date;
132
+ break;
133
+ }
134
+ case 'buffer': {
135
+ wrapper = Buffer;
136
+ break;
137
+ }
138
+ case 'null': {
139
+ wrapper = repository_1.Null;
140
+ break;
141
+ }
142
+ default: {
143
+ throw new Error('Unsupported type: ' + type);
144
+ }
145
+ }
146
+ return wrapper;
147
+ }
148
+ exports.stringTypeToWrapper = stringTypeToWrapper;
149
+ /**
150
+ * Determines whether a given string or constructor is array type or not
151
+ * @param type - Type as string or wrapper
152
+ */
153
+ function isArrayType(type) {
154
+ return type === Array || type === 'array';
155
+ }
156
+ exports.isArrayType = isArrayType;
157
+ /**
158
+ * Converts property metadata into a JSON property definition
159
+ * @param meta
160
+ */
161
+ function metaToJsonProperty(meta) {
162
+ const propDef = {};
163
+ let result;
164
+ let propertyType = meta.type;
165
+ if (isArrayType(propertyType) && meta.itemType) {
166
+ if (isArrayType(meta.itemType) && !meta.jsonSchema) {
167
+ throw new Error('You must provide the "jsonSchema" field when define ' +
168
+ 'a nested array property');
169
+ }
170
+ result = { type: 'array', items: propDef };
171
+ propertyType = meta.itemType;
172
+ }
173
+ else {
174
+ result = propDef;
175
+ }
176
+ const wrappedType = stringTypeToWrapper(propertyType);
177
+ const resolvedType = (0, repository_1.resolveType)(wrappedType);
178
+ if (resolvedType === Date) {
179
+ Object.assign(propDef, {
180
+ type: 'string',
181
+ format: 'date-time',
182
+ });
183
+ }
184
+ else if (propertyType === 'any') {
185
+ // no-op, the json schema for any type is {}
186
+ }
187
+ else if ((0, repository_1.isBuiltinType)(resolvedType)) {
188
+ Object.assign(propDef, {
189
+ type: resolvedType.name.toLowerCase(),
190
+ });
191
+ }
192
+ else {
193
+ Object.assign(propDef, { $ref: `#/definitions/${resolvedType.name}` });
194
+ }
195
+ if (meta.description) {
196
+ Object.assign(propDef, {
197
+ description: meta.description,
198
+ });
199
+ }
200
+ if (meta.jsonSchema) {
201
+ Object.assign(propDef, meta.jsonSchema);
202
+ }
203
+ return result;
204
+ }
205
+ exports.metaToJsonProperty = metaToJsonProperty;
206
+ /**
207
+ * Checks and return navigational property definition for the relation
208
+ * @param relMeta Relation metadata object
209
+ * @param targetRef Schema definition for the target model
210
+ */
211
+ function getNavigationalPropertyForRelation(relMeta, targetRef) {
212
+ if (relMeta.targetsMany === true) {
213
+ // Targets an array of object, like, hasMany
214
+ return {
215
+ type: 'array',
216
+ items: targetRef,
217
+ };
218
+ }
219
+ else if (relMeta.targetsMany === false) {
220
+ // Targets single object, like, hasOne, belongsTo
221
+ return targetRef;
222
+ }
223
+ else {
224
+ // targetsMany is undefined or null
225
+ // not allowed if includeRelations is true
226
+ throw new Error(`targetsMany attribute missing for ${relMeta.name}`);
227
+ }
228
+ }
229
+ exports.getNavigationalPropertyForRelation = getNavigationalPropertyForRelation;
230
+ function buildSchemaTitle(ctor, meta, options) {
231
+ if (options.title)
232
+ return options.title;
233
+ const title = meta.title || ctor.name;
234
+ return title + getTitleSuffix(options);
235
+ }
236
+ /**
237
+ * Checks the options and generates a descriptive suffix using compatible chars
238
+ * @param options json schema options
239
+ */
240
+ function getTitleSuffix(options = {}) {
241
+ var _a, _b;
242
+ let suffix = '';
243
+ if ((_a = options.optional) === null || _a === void 0 ? void 0 : _a.length) {
244
+ suffix += `Optional_${options.optional.join('-')}_`;
245
+ }
246
+ else if (options.partial) {
247
+ suffix += 'Partial';
248
+ }
249
+ if ((_b = options.exclude) === null || _b === void 0 ? void 0 : _b.length) {
250
+ suffix += `Excluding_${options.exclude.join('-')}_`;
251
+ }
252
+ if (options.includeRelations) {
253
+ suffix += 'WithRelations';
254
+ }
255
+ return suffix;
256
+ }
257
+ function stringifyOptions(modelSettings = {}) {
258
+ return (0, util_1.inspect)(modelSettings, {
259
+ depth: Infinity,
260
+ maxArrayLength: Infinity,
261
+ breakLength: Infinity,
262
+ });
263
+ }
264
+ function isEmptyJson(obj) {
265
+ return !(obj && Object.keys(obj).length);
266
+ }
267
+ /**
268
+ * Checks the options and generates a descriptive suffix that contains the
269
+ * TypeScript type and options
270
+ * @param typeName - TypeScript's type name
271
+ * @param options - json schema options
272
+ */
273
+ function getDescriptionSuffix(typeName, rawOptions = {}) {
274
+ const options = { ...rawOptions };
275
+ delete options.visited;
276
+ if (options.optional && !options.optional.length) {
277
+ delete options.optional;
278
+ }
279
+ const type = typeName;
280
+ let tsType = type;
281
+ if (options.includeRelations) {
282
+ tsType = `${type}WithRelations`;
283
+ }
284
+ if (options.partial) {
285
+ tsType = `Partial<${tsType}>`;
286
+ }
287
+ if (options.exclude) {
288
+ const excludedProps = options.exclude.map(p => `'${p}'`);
289
+ tsType = `Omit<${tsType}, ${excludedProps.join(' | ')}>`;
290
+ }
291
+ if (options.optional) {
292
+ const optionalProps = options.optional.map(p => `'${p}'`);
293
+ tsType = `@loopback/repository-json-schema#Optional<${tsType}, ${optionalProps.join(' | ')}>`;
294
+ }
295
+ return !isEmptyJson(options)
296
+ ? `(tsType: ${tsType}, schemaOptions: ${stringifyOptions(options)})`
297
+ : '';
298
+ }
299
+ // NOTE(shimks) no metadata for: union, optional, nested array, any, enum,
300
+ // string literal, anonymous types, and inherited properties
301
+ /**
302
+ * Converts a TypeScript class into a JSON Schema using TypeScript's
303
+ * reflection API
304
+ * @param ctor - Constructor of class to convert from
305
+ */
306
+ function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
307
+ var _a, _b, _c, _d, _e, _f, _g;
308
+ const options = { ...jsonSchemaOptions };
309
+ options.visited = (_a = options.visited) !== null && _a !== void 0 ? _a : {};
310
+ options.optional = (_b = options.optional) !== null && _b !== void 0 ? _b : [];
311
+ const partial = options.partial && !options.optional.length;
312
+ if (options.partial && !partial) {
313
+ debug('Overriding "partial" option with "optional" option');
314
+ delete options.partial;
315
+ }
316
+ debug('Creating schema for model %s', ctor.name);
317
+ debug('JSON schema options: %o', options);
318
+ const modelDef = repository_1.ModelMetadataHelper.getModelMetadata(ctor);
319
+ // returns an empty object if metadata is an empty object
320
+ if (modelDef == null || Object.keys(modelDef).length === 0) {
321
+ return {};
322
+ }
323
+ const meta = modelDef;
324
+ debug('Model settings', meta.settings);
325
+ const title = buildSchemaTitle(ctor, meta, options);
326
+ if (options.visited[title])
327
+ return options.visited[title];
328
+ const result = { title };
329
+ options.visited[title] = result;
330
+ result.type = 'object';
331
+ const descriptionSuffix = getDescriptionSuffix(ctor.name, options);
332
+ if (meta.description) {
333
+ const formatSuffix = descriptionSuffix ? ` ${descriptionSuffix}` : '';
334
+ result.description = meta.description + formatSuffix;
335
+ }
336
+ else if (descriptionSuffix) {
337
+ result.description = descriptionSuffix;
338
+ }
339
+ for (const p in meta.properties) {
340
+ if ((_c = options.exclude) === null || _c === void 0 ? void 0 : _c.includes(p)) {
341
+ debug('Property % is excluded by %s', p, options.exclude);
342
+ continue;
343
+ }
344
+ if (meta.properties[p].type == null) {
345
+ // Circular import of model classes can lead to this situation
346
+ throw new Error(`Property ${ctor.name}.${p} does not have "type" in its definition`);
347
+ }
348
+ result.properties = (_d = result.properties) !== null && _d !== void 0 ? _d : {};
349
+ result.properties[p] = result.properties[p] || {};
350
+ const metaProperty = Object.assign({}, meta.properties[p]);
351
+ // populating "properties" key
352
+ result.properties[p] = metaToJsonProperty(metaProperty);
353
+ // handling 'required' metadata
354
+ const optional = options.optional.includes(p);
355
+ if (metaProperty.required && !(partial || optional)) {
356
+ result.required = (_e = result.required) !== null && _e !== void 0 ? _e : [];
357
+ result.required.push(p);
358
+ }
359
+ // populating JSON Schema 'definitions'
360
+ // shimks: ugly type casting; this should be replaced by logic to throw
361
+ // error if itemType/type is not a string or a function
362
+ const resolvedType = (0, repository_1.resolveType)(metaProperty.type);
363
+ const referenceType = isArrayType(resolvedType)
364
+ ? // shimks: ugly type casting; this should be replaced by logic to throw
365
+ // error if itemType/type is not a string or a function
366
+ (0, repository_1.resolveType)(metaProperty.itemType)
367
+ : resolvedType;
368
+ if (typeof referenceType !== 'function' || (0, repository_1.isBuiltinType)(referenceType)) {
369
+ continue;
370
+ }
371
+ const propOptions = { ...options };
372
+ if (propOptions.partial !== 'deep') {
373
+ // Do not cascade `partial` to nested properties
374
+ delete propOptions.partial;
375
+ }
376
+ if (propOptions.includeRelations === true) {
377
+ // Do not cascade `includeRelations` to nested properties
378
+ delete propOptions.includeRelations;
379
+ }
380
+ // `title` is the unique identity of a schema,
381
+ // it should be removed from the `options`
382
+ // when generating the relation or property schemas
383
+ delete propOptions.title;
384
+ const propSchema = getJsonSchema(referenceType, propOptions);
385
+ // JSONSchema6Definition allows both boolean and JSONSchema6 types
386
+ if (typeof result.properties[p] !== 'boolean') {
387
+ const prop = result.properties[p];
388
+ const propTitle = (_f = propSchema.title) !== null && _f !== void 0 ? _f : referenceType.name;
389
+ const targetRef = { $ref: `#/definitions/${propTitle}` };
390
+ if (prop.type === 'array' && prop.items) {
391
+ // Update $ref for array type
392
+ prop.items = targetRef;
393
+ }
394
+ else {
395
+ result.properties[p] = targetRef;
396
+ }
397
+ includeReferencedSchema(propTitle, propSchema);
398
+ }
399
+ }
400
+ result.additionalProperties = meta.settings.strict === false;
401
+ debug(' additionalProperties?', result.additionalProperties);
402
+ if (options.includeRelations) {
403
+ for (const r in meta.relations) {
404
+ result.properties = (_g = result.properties) !== null && _g !== void 0 ? _g : {};
405
+ const relMeta = meta.relations[r];
406
+ const targetType = (0, repository_1.resolveType)(relMeta.target);
407
+ // `title` is the unique identity of a schema,
408
+ // it should be removed from the `options`
409
+ // when generating the relation or property schemas
410
+ const targetOptions = { ...options };
411
+ delete targetOptions.title;
412
+ const targetSchema = getJsonSchema(targetType, targetOptions);
413
+ const targetRef = { $ref: `#/definitions/${targetSchema.title}` };
414
+ const propDef = getNavigationalPropertyForRelation(relMeta, targetRef);
415
+ result.properties[relMeta.name] =
416
+ result.properties[relMeta.name] || propDef;
417
+ includeReferencedSchema(targetSchema.title, targetSchema);
418
+ }
419
+ }
420
+ function includeReferencedSchema(name, schema) {
421
+ var _a, _b;
422
+ if (!schema || !Object.keys(schema).length)
423
+ return;
424
+ // promote nested definition to the top level
425
+ if (result !== (schema === null || schema === void 0 ? void 0 : schema.definitions)) {
426
+ for (const key in schema.definitions) {
427
+ if (key === title)
428
+ continue;
429
+ result.definitions = (_a = result.definitions) !== null && _a !== void 0 ? _a : {};
430
+ result.definitions[key] = schema.definitions[key];
431
+ }
432
+ delete schema.definitions;
433
+ }
434
+ if (result !== schema) {
435
+ result.definitions = (_b = result.definitions) !== null && _b !== void 0 ? _b : {};
436
+ result.definitions[name] = schema;
437
+ }
438
+ }
439
+ if (meta.jsonSchema) {
440
+ Object.assign(result, meta.jsonSchema);
441
+ }
442
+ return result;
443
+ }
444
+ exports.modelToJsonSchema = modelToJsonSchema;
445
+ //# sourceMappingURL=build-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-schema.js","sourceRoot":"","sources":["../src/build-schema.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,gDAAgD;AAChD,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAAiD;AACjD,qDAS8B;AAC9B,+DAAiC;AACjC,+BAA6B;AAE7B,iCAAuC;AACvC,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,8CAA8C,CAAC,CAAC;AA0E3E;;GAEG;AACH,SAAgB,kBAAkB,CAChC,UAAgC,EAAE;;IAElC,0DAA0D;IAC1D,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,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