diff --git a/packages/datasource-customizer/src/decorators/rename-field/collection.ts b/packages/datasource-customizer/src/decorators/rename-field/collection.ts index a558220543..08c184fae4 100644 --- a/packages/datasource-customizer/src/decorators/rename-field/collection.ts +++ b/packages/datasource-customizer/src/decorators/rename-field/collection.ts @@ -35,6 +35,14 @@ export default class RenameFieldCollectionDecorator extends CollectionDecorator let initialName = currentName; + if (/ /.test(newName)) { + const sanitizedName = newName.replace(/ (.)/g, (_, s) => s.toUpperCase()); + throw new Error( + `The renaming of field '${currentName}' must not contain space.` + + ` Something like '${sanitizedName}' should work has expected.`, + ); + } + // Revert previous renaming (avoids conflicts and need to recurse on this.toSubCollection). if (this.toChildCollection[currentName]) { const childName = this.toChildCollection[currentName]; diff --git a/packages/datasource-customizer/test/decorators/rename-field/collection.test.ts b/packages/datasource-customizer/test/decorators/rename-field/collection.test.ts index 8470611809..9290f1c5d3 100644 --- a/packages/datasource-customizer/test/decorators/rename-field/collection.test.ts +++ b/packages/datasource-customizer/test/decorators/rename-field/collection.test.ts @@ -140,6 +140,13 @@ describe('RenameFieldCollectionDecorator', () => { expect(() => newPersons.renameField('id', 'primaryKey')).toThrow(`No such field 'id'`); }); + test('should throw when renaming with a name including space', () => { + expect(() => newPersons.renameField('id', 'the key')).toThrow( + `The renaming of field 'id' must not contain space.` + + ` Something like 'theKey' should work has expected.`, + ); + }); + test('should allow renaming multiple times the same field', () => { newPersons.renameField('id', 'key'); newPersons.renameField('key', 'primaryKey');