swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
335 stars 17 forks source link

Response header validation case sensitivity #141

Closed pboguslawski closed 1 year ago

pboguslawski commented 1 year ago

Describe the bug Accrording to #119 header names should be compared in case insensitive fashion.

When ETag response header is defined with ETag canonical name

ETag string `header:"ETag" json:"-" required:"true"`

response validation error is thrown (missing etag header value) even if ETag field is populated in response struct. No such error when response struct is defined with Etag header name

ETag string `header:"Etag" json:"-" required:"true"`

Expected behavior No response validation error thrown when header:"ETag" is used in struct definition.

vearutop commented 1 year ago

There is another problem in your example, required:"true" is an ineffective constraint once case sensitivity is solved.

required is checked against the presence of a key in an object, and string will always have at least "" zero value (as a header Etag:). You can use omitempty to convert zero value to key absence.

ETag string `header:"ETag,omitempty" json:"-" required:"true"`

Or use minLength:"1" instead of required:"true".

pboguslawski commented 1 year ago

Thank you. Please tag code after fixes to allow auto updating dependencies.