From dd04ad543a2e59bacbee88e1eaa236984d593b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 15 Feb 2025 16:00:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcontent=5Ftype=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generate.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/generate.go b/generate.go index 6f04556..405cc62 100644 --- a/generate.go +++ b/generate.go @@ -654,20 +654,22 @@ func (g *Generate) parseBaseUriConfig(uriPrefix string, paramType reflect.Type) res.OutputStrict = outputStrictModel == "1" || outputStrictModel == "true" deprecated := metaField.Tag.Get(define.TagDeprecated) res.Deprecated = deprecated == "1" || deprecated == "true" - res.ContentType = strings.Split(metaField.Tag.Get(define.TagContentType), ",") - if len(res.ContentType) == 0 { + requestContentType := strings.TrimSpace(metaField.Tag.Get(define.TagContentType)) + if len(requestContentType) == 0 { if wrapper.ArrayType(g.readMethodList).Has(res.Method) >= 0 { // get类请求 - res.ContentType = []string{consts.MimeTypeXWWWFormUrlencoded} + requestContentType = consts.MimeTypeXWWWFormUrlencoded } else { - res.ContentType = []string{consts.MimeTypeJson} + requestContentType = consts.MimeTypeJson } } - res.OutputContentType = strings.Split(metaField.Tag.Get(define.TagOutputContentType), ",") - if len(res.OutputContentType) == 0 { + res.ContentType = strings.Split(requestContentType, ",") + responseContentType := strings.TrimSpace(metaField.Tag.Get(define.TagOutputContentType)) + if len(responseContentType) == 0 { // 未设置响应类型默认JSON数据 - res.OutputContentType = []string{consts.MimeTypeJson} + responseContentType = consts.MimeTypeJson } + res.OutputContentType = strings.Split(responseContentType, ",") res.Summary = ParseStructField.Summary(metaField) if res.Method == "" { return nil, errors.New("baseCfg.Method is empty")