Skip to content

Commit

Permalink
added OAS test
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed May 22, 2024
1 parent 6510265 commit e681cd0
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/kbn-config-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export const schema = {
contextRef,
duration,
ip,
lazy,
literal,
mapOf,
maybe,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 52 additions & 1 deletion packages/kbn-router-to-openapispec/src/generate_oas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
*/

import { generateOpenApiDocument } from './generate_oas';
import { schema } from '@kbn/config-schema';
import { schema, Type } from '@kbn/config-schema';
import { createTestRouters, createRouter, createVersionedRouter } from './generate_oas.test.util';

interface RecursiveType {
name: string;
self: undefined | RecursiveType;
}

describe('generateOpenApiDocument', () => {
describe('@kbn/config-schema', () => {
it('generates the expected OpenAPI document', () => {
Expand Down Expand Up @@ -70,6 +75,52 @@ describe('generateOpenApiDocument', () => {
)
).toMatchSnapshot();
});

it('handles recursive schemas', () => {
const id = 'recursive';
const recursiveSchema: Type<RecursiveType> = schema.object(
{
name: schema.string(),
self: schema.lazy<RecursiveType>(id),
},
{ meta: { id } }
);
expect(
generateOpenApiDocument(
{
routers: [
createRouter({
routes: [
{
isVersioned: false,
path: '/recursive',
method: 'get',
validationSchemas: {
request: {
body: recursiveSchema,
},
response: {
[200]: {
body: () => schema.string({ maxLength: 10, minLength: 1 }),
},
},
},
options: { tags: ['foo'] },
handler: jest.fn(),
},
],
}),
],
versionedRouters: [],
},
{
title: 'test',
baseUrl: 'https://test.oas',
version: '99.99.99',
}
)
).toMatchSnapshot();
});
});

describe('unknown schema/validation', () => {
Expand Down

0 comments on commit e681cd0

Please sign in to comment.