-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
case-insensitive header comparison (#488)
- Loading branch information
Reuven Harrison
authored
Feb 6, 2024
1 parent
957bdc6
commit f7552e1
Showing
13 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: Test API | ||
version: v1 | ||
paths: | ||
/test: | ||
parameters: | ||
- in: header | ||
name: X-Case | ||
required: true | ||
schema: | ||
type: string | ||
get: | ||
tags: | ||
- Test | ||
responses: | ||
"200": | ||
description: Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: Test API | ||
version: v1 | ||
paths: | ||
/test: | ||
parameters: | ||
- in: header | ||
name: x-case | ||
required: true | ||
schema: | ||
type: string | ||
get: | ||
tags: | ||
- Test | ||
responses: | ||
"200": | ||
description: Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Package headers replaces all header names to lowercase | ||
*/ | ||
package headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package headers | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
) | ||
|
||
// Lowercase replaces header names to lowercase | ||
func Lowercase(spec *openapi3.T) { | ||
lowerHeaderNames(spec) | ||
} | ||
|
||
func lowerHeaderNames(spec *openapi3.T) { | ||
for _, path := range spec.Paths.Map() { | ||
|
||
for _, paramRef := range path.Parameters { | ||
lowerHeaderName(paramRef.Value) | ||
} | ||
|
||
for _, op := range path.Operations() { | ||
for _, paramRef := range op.Parameters { | ||
lowerHeaderName(paramRef.Value) | ||
} | ||
|
||
for _, responseRef := range op.Responses.Map() { | ||
for _, headerRef := range responseRef.Value.Headers { | ||
lowerHeaderName(&headerRef.Value.Parameter) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func lowerHeaderName(param *openapi3.Parameter) { | ||
if param.In != openapi3.ParameterInHeader { | ||
return | ||
} | ||
|
||
param.Name = strings.ToLower(param.Name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters