-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Headers prefixed with X-
are mistakenly ignored
#24
Comments
Have just run into this myself |
No problem, a simple fix in a couple of places. I'll work on this shortly. |
Available in |
@daveshanley There seems to be a regression of this issue in the I have also not checked if #54 has also re-surfaced, but I assume it is likely. Happy to help with a fix, if this would be useful. I would need some guidance with the codebase though. |
Hi Joe, Generally with each bug fix, I add a test to validate and prevent regressions. I may have missed this one, but I haven't heard any other comments from folks about it regressing. I do remember seeing that code again on my travels recently, but I didn't touch it, at least I can't remember touching it. So what would be helpful is a reproducible sample? |
Thanks for your swift response 👍 Under further investigation, the issue seems to only apply to response headers, and request headers are working as expected. The following is a package main
import (
"fmt"
"github.com/pb33f/libopenapi"
)
func main() {
fmt.Println("Spec with x-:")
printHeaders(`openapi: 3.0.0
paths:
/pets:
get:
parameters:
- name: x-api-key
in: header
responses:
'200':
headers:
x-next:
schema:
type: string
content:
application/json:
schema:
type: object
`)
fmt.Println("Spec without x-:")
printHeaders(`openapi: 3.0.0
paths:
/pets:
get:
parameters:
- name: api-key
in: header
responses:
'200':
headers:
next:
schema:
type: string
content:
application/json:
schema:
type: object
`)
}
func printHeaders(spec string) {
document, err := libopenapi.NewDocument([]byte(spec))
if err != nil {
panic(err)
}
v3Model, errs := document.BuildV3Model()
if len(errs) > 0 {
panic(errs)
}
for _, pathItem := range v3Model.Model.Paths.PathItems {
for _, op := range pathItem.GetOperations() {
fmt.Printf("\tRequest headers:\n")
for _, param := range op.Parameters {
if param.In == "header" {
fmt.Printf("\t\t- %s\n", param.Name)
}
}
fmt.Printf("\tResponse headers:\n")
for _, resp := range op.Responses.Codes {
for headerName, _ := range resp.Headers {
fmt.Printf("\t\t- %s\n", headerName)
}
}
}
}
} As can be seen in the output of this file's execution, request headers where correctly found, but the response headers were
Thanks for your time on this. |
Oh, I see, yeah, that should not happen. Will circle back to this on the next bug run at the end of the month. |
New extraction functions added (that just wrap the old ones). The difference here is that the extensions can be included or ignored now. This has been added to address issue #24 where header keys can in fact include an extension prefix. Signed-off-by: Dave Shanley <dave@quobix.com>
New extraction functions added (that just wrap the old ones). The difference here is that the extensions can be included or ignored now. This has been added to address issue #24 where header keys can in fact include an extension prefix. Signed-off-by: Dave Shanley <dave@quobix.com>
@JoeReid Can you try Header keys in responses can now use extension prefixes. |
While RFC 6648 deprecated the
X-
prefix we still have an API that includes the header (and some common proxies still include stuff likeX-Forwarded-For
). Interestingly, these seem to be completely ignored by libopenapi. I haven't dug into it yet but suspect this might clash with code handling the OpenAPI extensions which start withx-
as well. Notably the spec does not list headers as extensible via this method even though the response object itself does support it, so these should just be parsed as normal keys.Part of danielgtaylor/restish#115
The text was updated successfully, but these errors were encountered: