From 2809bb253d15aa5888ad2f2f941157a3d2d8c1f0 Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Mon, 26 Aug 2024 00:55:44 +0500 Subject: [PATCH] fix: show readonly in openapi spec of model property if it is generated Signed-off-by: Muhammad Aaqil --- .../src/__tests__/unit/build-schema.unit.ts | 14 ++++++++++++++ .../repository-json-schema/src/build-schema.ts | 3 +++ 2 files changed, 17 insertions(+) diff --git a/packages/repository-json-schema/src/__tests__/unit/build-schema.unit.ts b/packages/repository-json-schema/src/__tests__/unit/build-schema.unit.ts index 29493866baf2..a1a9cb5b5183 100644 --- a/packages/repository-json-schema/src/__tests__/unit/build-schema.unit.ts +++ b/packages/repository-json-schema/src/__tests__/unit/build-schema.unit.ts @@ -203,6 +203,20 @@ describe('build-schema', () => { }); }); + it('show generated', () => { + expect( + metaToJsonProperty({ + type: String, + description: 'test', + generated: true, + }), + ).to.eql({ + type: 'string', + description: 'test', + readOnly: true, + }); + }); + it('keeps AJV keywords', () => { const schema = metaToJsonProperty({ type: String, diff --git a/packages/repository-json-schema/src/build-schema.ts b/packages/repository-json-schema/src/build-schema.ts index e945000973e8..484fc420cc7f 100644 --- a/packages/repository-json-schema/src/build-schema.ts +++ b/packages/repository-json-schema/src/build-schema.ts @@ -271,6 +271,9 @@ export function metaToJsonProperty(meta: PropertyDefinition): JsonSchema { } else { result = propDef; } + if (meta.generated) { + result.readOnly = true; + } const wrappedType = stringTypeToWrapper(propertyType); const resolvedType = resolveType(wrappedType);