Skip to content

Commit 8b6ea17

Browse files
author
Jim Kalafut
authored
Don't show TypeHeader fields as being sent as headers in OpenAPI (#6679)
Fixes #6671
1 parent caa2a06 commit 8b6ea17

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

scripts/gen_openapi.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ vault secrets enable ssh
6161
vault secrets enable totp
6262
vault secrets enable transit
6363

64-
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" > openapi.json
64+
if [ "$1" == "-p" ]; then
65+
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" | jq > openapi.json
66+
else
67+
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" > openapi.json
68+
fi
6569

6670
kill $VAULT_PID
6771
sleep 1

sdk/framework/openapi.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,6 @@ func documentPath(p *Path, specialPaths *logical.Paths, backendType logical.Back
257257
required = false
258258
}
259259

260-
// Header parameters are part of the Parameters group but with
261-
// a dedicated "header" location, a header parameter is not required.
262-
if field.Type == TypeHeader {
263-
location = "header"
264-
required = false
265-
}
266-
267260
t := convertType(field.Type)
268261
p := OASParameter{
269262
Name: name,
@@ -608,8 +601,7 @@ func splitFields(allFields map[string]*FieldSchema, pattern string) (pathFields,
608601

609602
for name, field := range allFields {
610603
if _, ok := pathFields[name]; !ok {
611-
// Header fields are in "parameters" with other path fields
612-
if field.Type == TypeHeader || field.Query {
604+
if field.Query {
613605
pathFields[name] = field
614606
} else {
615607
bodyFields[name] = field

sdk/framework/openapi_test.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func TestOpenAPI_Regex(t *testing.T) {
151151

152152
func TestOpenAPI_ExpandPattern(t *testing.T) {
153153
tests := []struct {
154-
in_pattern string
155-
out_pathlets []string
154+
inPattern string
155+
outPathlets []string
156156
}{
157157
{"rekey/backup", []string{"rekey/backup"}},
158158
{"rekey/backup$", []string{"rekey/backup"}},
@@ -203,10 +203,10 @@ func TestOpenAPI_ExpandPattern(t *testing.T) {
203203
}
204204

205205
for i, test := range tests {
206-
out := expandPattern(test.in_pattern)
206+
out := expandPattern(test.inPattern)
207207
sort.Strings(out)
208-
if !reflect.DeepEqual(out, test.out_pathlets) {
209-
t.Fatalf("Test %d: Expected %v got %v", i, test.out_pathlets, out)
208+
if !reflect.DeepEqual(out, test.outPathlets) {
209+
t.Fatalf("Test %d: Expected %v got %v", i, test.outPathlets, out)
210210
}
211211
}
212212
}
@@ -266,7 +266,10 @@ func TestOpenAPI_SpecialPaths(t *testing.T) {
266266
Root: test.rootPaths,
267267
Unauthenticated: test.unauthPaths,
268268
}
269-
documentPath(&path, sp, logical.TypeLogical, doc)
269+
err := documentPath(&path, sp, logical.TypeLogical, doc)
270+
if err != nil {
271+
t.Fatal(err)
272+
}
270273
result := test.root
271274
if doc.Paths["/"+test.pattern].Sudo != result {
272275
t.Fatalf("Test (root) %d: Expected %v got %v", i, test.root, result)
@@ -288,11 +291,11 @@ func TestOpenAPI_Paths(t *testing.T) {
288291
Pattern: "lookup/" + GenericNameRegex("id"),
289292

290293
Fields: map[string]*FieldSchema{
291-
"id": &FieldSchema{
294+
"id": {
292295
Type: TypeString,
293296
Description: "My id parameter",
294297
},
295-
"token": &FieldSchema{
298+
"token": {
296299
Type: TypeString,
297300
Description: "My token",
298301
},
@@ -442,8 +445,14 @@ func TestOpenAPI_OperationID(t *testing.T) {
442445

443446
for _, context := range []string{"", "bar"} {
444447
doc := NewOASDocument()
445-
documentPath(path1, nil, logical.TypeLogical, doc)
446-
documentPath(path2, nil, logical.TypeLogical, doc)
448+
err := documentPath(path1, nil, logical.TypeLogical, doc)
449+
if err != nil {
450+
t.Fatal(err)
451+
}
452+
err = documentPath(path2, nil, logical.TypeLogical, doc)
453+
if err != nil {
454+
t.Fatal(err)
455+
}
447456
doc.CreateOperationIDs(context)
448457

449458
tests := []struct {
@@ -500,7 +509,10 @@ func TestOpenAPI_CustomDecoder(t *testing.T) {
500509
}
501510

502511
docOrig := NewOASDocument()
503-
documentPath(p, nil, logical.TypeLogical, docOrig)
512+
err := documentPath(p, nil, logical.TypeLogical, docOrig)
513+
if err != nil {
514+
t.Fatal(err)
515+
}
504516

505517
docJSON := mustJSONMarshal(t, docOrig)
506518

sdk/framework/testdata/operations.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@
3131
"type": "string"
3232
},
3333
"required": true
34-
},
35-
{
36-
"name": "x-abc-token",
37-
"description": "a header value",
38-
"in": "header",
39-
"schema": {
40-
"type": "string",
41-
"enum": ["a", "b", "c"]
42-
}
4334
}
4435
],
4536
"get": {
@@ -95,6 +86,11 @@
9586
"description": "the name",
9687
"default": "Larry",
9788
"pattern": "\\w([\\w-.]*\\w)?"
89+
},
90+
"x-abc-token": {
91+
"type": "string",
92+
"description": "a header value",
93+
"enum": ["a", "b", "c"]
9894
}
9995
}
10096
}

0 commit comments

Comments
 (0)