address feedback and double fix schema
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
@@ -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<Server> {
|
||||
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
|
||||
|
||||
@@ -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<LocationAnalyzer>;
|
||||
let permissionsService: jest.Mocked<PermissionsService>;
|
||||
|
||||
setupProxyHooks();
|
||||
|
||||
beforeAll(async () => {
|
||||
entitiesCatalog = {
|
||||
entities: jest.fn(),
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user