From a34751a13dfb1a062d6088f96d7fde011bb8a43d Mon Sep 17 00:00:00 2001 From: xucong053 Date: Mon, 20 Jun 2022 10:15:30 +0800 Subject: [PATCH] fix: failed to load json/data content in api reference --- hrp/step_api.go | 4 ++++ hrp/testcase.go | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/hrp/step_api.go b/hrp/step_api.go index c1c52c3a..cce14cd0 100644 --- a/hrp/step_api.go +++ b/hrp/step_api.go @@ -47,7 +47,11 @@ func (path *APIPath) ToAPI() (*API, error) { if err != nil { return nil, err } + // 1. deal with request body compatibility + convertCompatRequestBody(api.Request) + // 2. deal with validators compatibility err = convertCompatValidator(api.Validators) + // 3. deal with extract expr including hyphen convertExtract(api.Extract) return api, err } diff --git a/hrp/testcase.go b/hrp/testcase.go index 4182cec7..bae01478 100644 --- a/hrp/testcase.go +++ b/hrp/testcase.go @@ -182,16 +182,7 @@ func (tc *TCase) MakeCompat() (err error) { }() for _, step := range tc.TestSteps { // 1. deal with request body compatibility - if step.Request != nil && step.Request.Body == nil { - if step.Request.Json != nil { - step.Request.Headers["Content-Type"] = "application/json; charset=utf-8" - step.Request.Body = step.Request.Json - step.Request.Json = nil - } else if step.Request.Data != nil { - step.Request.Body = step.Request.Data - step.Request.Data = nil - } - } + convertCompatRequestBody(step.Request) // 2. deal with validators compatibility err = convertCompatValidator(step.Validators) @@ -205,6 +196,19 @@ func (tc *TCase) MakeCompat() (err error) { return nil } +func convertCompatRequestBody(request *Request) { + if request != nil && request.Body == nil { + if request.Json != nil { + request.Headers["Content-Type"] = "application/json; charset=utf-8" + request.Body = request.Json + request.Json = nil + } else if request.Data != nil { + request.Body = request.Data + request.Data = nil + } + } +} + func convertCompatValidator(Validators []interface{}) (err error) { for i, iValidator := range Validators { if _, ok := iValidator.(Validator); ok {