@ApiHideProperty() makes property read-only, TypeORM can't assign values to entity
See original GitHub issueBug report
Current behavior
When you decorate property of TypeORM entity with @ApiHideProperty()
, you get following error as the property is read-only - Cannot assign to read only property 'property' of object '#<Entity>'
.
Expected behavior
The property shouldn’t be read-only, so TypeORM can create class and assign values from db.
Minimal reproduction of the problem with instructions
Clone: https://github.com/nestjs/nest/tree/master/sample/05-sql-typeorm.
Install @nestjs/swagger (npm i @nestjs/swagger
).
Decorate property, for example views
in photo.entity.ts
.
@Column('int')
@ApiHideProperty()
views: number;
Add a photo to database.
You can edit `findAll` method in service to ensure that it returns at least one photo (or just add it manually). async findAll(): Promise<Photo[]> {
await this.photoRepository.save({
name: 'test',
description: 'test',
filename: 'test',
views: 99,
isPublished: true,
});
return this.photoRepository.find();
}
Running the application and navigating to localhost:3000/photo
causes an error - Cannot assign to read only property 'views' of object '#<Photo>'
.
What is the motivation / use case for changing the behavior?
For example, you want to hide some internal properties, like createdAt.
Environment
Nest version: 6.10.14 nestjs/swagger version: 4.1.7 TypeORM driver: pg
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
ApiHideProperty() makes property read-only, TypeORM can't assign ...
ApiHideProperty () makes property read-only, TypeORM can't assign values to entity.
Read more >Nestjs Swagger CLI Plugin displays entities from relations ...
You can use the @ApiHideProperty() decorator on all relations of your TypeORM entity, that way it won't be loaded into Swagger-UI schemas.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in 4.1.9. Thanks for reporting
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.