diff --git a/openapi/parser/_testdata/negative/parameters/cookie/invalid_cookie_name.json b/openapi/parser/_testdata/negative/parameters/cookie/invalid_cookie_name.json new file mode 100644 index 000000000..7ff04a332 --- /dev/null +++ b/openapi/parser/_testdata/negative/parameters/cookie/invalid_cookie_name.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "title", + "version": "v0.1.0" + }, + "paths": { + "/foo": { + "get": { + "parameters": [ + { + "name": "", + "in": "cookie", + "style": "form", + "explode": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "User info" + } + } + } + } + } +} diff --git a/openapi/parser/parse_parameter.go b/openapi/parser/parse_parameter.go index 6e952cdad..52ade0240 100644 --- a/openapi/parser/parse_parameter.go +++ b/openapi/parser/parse_parameter.go @@ -7,6 +7,7 @@ import ( "golang.org/x/net/http/httpguts" "github.com/ogen-go/ogen" + "github.com/ogen-go/ogen/internal/httpcookie" "github.com/ogen-go/ogen/internal/jsonpointer" "github.com/ogen-go/ogen/internal/location" "github.com/ogen-go/ogen/jsonschema" @@ -110,6 +111,11 @@ func (p *parser) validateParameter( err := errors.Errorf("invalid header name %q", name) return p.wrapField("name", file, locator, err) } + case openapi.LocationCookie: + if !httpcookie.IsCookieNameValid(name) { + err := errors.Errorf("invalid cookie name %q", name) + return p.wrapField("name", file, locator, err) + } } return nil }