diff --git a/.changeset/pretty-ways-knock.md b/.changeset/pretty-ways-knock.md new file mode 100644 index 0000000000..1b8d56c178 --- /dev/null +++ b/.changeset/pretty-ways-knock.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-todo-backend': patch +--- + +Fixed a bug where filter queries from the frontend would always fail validation. diff --git a/plugins/todo-backend/src/schema/openapi.generated.ts b/plugins/todo-backend/src/schema/openapi.generated.ts index a58a96ddb8..effe851790 100644 --- a/plugins/todo-backend/src/schema/openapi.generated.ts +++ b/plugins/todo-backend/src/schema/openapi.generated.ts @@ -173,6 +173,7 @@ export const spec = { name: 'filter', in: 'query', required: false, + allowReserved: true, schema: { type: 'array', description: diff --git a/plugins/todo-backend/src/schema/openapi.yaml b/plugins/todo-backend/src/schema/openapi.yaml index 0e6203e002..8023144f48 100644 --- a/plugins/todo-backend/src/schema/openapi.yaml +++ b/plugins/todo-backend/src/schema/openapi.yaml @@ -111,6 +111,7 @@ paths: - name: filter in: query required: false + allowReserved: true schema: type: array description: A list of filters used to narrow down the listed TODO items diff --git a/plugins/todo-backend/src/service/router.test.ts b/plugins/todo-backend/src/service/router.test.ts index 0bf591316c..64f894a147 100644 --- a/plugins/todo-backend/src/service/router.test.ts +++ b/plugins/todo-backend/src/service/router.test.ts @@ -131,6 +131,23 @@ describe('createRouter', () => { ); }); + it('forwards filter query', async () => { + mockService.listTodos.mockResolvedValueOnce(mockListBody); + + const response = await request(app).get('/v1/todos?filter=text=*borked*'); + expect(response.status).toEqual(200); + expect(response.body).toEqual(mockListBody); + expect(mockService.listTodos).toHaveBeenCalledWith( + { + entity: undefined, + offset: undefined, + limit: undefined, + filters: [{ field: 'text', value: '*borked*' }], + }, + { token: undefined }, + ); + }); + it('rejects invalid queries', async () => { request(app) .get('/v1/todos?entity=k:n&entity=k:n')