mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
refactor: enhance OpenAPI integration and security handling
- Updated GetOpenAPI function to improve clarity by storing the Fizz instance in a variable. - Added security middleware to FizzWrapper for API token authentication, enhancing security measures. - Configured sorting of tags in the OpenAPI generator to maintain consistency in API documentation. - Improved comments for better understanding of the changes made in the OpenAPI wrapper.
This commit is contained in:
@@ -6,11 +6,14 @@ import (
|
||||
)
|
||||
|
||||
func GetOpenAPI(c *gin.Context) {
|
||||
f := globalWrapper.GetFizz()
|
||||
|
||||
info := &openapi.Info{
|
||||
Title: "Crawlab API",
|
||||
Description: "REST API for Crawlab",
|
||||
Version: "0.7.0",
|
||||
}
|
||||
handleFunc := globalWrapper.GetFizz().OpenAPI(info, "json")
|
||||
|
||||
handleFunc := f.OpenAPI(info, "json")
|
||||
handleFunc(c)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package openapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/crawlab-team/fizz/openapi"
|
||||
"sync"
|
||||
|
||||
"github.com/crawlab-team/crawlab/core/interfaces"
|
||||
@@ -23,6 +24,21 @@ type FizzWrapper struct {
|
||||
func newFizzWrapper(engine *gin.Engine) *FizzWrapper {
|
||||
// Create a new Fizz instance using the existing Gin engine
|
||||
f := fizz.NewFromEngine(engine)
|
||||
|
||||
// Add security middleware
|
||||
f.Generator().SetSecuritySchemes(map[string]*openapi.SecuritySchemeOrRef{
|
||||
"apiToken": {
|
||||
SecurityScheme: &openapi.SecurityScheme{
|
||||
Type: "apiKey",
|
||||
Name: "API Token",
|
||||
In: "header",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Sort tags
|
||||
f.Generator().SetSortTags(false)
|
||||
|
||||
return &FizzWrapper{
|
||||
fizz: f,
|
||||
gin: engine,
|
||||
|
||||
Reference in New Issue
Block a user