test: add schemaKeyword tests

This commit is contained in:
hgpark
2024-03-22 12:30:43 +09:00
parent c6727c7144
commit 4ae982987f
+29 -5
View File
@@ -2,7 +2,7 @@ import { Elysia, t } from 'elysia'
import SwaggerParser from '@apidevtools/swagger-parser'
import { swagger } from '../src'
import { describe, expect, it } from 'bun:test'
import { it } from 'bun:test'
import { fail } from 'assert'
const req = (path: string) => new Request(`http://localhost${path}`)
@@ -27,17 +27,30 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => {
)
.post(
'/json/:id',
({ body, params: { id }, query: { name } }) => ({
({ body, params: { id }, query: { name, email, birthday } }) => ({
...body,
id,
name
name,
email,
birthday
}),
{
params: t.Object({
id: t.String()
}),
query: t.Object({
name: t.String()
name: t.String(),
email: t.String({
description: 'sample email description',
format: 'email'
}),
birthday: t.String({
description: 'sample birthday description',
pattern: '\\d{4}-\\d{2}-\\d{2}',
minLength: 10,
maxLength: 10
}),
}),
body: t.Object({
username: t.String(),
@@ -48,7 +61,17 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => {
username: t.String(),
password: t.String(),
id: t.String(),
name: t.String()
name: t.String(),
email: t.String({
description: 'sample email description',
format: 'email'
}),
birthday: t.String({
description: 'sample birthday description',
pattern: '\\d{4}-\\d{2}-\\d{2}',
minLength: 10,
maxLength: 10
}),
},
{ description: 'sample description 3' }
)
@@ -56,5 +79,6 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => {
)
const res = await app.handle(req('/swagger/json')).then((x) => x.json())
console.log(res.paths['/json/{id}'].post.parameters)
await SwaggerParser.validate(res).catch((err) => fail(err))
})