mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2025-12-06 00:36:10 +00:00
60 lines
960 B
TypeScript
60 lines
960 B
TypeScript
import { Elysia, t } from 'elysia'
|
|
import { swagger } from '../src/index'
|
|
|
|
const schema = t.Object({
|
|
test: t.Literal('hello')
|
|
})
|
|
|
|
const app = new Elysia()
|
|
.use(
|
|
swagger({
|
|
provider: 'scalar',
|
|
documentation: {
|
|
info: {
|
|
title: 'Elysia Scalar',
|
|
version: '0.8.1'
|
|
},
|
|
tags: [
|
|
{
|
|
name: 'Test',
|
|
description: 'Hello'
|
|
}
|
|
],
|
|
components: {
|
|
schemas: {
|
|
User: {
|
|
description: 'string'
|
|
}
|
|
},
|
|
securitySchemes: {
|
|
JwtAuth: {
|
|
type: 'http',
|
|
scheme: 'bearer',
|
|
bearerFormat: 'JWT',
|
|
description: 'Enter JWT Bearer token **_only_**'
|
|
}
|
|
}
|
|
}
|
|
},
|
|
swaggerOptions: {
|
|
persistAuthorization: true
|
|
}
|
|
})
|
|
)
|
|
.model({ schema })
|
|
.get(
|
|
'/',
|
|
() => {
|
|
return { test: 'hello' as const }
|
|
},
|
|
{
|
|
response: 'schema'
|
|
}
|
|
)
|
|
.post('/json', ({ body }) => body, {
|
|
parse: 'formdata',
|
|
body: 'schema',
|
|
response: 'schema'
|
|
})
|
|
.listen(3000)
|