mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2026-06-02 21:59:35 +00:00
test: add schemaKeyword tests
This commit is contained in:
@@ -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))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user