From 58ac19b600c8584dcdd1bd83ce0f2a674c7b0270 Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Mon, 5 Dec 2022 10:17:00 +0500 Subject: [PATCH] feat(cli): enum relations in openapispec relation object This PR will restrict the relations in openapi spec by using enum. Signed-off-by: Muhammad Aaqil --- .../src/__tests__/unit/filter-json-schema.unit.ts | 13 +++++++++++++ .../src/filter-json-schema.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts b/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts index c176470d679b..2e30fd2b5dcb 100644 --- a/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts +++ b/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts @@ -260,6 +260,19 @@ describe('getFilterJsonSchemaFor', () => { .to.equal('Customer.IncludeFilter'); }); + it('enumerates relations under relation object', () => { + expect(customerFilterSchema.properties) + .to.have.propertyByPath( + 'include', + 'items', + 'anyOf', + '0', + 'properties', + 'relation', + 'enum', + ) + .containDeep(['orders']); + }); it('returns "include.items.title" when no options were provided', () => { expect(customerFilterSchema.properties) .to.have.propertyByPath('include', 'items', 'anyOf', '0', 'title') diff --git a/packages/repository-json-schema/src/filter-json-schema.ts b/packages/repository-json-schema/src/filter-json-schema.ts index 0573174c18fe..9ced979baaa7 100644 --- a/packages/repository-json-schema/src/filter-json-schema.ts +++ b/packages/repository-json-schema/src/filter-json-schema.ts @@ -153,7 +153,7 @@ export function getFilterJsonSchemaFor( type: 'object', properties: { // TODO(bajtos) restrict values to relations defined by "model" - relation: {type: 'string'}, + relation: {type: 'string', enum: Object.keys(modelRelations)}, // TODO(bajtos) describe the filter for the relation target model scope: getScopeFilterJsonSchemaFor(modelCtor, options), },