mirror of
https://github.com/karust/openserp.git
synced 2026-08-05 16:53:54 +08:00
fix: openapi yaml parse error + /extract/batch timeout exemption
This commit is contained in:
@@ -65,10 +65,10 @@ func RequestContextMiddleware() fiber.Handler {
|
||||
|
||||
// RequestTimeoutMiddleware bounds wall-clock time per request by attaching a
|
||||
// deadline to the user context, which fasthttp never cancels on client
|
||||
// disconnect. /mega/* (MegaTimeout) and /extract (batch budget) are exempt.
|
||||
// disconnect. /mega/* (MegaTimeout) and /extract* (batch budget) are exempt.
|
||||
func RequestTimeoutMiddleware(timeout time.Duration) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
if strings.HasPrefix(c.Path(), "/mega/") || c.Path() == "/extract" {
|
||||
if strings.HasPrefix(c.Path(), "/mega/") || c.Path() == "/extract" || c.Path() == "/extract/batch" {
|
||||
return c.Next()
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(c.UserContext(), timeout)
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
// FP-2: every endpoint that doesn't manage its own deadline budget must get
|
||||
// one from RequestTimeoutMiddleware; /mega/* (MegaTimeout) and /extract
|
||||
// (batch budget) keep theirs.
|
||||
// one from RequestTimeoutMiddleware; /mega/* (MegaTimeout) and /extract,
|
||||
// /extract/batch (batch budget) keep theirs.
|
||||
func TestRequestTimeoutMiddlewareSetsDeadlineExceptBudgetedPaths(t *testing.T) {
|
||||
app := fiber.New()
|
||||
app.Use(RequestTimeoutMiddleware(time.Minute))
|
||||
@@ -32,12 +32,14 @@ func TestRequestTimeoutMiddlewareSetsDeadlineExceptBudgetedPaths(t *testing.T) {
|
||||
app.Post("/google/parse", record("/google/parse"))
|
||||
app.Get("/mega/search", record("/mega/search"))
|
||||
app.Get("/extract", record("/extract"))
|
||||
app.Post("/extract/batch", record("/extract/batch"))
|
||||
|
||||
for path, method := range map[string]string{
|
||||
"/google/search": http.MethodGet,
|
||||
"/google/parse": http.MethodPost,
|
||||
"/mega/search": http.MethodGet,
|
||||
"/extract": http.MethodGet,
|
||||
"/extract/batch": http.MethodPost,
|
||||
} {
|
||||
req := httptest.NewRequest(method, path, nil)
|
||||
resp, err := app.Test(req, -1)
|
||||
@@ -54,6 +56,7 @@ func TestRequestTimeoutMiddlewareSetsDeadlineExceptBudgetedPaths(t *testing.T) {
|
||||
"/google/parse": true,
|
||||
"/mega/search": false,
|
||||
"/extract": false,
|
||||
"/extract/batch": false,
|
||||
} {
|
||||
if deadlines[path] != want {
|
||||
t.Errorf("%s: deadline attached = %v, want %v", path, deadlines[path], want)
|
||||
|
||||
@@ -2080,7 +2080,7 @@ components:
|
||||
mode:
|
||||
type: string
|
||||
enum: [auto, fast, rendered]
|
||||
description: Extraction mode (default: auto)
|
||||
description: "Extraction mode (default: auto)"
|
||||
|
||||
BatchExtractItem:
|
||||
type: object
|
||||
|
||||
Reference in New Issue
Block a user