From 9679aa88999a7ee2194b55d73c182e8a366bc5a2 Mon Sep 17 00:00:00 2001 From: dougal83 Date: Mon, 23 Dec 2019 18:06:42 +0000 Subject: [PATCH] feat(repository-json-schema): add title to filter schemas add title property to filter schemas(filter, where, scope) in preparation for openapi schema consolidation --- .../src/__tests__/unit/filter-schema.unit.ts | 3 +++ .../src/filter-json-schema.ts | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/openapi-v3/src/__tests__/unit/filter-schema.unit.ts b/packages/openapi-v3/src/__tests__/unit/filter-schema.unit.ts index 3a7373190ca2..4b38e4faf93f 100644 --- a/packages/openapi-v3/src/__tests__/unit/filter-schema.unit.ts +++ b/packages/openapi-v3/src/__tests__/unit/filter-schema.unit.ts @@ -21,13 +21,16 @@ describe('filterSchema', () => { const schema = getFilterSchemaFor(MyUserModel); expect(MyUserModel.definition.name).to.eql('my-user-model'); expect(schema).to.eql({ + title: 'my-user-modelFilter', properties: { where: { type: 'object', + title: 'my-user-modelWhere', additionalProperties: true, }, fields: { type: 'object', + title: 'my-user-modelFields', properties: { id: {type: 'boolean'}, age: {type: 'boolean'}, diff --git a/packages/repository-json-schema/src/filter-json-schema.ts b/packages/repository-json-schema/src/filter-json-schema.ts index 284c8215e532..b5bdf634c731 100644 --- a/packages/repository-json-schema/src/filter-json-schema.ts +++ b/packages/repository-json-schema/src/filter-json-schema.ts @@ -9,7 +9,10 @@ import {JSONSchema6 as JsonSchema} from 'json-schema'; @model({settings: {strict: false}}) class EmptyModel extends Model {} -const scopeFilter = getFilterJsonSchemaFor(EmptyModel); +const scopeFilter = { + ...getFilterJsonSchemaFor(EmptyModel), + title: 'ScopeFilter', // TODO(dougal83) base title on model +}; /** * Build a JSON schema describing the format of the "filter" object @@ -22,6 +25,10 @@ const scopeFilter = getFilterJsonSchemaFor(EmptyModel); */ export function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSchema { const schema: JsonSchema = { + title: + modelCtor.modelName === 'EmptyModel' + ? undefined + : `${modelCtor.modelName}Filter`, properties: { where: getWhereJsonSchemaFor(modelCtor), @@ -58,6 +65,8 @@ export function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSchema { if (hasRelations) { schema.properties!.include = { + // TODO(dougal83) base title on model + title: 'Include', type: 'array', items: { type: 'object', @@ -85,6 +94,10 @@ export function getFilterJsonSchemaFor(modelCtor: typeof Model): JsonSchema { */ export function getWhereJsonSchemaFor(modelCtor: typeof Model): JsonSchema { const schema: JsonSchema = { + title: + modelCtor.modelName === 'EmptyModel' + ? undefined + : `${modelCtor.modelName}Where`, type: 'object', // TODO(bajtos) enumerate "model" properties and operators like "and" // See https://github.com/strongloop/loopback-next/issues/1748 @@ -102,7 +115,12 @@ export function getWhereJsonSchemaFor(modelCtor: typeof Model): JsonSchema { export function getFieldsJsonSchemaFor(modelCtor: typeof Model): JsonSchema { const schema: JsonSchema = { + title: + modelCtor.modelName === 'EmptyModel' + ? undefined + : `${modelCtor.modelName}Fields`, type: 'object', + properties: Object.assign( {}, ...Object.keys(modelCtor.definition.properties).map(k => ({