-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
filter-schema.ts
42 lines (39 loc) · 1.44 KB
/
filter-schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/openapi-v3
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {
getFilterJsonSchemaFor,
getWhereJsonSchemaFor,
Model,
} from '@loopback/repository-json-schema';
import {jsonToSchemaObject} from './json-to-schema';
import {SchemaObject} from './types';
/**
* Build an OpenAPI schema describing the format of the "filter" object
* used to query model instances.
*
* Note we don't take the model properties into account yet and return
* a generic json schema allowing any "where" condition.
*
* @param modelCtor - The model constructor to build the filter schema for.
*/
export function getFilterSchemaFor(modelCtor: typeof Model): SchemaObject {
const jsonSchema = getFilterJsonSchemaFor(modelCtor);
const schema = jsonToSchemaObject(jsonSchema);
return schema;
}
/**
* Build a OpenAPI schema describing the format of the "where" object
* used to filter model instances to query, update or delete.
*
* Note we don't take the model properties into account yet and return
* a generic json schema allowing any "where" condition.
*
* @param modelCtor - The model constructor to build the filter schema for.
*/
export function getWhereSchemaFor(modelCtor: typeof Model): SchemaObject {
const jsonSchema = getWhereJsonSchemaFor(modelCtor);
const schema = jsonToSchemaObject(jsonSchema);
return schema;
}