feature: Support class-level decorators #1788
Labels
flag: needs discussion
Issues which needs discussion before implementation.
type: feature
Issues related to new features.
Also, I'm willing to contribute this feature. Please provide feedback as our codebase would benefit from implementing this.
Description
There are cases, in particular for parsing with
plainToInstance
that there are transformations, and annotations that are universal to a class, whenever it is used as a property. What I'd like to do is take the decorators that we now need to repeat on all properties using that type, and place them on the class directly.Detailed use-case, involving Sanity
Let me describe a real use-case where we are facing this.
We have some parts that query Sanity, a free-form json-encoded data-store.
You get to set-up the entire schema for the data yourself. Additionally Sanity has a small set of datatypes, one of which is
asset
. Asset is a file uploaded to the sanity store and you can reference that asset within your data.This is what the data of an asset could look like:
In this case,
InjectSanityAssetUrl
is a decorator that needs to be set on all DTOs that have aAssetDto
property.Proposed solution
Taking
@Transform
as example, but other decorators may qualify as well, allow it to be used on at the class level.A decorator applied at the class level is equivalent to applying the decorator to the property the class is used in, when it shows up in a class that is being transformed.
In its simplest form, what would happen is that when the decorators of a property are collected, the
@Type
decorator is evaluated to find class-level decorators that merged onto the property the@Type
applies to.Before
After
The text was updated successfully, but these errors were encountered: