I am encountering an issue with the Loopback 4 filter
on the generated endpoints being marked as required in my Nswag typescript file. I need it to be optional, but I am struggling to locate where this requirement is originating from.
The endpoint from my controller
:
@get('/', {
operationId: 'getPages',
responses: {
'200': {
description: 'Array of Page model instances',
content: {
'application/json': {
schema: {
type: 'array',
items: getModelSchemaRef(Page, {includeRelations: true}),
},
},
},
},
},
})
async find (
@param.filter(Page) filter?: Filter<Page>,
): Promise<Page[]> {
return this.pageRepository.find(filter);
}
The issue arises because it is identified as optional (filter?: Filter<Page>
)
The code snippet for this endpoint:
getPages (filter: any | undefined): Promise<PageWithRelations[]> {
let url_ = this.baseUrl + "/pages?";
if (filter === null)
throw new Error("The parameter 'filter' cannot be null.");
else if (filter !== undefined)
url_ += "filter=" + encodeURIComponent("" + filter) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_ = <RequestInit>{
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetPages(_response);
});
}
In addition, within the getPages
function, we see that the filter
has a type of any | undefined
. I understand the presence of undefined
, but I am puzzled by why the type of filter
is not defined as the property's type (filter: Filter
). The interface is exported, yet somehow not associated with the property.
export interface Filter {
offset?: number;
limit?: number;
skip?: number;
order?: string[];
fields?: Fields;
}