Files
gitbook/packages/react-openapi/src/OpenAPISchema.test.ts
T
2025-01-30 08:44:08 +01:00

102 lines
2.5 KiB
TypeScript

import { it, describe, expect } from 'bun:test';
import { getSchemaAlternatives } from './OpenAPISchema';
import { OpenAPIV3 } from '@scalar/openapi-types';
describe('getSchemaAlternatives', () => {
it('should flatten oneOf', () => {
expect(
getSchemaAlternatives({
oneOf: [
{
oneOf: [
{
type: 'number',
},
{
type: 'boolean',
},
],
},
{
type: 'string',
},
],
}),
).toEqual([
[
{
type: 'number',
},
{
type: 'boolean',
},
{
type: 'string',
},
],
undefined,
]);
});
it('should not flatten oneOf and allOf', () => {
expect(
getSchemaAlternatives({
oneOf: [
{
allOf: [
{
type: 'number',
},
{
type: 'boolean',
},
],
},
{
type: 'string',
},
],
}),
).toEqual([
[
{
allOf: [
{
type: 'number',
},
{
type: 'boolean',
},
],
},
{
type: 'string',
},
],
undefined,
]);
});
it('should stop at circular references', () => {
const a: OpenAPIV3.SchemaObject = {
anyOf: [
{
type: 'string',
},
],
};
a.anyOf!.push(a);
expect(getSchemaAlternatives(a)).toEqual([
[
{
type: 'string',
},
a,
],
undefined,
]);
});
});