amplication / amplication/amplication

Transform a response schema/data only for one specific autogenerated route (before returning it to the user)

Đang mở
#4,148 3 bình luận 1 reaction 1 người được giao Được @GreenMachine01 nhận Xem trên GitHub
type: feature request
Ngôn ngữ chính
TypeScript
Star
16k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Feature description

**The feature request would be either or**
- a blog post how to do it in code as a best practice
- or an advanced ui, where you can transform a schema for a specific route (exclude fields, transform, expose new fields)

### Use case

**for solving this problem:**
How do I best override an autogenerated route to map the response to another schema without touching the base folder?
or in other words:
What is the best practice (in the amplication context) to transform the response data before returning it to the user on one route (and also show the transformed schema in OpenAPI spec documentation)

**My approaches so far:**
- If I just copy the whole route method from the base controller into the custom controller, the return types have to match exactly says typescript, so I can't just change the return type.
- If I directly alter the type in the controller.base.ts it conflicts with the used prisma service that uses the original type, so I would have to to a manual mapping inside the controller, which seems not the best practice because i want to alter the schema only in this one route

- What I could find was to use Serializing with NestJS with class-transformer (https://docs.nestjs.com/techniques/serialization) or use @nestjs/swagger mapped types (https://docs.nestjs.com/openapi/mapped-types) to extend and alter the DTO classes that way, but I could not figure out how to use that in this context.

**Thanks to @abrl91 for a current approach:**
The solution for now is to create a new route (with a different method name), so that you would be able to set whatever type you want, and again - open a feature request about it and we will consider to implement a better approach for that

### Are you willing to submit PR?

_No response_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.