@loopback/repository-json-schema 1.11.3 → 1.12.2
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.
- package/CHANGELOG.md +36 -0
- package/dist/filter-json-schema.d.ts +22 -3
- package/dist/filter-json-schema.js +45 -35
- package/dist/filter-json-schema.js.map +1 -1
- package/package.json +11 -11
- package/src/filter-json-schema.ts +67 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,42 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.12.2](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.12.1...@loopback/repository-json-schema@1.12.2) (2020-02-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.12.1](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.12.0...@loopback/repository-json-schema@1.12.1) (2020-02-05)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [1.12.0](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.4...@loopback/repository-json-schema@1.12.0) (2020-01-27)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **repository-json-schema:** add filter title ([2d65971](https://github.com/strongloop/loopback-next/commit/2d6597133885c16c132221cef80893093fa3d289))
|
|
28
|
+
* **repository-json-schema:** add title to filter schemas ([6105883](https://github.com/strongloop/loopback-next/commit/6105883967ca5853cc8990f423d9febd1eb07101))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [1.11.4](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.3...@loopback/repository-json-schema@1.11.4) (2020-01-07)
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
6
42
|
## [1.11.3](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.2...@loopback/repository-json-schema@1.11.3) (2019-12-09)
|
|
7
43
|
|
|
8
44
|
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { Model } from '@loopback/repository';
|
|
2
2
|
import { JSONSchema6 as JsonSchema } from 'json-schema';
|
|
3
|
+
export interface FilterSchemaOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Set this flag if you want the schema to set generated title property.
|
|
6
|
+
*
|
|
7
|
+
* By default the setting is enabled. (e.g. {setTitle: true})
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
setTitle?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Build a JSON schema describing the format of the "scope" object
|
|
14
|
+
* used to query model instances.
|
|
15
|
+
*
|
|
16
|
+
* Note we don't take the model properties into account yet and return
|
|
17
|
+
* a generic json schema allowing any "where" condition.
|
|
18
|
+
*
|
|
19
|
+
* @param modelCtor - The model constructor to build the filter schema for.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getScopeFilterJsonSchemaFor(modelCtor: typeof Model, options?: FilterSchemaOptions): JsonSchema;
|
|
3
22
|
/**
|
|
4
23
|
* Build a JSON schema describing the format of the "filter" object
|
|
5
24
|
* used to query model instances.
|
|
@@ -9,7 +28,7 @@ import { JSONSchema6 as JsonSchema } from 'json-schema';
|
|
|
9
28
|
*
|
|
10
29
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
11
30
|
*/
|
|
12
|
-
export declare function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSchema;
|
|
31
|
+
export declare function getFilterJsonSchemaFor(modelCtor: typeof Model, options?: FilterSchemaOptions): JsonSchema;
|
|
13
32
|
/**
|
|
14
33
|
* Build a JSON schema describing the format of the "where" object
|
|
15
34
|
* used to filter model instances to query, update or delete.
|
|
@@ -19,11 +38,11 @@ export declare function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSch
|
|
|
19
38
|
*
|
|
20
39
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
21
40
|
*/
|
|
22
|
-
export declare function getWhereJsonSchemaFor(modelCtor: typeof Model): JsonSchema;
|
|
41
|
+
export declare function getWhereJsonSchemaFor(modelCtor: typeof Model, options?: FilterSchemaOptions): JsonSchema;
|
|
23
42
|
/**
|
|
24
43
|
* Build a JSON schema describing the format of the "fields" object
|
|
25
44
|
* used to include or exclude properties of model instances.
|
|
26
45
|
*
|
|
27
46
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
28
47
|
*/
|
|
29
|
-
export declare function getFieldsJsonSchemaFor(modelCtor: typeof Model): JsonSchema;
|
|
48
|
+
export declare function getFieldsJsonSchemaFor(modelCtor: typeof Model, options?: FilterSchemaOptions): JsonSchema;
|
|
@@ -11,12 +11,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
const repository_1 = require("@loopback/repository");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Build a JSON schema describing the format of the "scope" object
|
|
16
|
+
* used to query model instances.
|
|
17
|
+
*
|
|
18
|
+
* Note we don't take the model properties into account yet and return
|
|
19
|
+
* a generic json schema allowing any "where" condition.
|
|
20
|
+
*
|
|
21
|
+
* @param modelCtor - The model constructor to build the filter schema for.
|
|
22
|
+
*/
|
|
23
|
+
function getScopeFilterJsonSchemaFor(modelCtor, options = {}) {
|
|
24
|
+
let EmptyModel = class EmptyModel extends repository_1.Model {
|
|
25
|
+
};
|
|
26
|
+
EmptyModel = __decorate([
|
|
27
|
+
repository_1.model({ settings: { strict: false } })
|
|
28
|
+
], EmptyModel);
|
|
29
|
+
const schema = Object.assign(Object.assign({}, getFilterJsonSchemaFor(EmptyModel, { setTitle: false })), (options.setTitle !== false && {
|
|
30
|
+
title: `${modelCtor.modelName}.ScopeFilter`,
|
|
31
|
+
}));
|
|
32
|
+
return schema;
|
|
33
|
+
}
|
|
34
|
+
exports.getScopeFilterJsonSchemaFor = getScopeFilterJsonSchemaFor;
|
|
20
35
|
/**
|
|
21
36
|
* Build a JSON schema describing the format of the "filter" object
|
|
22
37
|
* used to query model instances.
|
|
@@ -26,11 +41,12 @@ const scopeFilter = getFilterJsonSchemaFor(EmptyModel);
|
|
|
26
41
|
*
|
|
27
42
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
28
43
|
*/
|
|
29
|
-
function getFilterJsonSchemaFor(modelCtor) {
|
|
30
|
-
const schema = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
function getFilterJsonSchemaFor(modelCtor, options = {}) {
|
|
45
|
+
const schema = Object.assign(Object.assign({}, (options.setTitle !== false && {
|
|
46
|
+
title: `${modelCtor.modelName}.Filter`,
|
|
47
|
+
})), { properties: {
|
|
48
|
+
where: getWhereJsonSchemaFor(modelCtor, options),
|
|
49
|
+
fields: getFieldsJsonSchemaFor(modelCtor, options),
|
|
34
50
|
offset: {
|
|
35
51
|
type: 'integer',
|
|
36
52
|
minimum: 0,
|
|
@@ -50,24 +66,20 @@ function getFilterJsonSchemaFor(modelCtor) {
|
|
|
50
66
|
type: 'string',
|
|
51
67
|
},
|
|
52
68
|
},
|
|
53
|
-
},
|
|
54
|
-
additionalProperties: false,
|
|
55
|
-
};
|
|
69
|
+
}, additionalProperties: false });
|
|
56
70
|
const modelRelations = repository_1.getModelRelations(modelCtor);
|
|
57
71
|
const hasRelations = Object.keys(modelRelations).length > 0;
|
|
58
72
|
if (hasRelations) {
|
|
59
|
-
schema.properties.include = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
schema.properties.include = Object.assign(Object.assign({}, (options.setTitle !== false && {
|
|
74
|
+
title: `${modelCtor.modelName}.IncludeFilter`,
|
|
75
|
+
})), { type: 'array', items: Object.assign(Object.assign({}, (options.setTitle !== false && {
|
|
76
|
+
title: `${modelCtor.modelName}.IncludeFilter.Items`,
|
|
77
|
+
})), { type: 'object', properties: {
|
|
64
78
|
// TODO(bajtos) restrict values to relations defined by "model"
|
|
65
79
|
relation: { type: 'string' },
|
|
66
80
|
// TODO(bajtos) describe the filter for the relation target model
|
|
67
|
-
scope:
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
};
|
|
81
|
+
scope: getScopeFilterJsonSchemaFor(modelCtor, options),
|
|
82
|
+
} }) });
|
|
71
83
|
}
|
|
72
84
|
return schema;
|
|
73
85
|
}
|
|
@@ -81,13 +93,13 @@ exports.getFilterJsonSchemaFor = getFilterJsonSchemaFor;
|
|
|
81
93
|
*
|
|
82
94
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
83
95
|
*/
|
|
84
|
-
function getWhereJsonSchemaFor(modelCtor) {
|
|
85
|
-
const schema = {
|
|
86
|
-
|
|
96
|
+
function getWhereJsonSchemaFor(modelCtor, options = {}) {
|
|
97
|
+
const schema = Object.assign(Object.assign({}, (options.setTitle !== false && {
|
|
98
|
+
title: `${modelCtor.modelName}.WhereFilter`,
|
|
99
|
+
})), { type: 'object',
|
|
87
100
|
// TODO(bajtos) enumerate "model" properties and operators like "and"
|
|
88
101
|
// See https://github.com/strongloop/loopback-next/issues/1748
|
|
89
|
-
additionalProperties: true
|
|
90
|
-
};
|
|
102
|
+
additionalProperties: true });
|
|
91
103
|
return schema;
|
|
92
104
|
}
|
|
93
105
|
exports.getWhereJsonSchemaFor = getWhereJsonSchemaFor;
|
|
@@ -97,14 +109,12 @@ exports.getWhereJsonSchemaFor = getWhereJsonSchemaFor;
|
|
|
97
109
|
*
|
|
98
110
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
99
111
|
*/
|
|
100
|
-
function getFieldsJsonSchemaFor(modelCtor) {
|
|
101
|
-
const schema = {
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
function getFieldsJsonSchemaFor(modelCtor, options = {}) {
|
|
113
|
+
const schema = Object.assign(Object.assign({}, (options.setTitle !== false && {
|
|
114
|
+
title: `${modelCtor.modelName}.Fields`,
|
|
115
|
+
})), { type: 'object', properties: Object.assign({}, ...Object.keys(modelCtor.definition.properties).map(k => ({
|
|
104
116
|
[k]: { type: 'boolean' },
|
|
105
|
-
}))),
|
|
106
|
-
additionalProperties: modelCtor.definition.settings.strict === false,
|
|
107
|
-
};
|
|
117
|
+
}))), additionalProperties: modelCtor.definition.settings.strict === false });
|
|
108
118
|
return schema;
|
|
109
119
|
}
|
|
110
120
|
exports.getFieldsJsonSchemaFor = getFieldsJsonSchemaFor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-json-schema.js","sourceRoot":"","sources":["../src/filter-json-schema.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,gDAAgD;AAChD,+CAA+C;AAC/C,gEAAgE;;;;;;;;AAEhE,qDAAqE;
|
|
1
|
+
{"version":3,"file":"filter-json-schema.js","sourceRoot":"","sources":["../src/filter-json-schema.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,gDAAgD;AAChD,+CAA+C;AAC/C,gEAAgE;;;;;;;;AAEhE,qDAAqE;AAarE;;;;;;;;GAQG;AACH,SAAgB,2BAA2B,CACzC,SAAuB,EACvB,UAA+B,EAAE;IAGjC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,kBAAK;KAAG,CAAA;IAA3B,UAAU;QADf,kBAAK,CAAC,EAAC,QAAQ,EAAE,EAAC,MAAM,EAAE,KAAK,EAAC,E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,CAAC;YACxD,CAAC,CAAC,CAAC,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC;SACvB,CAAC,CAAC,CACJ,EACD,oBAAoB,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,KAAK,KAAK,GACrE,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,wDAoBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/repository-json-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.2",
|
|
4
4
|
"description": "Converts TS classes into JSON Schemas using TypeScript's reflection API",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.9"
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@loopback/context": "^1.
|
|
27
|
-
"@loopback/metadata": "^1.
|
|
28
|
-
"@loopback/repository": "^1.
|
|
29
|
-
"@types/json-schema": "^7.0.
|
|
26
|
+
"@loopback/context": "^2.1.1",
|
|
27
|
+
"@loopback/metadata": "^1.4.1",
|
|
28
|
+
"@loopback/repository": "^1.19.1",
|
|
29
|
+
"@types/json-schema": "^7.0.4",
|
|
30
30
|
"debug": "^4.1.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@loopback/build": "^3.
|
|
34
|
-
"@loopback/eslint-config": "^5.0.
|
|
35
|
-
"@loopback/testlab": "^1.10.
|
|
33
|
+
"@loopback/build": "^3.1.1",
|
|
34
|
+
"@loopback/eslint-config": "^5.0.3",
|
|
35
|
+
"@loopback/testlab": "^1.10.3",
|
|
36
36
|
"@types/debug": "^4.1.5",
|
|
37
|
-
"@types/node": "^10.17.
|
|
38
|
-
"ajv": "^6.
|
|
37
|
+
"@types/node": "^10.17.14",
|
|
38
|
+
"ajv": "^6.11.0"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"README.md",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
51
51
|
"directory": "packages/repository-json-schema"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "6eea5e428b145cafb84a998bd53979da8c8fba07"
|
|
54
54
|
}
|
|
@@ -6,10 +6,41 @@
|
|
|
6
6
|
import {getModelRelations, Model, model} from '@loopback/repository';
|
|
7
7
|
import {JSONSchema6 as JsonSchema} from 'json-schema';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
export interface FilterSchemaOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Set this flag if you want the schema to set generated title property.
|
|
12
|
+
*
|
|
13
|
+
* By default the setting is enabled. (e.g. {setTitle: true})
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
setTitle?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Build a JSON schema describing the format of the "scope" object
|
|
21
|
+
* used to query model instances.
|
|
22
|
+
*
|
|
23
|
+
* Note we don't take the model properties into account yet and return
|
|
24
|
+
* a generic json schema allowing any "where" condition.
|
|
25
|
+
*
|
|
26
|
+
* @param modelCtor - The model constructor to build the filter schema for.
|
|
27
|
+
*/
|
|
28
|
+
export function getScopeFilterJsonSchemaFor(
|
|
29
|
+
modelCtor: typeof Model,
|
|
30
|
+
options: FilterSchemaOptions = {},
|
|
31
|
+
): JsonSchema {
|
|
32
|
+
@model({settings: {strict: false}})
|
|
33
|
+
class EmptyModel extends Model {}
|
|
11
34
|
|
|
12
|
-
const
|
|
35
|
+
const schema: JsonSchema = {
|
|
36
|
+
...getFilterJsonSchemaFor(EmptyModel, {setTitle: false}),
|
|
37
|
+
...(options.setTitle !== false && {
|
|
38
|
+
title: `${modelCtor.modelName}.ScopeFilter`,
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return schema;
|
|
43
|
+
}
|
|
13
44
|
|
|
14
45
|
/**
|
|
15
46
|
* Build a JSON schema describing the format of the "filter" object
|
|
@@ -20,12 +51,18 @@ const scopeFilter = getFilterJsonSchemaFor(EmptyModel);
|
|
|
20
51
|
*
|
|
21
52
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
22
53
|
*/
|
|
23
|
-
export function getFilterJsonSchemaFor(
|
|
54
|
+
export function getFilterJsonSchemaFor(
|
|
55
|
+
modelCtor: typeof Model,
|
|
56
|
+
options: FilterSchemaOptions = {},
|
|
57
|
+
): JsonSchema {
|
|
24
58
|
const schema: JsonSchema = {
|
|
59
|
+
...(options.setTitle !== false && {
|
|
60
|
+
title: `${modelCtor.modelName}.Filter`,
|
|
61
|
+
}),
|
|
25
62
|
properties: {
|
|
26
|
-
where: getWhereJsonSchemaFor(modelCtor),
|
|
63
|
+
where: getWhereJsonSchemaFor(modelCtor, options),
|
|
27
64
|
|
|
28
|
-
fields: getFieldsJsonSchemaFor(modelCtor),
|
|
65
|
+
fields: getFieldsJsonSchemaFor(modelCtor, options),
|
|
29
66
|
|
|
30
67
|
offset: {
|
|
31
68
|
type: 'integer',
|
|
@@ -58,14 +95,20 @@ export function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSchema {
|
|
|
58
95
|
|
|
59
96
|
if (hasRelations) {
|
|
60
97
|
schema.properties!.include = {
|
|
98
|
+
...(options.setTitle !== false && {
|
|
99
|
+
title: `${modelCtor.modelName}.IncludeFilter`,
|
|
100
|
+
}),
|
|
61
101
|
type: 'array',
|
|
62
102
|
items: {
|
|
103
|
+
...(options.setTitle !== false && {
|
|
104
|
+
title: `${modelCtor.modelName}.IncludeFilter.Items`,
|
|
105
|
+
}),
|
|
63
106
|
type: 'object',
|
|
64
107
|
properties: {
|
|
65
108
|
// TODO(bajtos) restrict values to relations defined by "model"
|
|
66
109
|
relation: {type: 'string'},
|
|
67
110
|
// TODO(bajtos) describe the filter for the relation target model
|
|
68
|
-
scope:
|
|
111
|
+
scope: getScopeFilterJsonSchemaFor(modelCtor, options),
|
|
69
112
|
},
|
|
70
113
|
},
|
|
71
114
|
};
|
|
@@ -83,13 +126,20 @@ export function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSchema {
|
|
|
83
126
|
*
|
|
84
127
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
85
128
|
*/
|
|
86
|
-
export function getWhereJsonSchemaFor(
|
|
129
|
+
export function getWhereJsonSchemaFor(
|
|
130
|
+
modelCtor: typeof Model,
|
|
131
|
+
options: FilterSchemaOptions = {},
|
|
132
|
+
): JsonSchema {
|
|
87
133
|
const schema: JsonSchema = {
|
|
134
|
+
...(options.setTitle !== false && {
|
|
135
|
+
title: `${modelCtor.modelName}.WhereFilter`,
|
|
136
|
+
}),
|
|
88
137
|
type: 'object',
|
|
89
138
|
// TODO(bajtos) enumerate "model" properties and operators like "and"
|
|
90
139
|
// See https://github.com/strongloop/loopback-next/issues/1748
|
|
91
140
|
additionalProperties: true,
|
|
92
141
|
};
|
|
142
|
+
|
|
93
143
|
return schema;
|
|
94
144
|
}
|
|
95
145
|
|
|
@@ -100,9 +150,16 @@ export function getWhereJsonSchemaFor(modelCtor: typeof Model): JsonSchema {
|
|
|
100
150
|
* @param modelCtor - The model constructor to build the filter schema for.
|
|
101
151
|
*/
|
|
102
152
|
|
|
103
|
-
export function getFieldsJsonSchemaFor(
|
|
153
|
+
export function getFieldsJsonSchemaFor(
|
|
154
|
+
modelCtor: typeof Model,
|
|
155
|
+
options: FilterSchemaOptions = {},
|
|
156
|
+
): JsonSchema {
|
|
104
157
|
const schema: JsonSchema = {
|
|
158
|
+
...(options.setTitle !== false && {
|
|
159
|
+
title: `${modelCtor.modelName}.Fields`,
|
|
160
|
+
}),
|
|
105
161
|
type: 'object',
|
|
162
|
+
|
|
106
163
|
properties: Object.assign(
|
|
107
164
|
{},
|
|
108
165
|
...Object.keys(modelCtor.definition.properties).map(k => ({
|
|
@@ -111,5 +168,6 @@ export function getFieldsJsonSchemaFor(modelCtor: typeof Model): JsonSchema {
|
|
|
111
168
|
),
|
|
112
169
|
additionalProperties: modelCtor.definition.settings.strict === false,
|
|
113
170
|
};
|
|
171
|
+
|
|
114
172
|
return schema;
|
|
115
173
|
}
|