diff --git a/packages/backend-openapi-utils/src/testUtils.ts b/packages/backend-openapi-utils/src/testUtils.ts index ea329332bd..ebe22fce26 100644 --- a/packages/backend-openapi-utils/src/testUtils.ts +++ b/packages/backend-openapi-utils/src/testUtils.ts @@ -17,21 +17,7 @@ import { Express } from 'express'; import { Server } from 'http'; import { Proxy } from './proxy/setup'; -const proxy = new Proxy(); - -/** - * Setup the proxy hooks for the test suite. This will start the proxy before all tests and stop it after all tests. - * @public - */ -export function setupProxyHooks() { - beforeAll(async () => { - await proxy.setup(); - }); - - afterAll(() => { - proxy.stop(); - }); -} +const proxiesToCleanup: Proxy[] = []; /** * !!! THIS CURRENTLY ONLY SUPPORTS SUPERTEST !!! @@ -42,11 +28,33 @@ export function setupProxyHooks() { * @public */ export async function wrapServer(app: Express): Promise { + const proxy = new Proxy(); + await proxy.setup(); const server = app.listen(proxy.forwardTo.port); await proxy.initialize(`http://localhost:${proxy.forwardTo.port}`, server); + return { ...server, address: () => new URL(proxy.url) } as any; } +let registered = false; +function registerHooks() { + if (typeof afterAll !== 'function' || typeof beforeAll !== 'function') { + return; + } + if (registered) { + return; + } + registered = true; + + afterAll(() => { + for (const proxy of proxiesToCleanup) { + proxy.stop(); + } + }); +} + +registerHooks(); + /** * !!! THIS CURRENTLY ONLY SUPPORTS SUPERTEST !!! * Running against supertest, we need some way to hit the optic proxy. This ensures that diff --git a/plugins/catalog-backend/src/service/createRouter.test.ts b/plugins/catalog-backend/src/service/createRouter.test.ts index 3b478a2a84..6654187526 100644 --- a/plugins/catalog-backend/src/service/createRouter.test.ts +++ b/plugins/catalog-backend/src/service/createRouter.test.ts @@ -38,7 +38,7 @@ import { RESOURCE_TYPE_CATALOG_ENTITY } from '@backstage/plugin-catalog-common/a import { CatalogProcessingOrchestrator } from '../processing/types'; import { z } from 'zod'; import { decodeCursor, encodeCursor } from './util'; -import { setupProxyHooks, wrapServer } from '@backstage/backend-openapi-utils'; +import { wrapServer } from '@backstage/backend-openapi-utils'; import { Server } from 'http'; import { mockCredentials, mockServices } from '@backstage/backend-test-utils'; import { LocationAnalyzer } from '@backstage/plugin-catalog-node'; @@ -53,8 +53,6 @@ describe('createRouter readonly disabled', () => { let locationAnalyzer: jest.Mocked; let permissionsService: jest.Mocked; - setupProxyHooks(); - beforeAll(async () => { entitiesCatalog = { entities: jest.fn(), diff --git a/plugins/search-backend/src/schema/openapi.generated.ts b/plugins/search-backend/src/schema/openapi.generated.ts index 56aaeb2bbe..1e6adfb08f 100644 --- a/plugins/search-backend/src/schema/openapi.generated.ts +++ b/plugins/search-backend/src/schema/openapi.generated.ts @@ -207,8 +207,7 @@ export const spec = { name: 'filters', in: 'query', required: false, - style: 'form', - explode: true, + style: 'deepObject', allowReserved: true, schema: { $ref: '#/components/schemas/JsonObject', @@ -244,6 +243,18 @@ export const spec = { type: 'integer', }, }, + { + name: 'unknown', + in: 'query', + required: false, + style: 'form', + explode: true, + allowReserved: true, + schema: { + type: 'object', + additionalProperties: true, + }, + }, ], }, }, diff --git a/plugins/search-backend/src/schema/openapi.yaml b/plugins/search-backend/src/schema/openapi.yaml index a49b783b64..cbf3db273a 100644 --- a/plugins/search-backend/src/schema/openapi.yaml +++ b/plugins/search-backend/src/schema/openapi.yaml @@ -139,8 +139,7 @@ paths: - name: filters in: query required: false - style: form - explode: true + style: deepObject allowReserved: true schema: # JsonObject is used here instead of the full ZOD schema definition as @@ -167,3 +166,13 @@ paths: allowReserved: true schema: type: integer + - name: unknown + in: query + required: false + # explode form is the equivalent to allow any extra query parameters + style: form + explode: true + allowReserved: true + schema: + type: object + additionalProperties: true diff --git a/plugins/search-backend/src/service/router.test.ts b/plugins/search-backend/src/service/router.test.ts index 41b03501a3..5b6900ede1 100644 --- a/plugins/search-backend/src/service/router.test.ts +++ b/plugins/search-backend/src/service/router.test.ts @@ -23,7 +23,7 @@ import { import express from 'express'; import request from 'supertest'; import { createRouter } from './router'; -import { setupProxyHooks, wrapServer } from '@backstage/backend-openapi-utils'; +import { wrapServer } from '@backstage/backend-openapi-utils'; import { Server } from 'http'; import { mockCredentials, @@ -55,8 +55,6 @@ describe('createRouter', () => { }, }; - setupProxyHooks(); - beforeAll(async () => { const logger = mockServices.logger.mock(); mockSearchEngine = {