From b7f3cf84c844f4541c694522a54c9948bd97115b Mon Sep 17 00:00:00 2001 From: Heiko Henning Date: Fri, 23 Feb 2024 15:38:53 +0100 Subject: [PATCH] feat: append schema title to objects (#920) --- library/src/helpers/__tests__/schema.test.ts | 6 ++++++ library/src/helpers/schema.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/library/src/helpers/__tests__/schema.test.ts b/library/src/helpers/__tests__/schema.test.ts index ebe27c1b8..3c2ff948a 100644 --- a/library/src/helpers/__tests__/schema.test.ts +++ b/library/src/helpers/__tests__/schema.test.ts @@ -169,6 +169,12 @@ describe('SchemaHelpers', () => { const result = SchemaHelpers.toSchemaType(schema); expect(result).toEqual(`number | string | boolean`); }); + + test('should handle append title to object', () => { + const schema = new Schema({ type: 'object', title: 'SampleType' }); + const result = SchemaHelpers.toSchemaType(schema); + expect(result).toEqual('object [SampleType]'); + }); }); describe('.prettifyValue', () => { diff --git a/library/src/helpers/schema.ts b/library/src/helpers/schema.ts index c84c4e395..f6e9aa6d8 100644 --- a/library/src/helpers/schema.ts +++ b/library/src/helpers/schema.ts @@ -98,6 +98,10 @@ export class SchemaHelpers { if (combinedType) { return combinedType; } + + if (type === 'object' && schema.title()) { + type += ' [' + schema.title() + ']'; + } return type; }