amplication / amplication/amplication

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

Open
#4,148 3 comments 1 reaction 1 assignee Claimed by @GreenMachine01 View on GitHub
type: feature request
Dominant language
TypeScript
Stars
16k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.