🎉 feat: rc.0

This commit is contained in:
saltyaom
2023-01-23 13:39:47 +07:00
parent 594e58c832
commit 376c7e4efd
4 changed files with 53 additions and 32 deletions
BIN
View File
Binary file not shown.
+33 -15
View File
@@ -3,8 +3,35 @@ import swagger from '../src/index'
const app = new Elysia()
.use(swagger())
.get('/', () => 'hi')
.get('/unpath/:id', ({ params: { id } }) => id)
.setModel({
sign: t.Object(
{
username: t.String(),
password: t.String()
},
{
title: 'Sign Model',
description: 'Models for handling authentication'
}
),
number: t.Number()
})
.get('/', () => 'hi', {
schema: {
detail: {
summary: 'Ping Pong',
description: 'Lorem Ipsum Dolar',
tags: ['Test']
}
}
})
.get('/unpath/:id', ({ params: { id } }) => id, {
schema: {
detail: {
deprecated: false
}
}
})
.post(
'/json/:id',
({ body, params: { id }, query: { name } }) => ({
@@ -13,10 +40,7 @@ const app = new Elysia()
}),
{
schema: {
body: t.Object({
username: t.String(),
password: t.String()
}),
body: 'sign',
response: t.Object({
username: t.String(),
password: t.String(),
@@ -26,16 +50,10 @@ const app = new Elysia()
}
)
.get('/unpath/:id/:name', ({ params: { id } }) => id)
.post('/json', ({ body }) => body, {
.post('/json', ({ body }) => '1', {
schema: {
body: t.Object({
username: t.String(),
password: t.String()
}),
response: t.Object({
username: t.String(),
password: t.String()
})
body: 'sign',
response: 'sign'
}
})
.listen(8080)
+6 -7
View File
@@ -1,6 +1,6 @@
{
"name": "@elysiajs/swagger",
"version": "0.1.1",
"version": "0.2.0-rc.0",
"description": "Plugin for Elysia to auto-generate Swagger page",
"author": {
"name": "saltyAom",
@@ -33,19 +33,18 @@
"release": "npm run build && npm run test && npm publish --access public"
},
"peerDependencies": {
"elysia": ">= 0.1.0"
"elysia": ">= 0.2.0-rc.0"
},
"devDependencies": {
"@types/node": "^18.11.7",
"@types/swagger-ui-dist": "^3.30.1",
"bun-types": "^0.2.2",
"bun-types": "^0.5.0",
"eslint": "^8.26.0",
"elysia": "^0.1.0",
"typescript": "^4.8.4"
"elysia": "^0.2.0-rc.0",
"typescript": "^4.9.3"
},
"dependencies": {
"@elysiajs/static": "0.1.0",
"openapi-types": "^12.0.2",
"@elysiajs/static": "0.2.0-rc.0",
"swagger-ui-dist": "^4.15.5"
}
}
+14 -10
View File
@@ -1,4 +1,4 @@
import { type Elysia, SCHEMA } from 'elysia'
import { type Elysia, SCHEMA, DEFS } from 'elysia'
import { getAbsoluteFSPath } from 'swagger-ui-dist'
import { staticPlugin } from '@elysiajs/static'
@@ -34,11 +34,10 @@ export const swagger =
exclude: []
}
) =>
(app: Elysia) =>
app
.get(path, (context) => {
context.set.redirect = `${path}/static/index.html`
})
(app: Elysia) => {
app.get(path, (context) => {
context.set.redirect = `${path}/static/index.html`
})
.get(
`${path}/static/swagger-initializer.js`,
() =>
@@ -48,7 +47,7 @@ export const swagger =
}
})
)
.get(`${path}/json`, (context) => ({
.get(`${path}/json`, ({ store }) => ({
...{
...defaultConfig,
...swagger,
@@ -59,16 +58,21 @@ export const swagger =
...swagger.info
}
},
paths: filterPaths(context.store[SCHEMA], {
paths: filterPaths(store[SCHEMA], {
excludeStaticFile,
exclude: Array.isArray(exclude) ? exclude : [exclude]
})
}),
definitions: store[DEFS]
}))
.use(
staticPlugin({
prefix: `${path}/static`,
path: getAbsoluteFSPath()
assets: getAbsoluteFSPath()
})
)
// This is intentional to prevent deeply nested type
return app
}
export default swagger