import { describe, expect, it } from 'bun:test';
import { OpenAPIParseError } from './error';
import { parseOpenAPI } from './parse';
const spec = await Bun.file(new URL('./fixtures/recursive-spec.json', import.meta.url)).text();
const specV2 = await Bun.file(new URL('./fixtures/spec-v2.json', import.meta.url)).text();
const html = `
API Documentation `;
describe('#parseOpenAPI', () => {
it('parses a recursive OpenAPI document', async () => {
const schema = await parseOpenAPI({
value: spec,
rootURL: null,
});
// Ensure the structure returned is not recursive (not dereferenced).
JSON.stringify(schema);
});
it('parses a swagger v2', async () => {
const schema = await parseOpenAPI({
value: specV2,
rootURL: null,
});
// Ensure the structure returned is not recursive (not dereferenced).
JSON.stringify(schema);
});
it('throws an error for invalid OpenAPI document', async () => {
expect.assertions(1);
try {
await parseOpenAPI({
value: html,
rootURL: null,
});
} catch (error) {
if (error instanceof OpenAPIParseError) {
expect(error.message).toContain('Invalid OpenAPI document');
}
}
});
});