From b9f83d981fac434dfc687650f4237841b5cea5a4 Mon Sep 17 00:00:00 2001 From: Matthias Popp Date: Sat, 11 May 2024 09:29:32 +0200 Subject: [PATCH] openapi4filter: improve CSV resp decoder performance (#948) * Improve csv resp decoder performance Use String Builder for string concatenation * Update req_resp_decoder.go --- openapi3filter/req_resp_decoder.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openapi3filter/req_resp_decoder.go b/openapi3filter/req_resp_decoder.go index 72e9d86d9..1562a6693 100644 --- a/openapi3filter/req_resp_decoder.go +++ b/openapi3filter/req_resp_decoder.go @@ -1562,7 +1562,7 @@ func zipFileBodyDecoder(body io.Reader, header http.Header, schema *openapi3.Sch func csvBodyDecoder(body io.Reader, header http.Header, schema *openapi3.SchemaRef, encFn EncodingFn) (interface{}, error) { r := csv.NewReader(body) - var content string + var sb strings.Builder for { record, err := r.Read() if err == io.EOF { @@ -1572,8 +1572,9 @@ func csvBodyDecoder(body io.Reader, header http.Header, schema *openapi3.SchemaR return nil, err } - content += strings.Join(record, ",") + "\n" + sb.WriteString(strings.Join(record, ",")) + sb.WriteString("\n") } - return content, nil + return sb.String(), nil }