amplication / amplication/amplication
Transform a response schema/data only for one specific autogenerated route (before returning it to the user)
- Lingua principale
- TypeScript
- Stelle
- 16k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
### 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_
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.