feat(repo-tools): add a new command that provides dynamic test-driven OpenAPI schema feedback.
Signed-off-by: Aramis Sennyey <aramiss@spotify.com> Signed-off-by: Aramis <sennyeyaramis@gmail.com>
This commit is contained in:
@@ -32,3 +32,4 @@ export type {
|
||||
} from './utility';
|
||||
export type { ApiRouter } from './router';
|
||||
export { createValidatedOpenApiRouter } from './stub';
|
||||
export { wrapInOpenApiTestServer } from './testUtils';
|
||||
|
||||
@@ -27,7 +27,6 @@ describe('createRouter', () => {
|
||||
status: 'available',
|
||||
photoUrls: [],
|
||||
};
|
||||
|
||||
it('does NOT override originalUrl and basePath after execution', async () => {
|
||||
expect.assertions(2);
|
||||
const router = createValidatedOpenApiRouter(singlePathSpec);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Express } from 'express';
|
||||
import { Server } from 'http';
|
||||
|
||||
/**
|
||||
* !!! THIS CURRENTLY ONLY SUPPORTS SUPERTEST !!!
|
||||
* Running against supertest, we need some way to hit the optic proxy. This ensures that
|
||||
* that happens at runtime when in the context of a `yarn optic capture` command.
|
||||
* @param app - Express router that would be passed to supertest's `request`.
|
||||
* @returns A wrapper around the express router (or the router untouched) that still works with supertest.
|
||||
* @public
|
||||
*/
|
||||
export const wrapInOpenApiTestServer = (app: Express): Server | Express => {
|
||||
if (process.env.OPTIC_PROXY) {
|
||||
const server = app.listen(+process.env.PORT!);
|
||||
return {
|
||||
...server,
|
||||
address: () => new URL(process.env.OPTIC_PROXY!),
|
||||
} as any;
|
||||
}
|
||||
return app;
|
||||
};
|
||||
Reference in New Issue
Block a user