2
0
فهرست منبع

注册Bearer认证方案

yourname 6 ماه پیش
والد
کامیت
2f5b3b8c23
2فایلهای تغییر یافته به همراه15 افزوده شده و 2 حذف شده
  1. 11 1
      src/server/api.ts
  2. 4 1
      src/server/index.tsx

+ 11 - 1
src/server/api.ts

@@ -26,14 +26,24 @@ const createApi = (app:OpenAPIHono) => {
   app.route('/api/v1', authOpenApiApp)
 
   // OpenAPI documentation endpoint
-  app.doc('/doc', {
+  app.doc31('/doc', {
     openapi: '3.1.0',
     info: {
       title: 'API Documentation',
       version: '1.0.0'
     },
+    security: [{
+      bearerAuth: []
+    }]
     // servers: [{ url: '/api/v1' }]
   })
+  // 注册Bearer认证方案
+  app.openAPIRegistry.registerComponent('securitySchemes','bearerAuth',{
+    type:'http',
+    scheme:'bearer',
+    bearerFormat:'JWT',
+    description:'使用JWT进行认证'
+  })
 
   return app;
 

+ 4 - 1
src/server/index.tsx

@@ -25,7 +25,10 @@ createApi(app);
 
 app.use(renderer)
 
-app.get('/ui', swaggerUI({ url: '/doc' }))
+app.get('/ui', swaggerUI({
+  url: '/doc',
+  persistAuthorization: true
+}))
 
 app.get('/*', (c) => {
   return c.render(