Hello there! I'm having a situation where I'm exposing a filter query parameter according to the JSON:API specification which allows consumers to filter any of the resource's properties. So far so good! Now I'd like to document that query parameter in Swagger.
For both the validation via class-validator and the actual filtering I'm using a class that looks like so:
export class SomeFilterQuery {
IsNumber()
someNumber?: number;
}
Now I thought of doing something like this in the controller:
ApiQuery(documentFilterQuery(SomeFilterQuery))
Where documentFilterQuery is a function that takes the class (or an instance of it) and returns a documentation object that contains the properties.
Something along these lines:
export const documentFilterQuery(FilterQuery: new () => object) {
const filterQuery = new FilterQuery();
const properties = Object.keys(filterQuery);
// ...
}
Of course, the class won't contain the properties at runtime due to JavaScript being JavaScript, and now I'm looking for an elegant way around that. I noticed that all the objects that are being validated by class-validator via the one of the validation decorators will contain all properties, even optional and undefined ones and I was wondering how class-validator was doing this. Maybe someone has an idea?