import { Hono } from 'hono' import { SwaggerUI, swaggerUI } from '../src' describe('SwaggerUI Rendering', () => { const url = 'https://petstore3.swagger.io/api/v3/openapi.json' it('renders correctly with default UI version', () => { expect(SwaggerUI({ url }).toString()).toEqual(`
`) }) it('renders correctly with specified UI version', () => { expect(SwaggerUI({ url, version: '5.0.0' }).toString()).toEqual(`
`) }) it('renders correctly with custom UI', () => { expect( SwaggerUI({ url, manuallySwaggerUIHtml: (asset) => `
${asset.css.map((url) => ``)} ${asset.js.map((url) => ``)}
`.trim(), }).toString() ).toEqual( `
`.trim() ) }) }) describe('SwaggerUI Middleware', () => { let app: Hono beforeEach(() => { app = new Hono() }) it('responds with status 200', async () => { app.get('/', swaggerUI({ url: 'https://petstore3.swagger.io/api/v3/openapi.json' })) const res = await app.request('/') expect(res.status).toBe(200) }) it('collectly renders SwaggerUI with custom options', async () => { app.get( '/', swaggerUI({ url: 'https://petstore3.swagger.io/api/v3/openapi.json', spec: { info: { title: 'Custom UI', version: '1.0.0', }, }, presets: ['SwaggerUIStandalonePreset', 'SwaggerUIBundle.presets.apis'], operationsSorter: '(a, b) => a.get("path").localeCompare(b.get("path"))', }) ) const res = await app.request('/') expect(res.status).toBe(200) const html = await res.text() expect(html).toContain('https://petstore3.swagger.io/api/v3/openapi.json') // RENDER_TYPE.STRING expect(html).toContain('[SwaggerUIStandalonePreset,SwaggerUIBundle.presets.apis]') // RENDER_TYPE.STRING_ARRAY expect(html).toContain('(a, b) => a.get("path").localeCompare(b.get("path"))') // RENDER_TYPE.RAW expect(html).toContain('{"info":{"title":"Custom UI","version":"1.0.0"}}') // RENDER_TYPE.JSON_STRING expect(html).toContain('window.ui = SwaggerUIBundle({') // entry point of SwaggerUI }) })