Closed elliotaplant closed 1 year ago
Hey, yup this sounds good. there are a couple of examples of rule configurations that accept an array of custom decorators if anyone wants to take a crack at a PR 👍
I'll keep custom decorator requirement in mind the next time there is a new rule added to library where custom decorators might need to be configured. Seems to be a fairly consistent ask for these rules
We ended up solving this by making the routes that return paginated DTOs extend an API decorated base PageDto
. Contrary to my initial post, I think that creating decorators like ApiPaginatedResponse
may actually be an anti-pattern because it duplicates the responsibility of type annotations on network DTOs.
For example, routes decorated by @ApiPaginatedResponse(SomeDataType)
would have to decorate methods that return a value of PageDto<SomeDataType>
. Both ApiPaginatedResponse
and PageDto
would have to provide the same information to Swagger, which invites an opportunity to have contradicting information. Better to let PageDto
be the source of truth and simply use @ApiOkResponse({ type: PageDto })
.
What other asks have you seen for custom rules? I'm curious to see if they might fall into the same pattern we saw in our project.
Hey yea that sounds like a nice solution with the object properties handling it
This link is an example of a rule has a configuration option for telling the rule a list of custom "class-validator" decorators. But this is a very common use case where people create custom validators or combine multiple validators into one for their domain.
i will close this issue, it sounds like it's resolved 👍
Hey yea that sounds like a nice solution with the object properties handling it
This link is an example of a rule has a configuration option for telling the rule a list of custom "class-validator" decorators. But this is a very common use case where people create custom validators or combine multiple validators into one for their domain.
i will close this issue, it sounds like it's resolved 👍
This not works for me, there are different rules
Error:
Eslint config:
ApiPaginatedResponse is my custom decorator
Being able to configure custom decorators for this rule would be really great. In my project, I have custom decorators that apply multiple decorators including ApiResponse. At the moment, I have to disable the rule for endpoints using those decorators.
We use this lint rule to ensure all of our API methods define their response types. We also have an additional decorator we want the linter to recognize:
@ApiPaginatedResponse(SomeDataType)
that defines a paginated response of some data type. What do you think about adding some way to include custom decorators in this linter?