From 5a6afbe874a8d3bbb306df1e6cd8c48bf8c53b72 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sat, 6 Apr 2024 11:57:30 +0200 Subject: [PATCH] openapi3filter: some syntax tweaks (#933) Signed-off-by: Pierre Fenoll --- openapi3filter/req_resp_decoder.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openapi3filter/req_resp_decoder.go b/openapi3filter/req_resp_decoder.go index 4bcc3ae64..72e9d86d9 100644 --- a/openapi3filter/req_resp_decoder.go +++ b/openapi3filter/req_resp_decoder.go @@ -987,7 +987,7 @@ func buildResObj(params map[string]interface{}, parentKeys []string, key string, if err != nil { return nil, &ParseError{path: pathFromKeys(mapKeys), Kind: KindInvalidFormat, Reason: fmt.Sprintf("could not convert value map to array: %v", err)} } - resultArr := make([]interface{}, len(arr)) + resultArr := make([]interface{} /*not 0,*/, len(arr)) for i := range arr { r, err := buildResObj(params, mapKeys, strconv.Itoa(i), schema.Value.Items) if err != nil { @@ -1096,9 +1096,9 @@ func handlePropParseError(path []string, err error) error { } func pathFromKeys(kk []string) []interface{} { - path := make([]interface{}, len(kk)) - for i, v := range kk { - path[i] = v + path := make([]interface{}, 0, len(kk)) + for _, v := range kk { + path = append(path, v) } return path } @@ -1135,8 +1135,7 @@ func parsePrimitive(raw string, schema *openapi3.SchemaRef) (v interface{}, err return nil, nil } for _, typ := range schema.Value.Type.Slice() { - v, err = parsePrimitiveCase(raw, schema, typ) - if err == nil { + if v, err = parsePrimitiveCase(raw, schema, typ); err == nil { return } }