🎉 feat: 0.8.5

This commit is contained in:
saltyaom
2024-01-24 17:10:31 +07:00
parent 48d525a0c1
commit d3aecbc921
7 changed files with 218 additions and 163 deletions

View File

@@ -1,19 +1,30 @@
import { Elysia, t } from 'elysia'
import SwaggerParser from '@apidevtools/swagger-parser';
import SwaggerParser from '@apidevtools/swagger-parser'
import { swagger } from '../src'
import { describe, expect, it } from 'bun:test'
import { fail } from 'assert';
import { fail } from 'assert'
const req = (path: string) => new Request(`http://localhost${path}`)
it('returns a valid Swagger/OpenAPI json config for many routes', async () => {
const app = new Elysia()
.use(swagger())
.get('/', () => 'hi', { response: t.String({ description: 'sample description' }) })
.get('/unpath/:id', ({ params: { id } }) => id, { response: t.String({ description: 'sample description' }) })
.get('/unpath/:id/:name/:age', ({ params: { id, name } }) => `${id} ${name}`,
{ type: "json", response: t.String({ description: 'sample description' }), params: t.Object({ id: t.String(), name: t.String() }) })
.get('/', () => 'hi', {
response: t.String({ description: 'sample description' })
})
.get('/unpath/:id', ({ params: { id } }) => id, {
response: t.String({ description: 'sample description' })
})
.get(
'/unpath/:id/:name/:age',
({ params: { id, name } }) => `${id} ${name}`,
{
type: 'json',
response: t.String({ description: 'sample description' }),
params: t.Object({ id: t.String(), name: t.String() })
}
)
.post(
'/json/:id',
({ body, params: { id }, query: { name } }) => ({
@@ -32,14 +43,18 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => {
username: t.String(),
password: t.String()
}),
response: t.Object({
username: t.String(),
password: t.String(),
id: t.String(),
name: t.String()
}, { description: 'sample description 3' })
response: t.Object(
{
username: t.String(),
password: t.String(),
id: t.String(),
name: t.String()
},
{ description: 'sample description 3' }
)
}
);
const res = await app.handle(req('/swagger/json')).then((x) => x.json());
await SwaggerParser.validate(res).catch((err) => fail(err));
});
)
const res = await app.handle(req('/swagger/json')).then((x) => x.json())
await SwaggerParser.validate(res).catch((err) => fail(err))
})