Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/gen_openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ vault secrets enable ssh
vault secrets enable totp
vault secrets enable transit

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

kill $VAULT_PID
sleep 1
Expand Down
10 changes: 1 addition & 9 deletions sdk/framework/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,6 @@ func documentPath(p *Path, specialPaths *logical.Paths, backendType logical.Back
required = false
}

// Header parameters are part of the Parameters group but with
// a dedicated "header" location, a header parameter is not required.
if field.Type == TypeHeader {
location = "header"
required = false
}

t := convertType(field.Type)
p := OASParameter{
Name: name,
Expand Down Expand Up @@ -608,8 +601,7 @@ func splitFields(allFields map[string]*FieldSchema, pattern string) (pathFields,

for name, field := range allFields {
if _, ok := pathFields[name]; !ok {
// Header fields are in "parameters" with other path fields
if field.Type == TypeHeader || field.Query {
if field.Query {
pathFields[name] = field
} else {
bodyFields[name] = field
Expand Down
34 changes: 23 additions & 11 deletions sdk/framework/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func TestOpenAPI_Regex(t *testing.T) {

func TestOpenAPI_ExpandPattern(t *testing.T) {
tests := []struct {
in_pattern string
out_pathlets []string
inPattern string
outPathlets []string
}{
{"rekey/backup", []string{"rekey/backup"}},
{"rekey/backup$", []string{"rekey/backup"}},
Expand Down Expand Up @@ -203,10 +203,10 @@ func TestOpenAPI_ExpandPattern(t *testing.T) {
}

for i, test := range tests {
out := expandPattern(test.in_pattern)
out := expandPattern(test.inPattern)
sort.Strings(out)
if !reflect.DeepEqual(out, test.out_pathlets) {
t.Fatalf("Test %d: Expected %v got %v", i, test.out_pathlets, out)
if !reflect.DeepEqual(out, test.outPathlets) {
t.Fatalf("Test %d: Expected %v got %v", i, test.outPathlets, out)
}
}
}
Expand Down Expand Up @@ -266,7 +266,10 @@ func TestOpenAPI_SpecialPaths(t *testing.T) {
Root: test.rootPaths,
Unauthenticated: test.unauthPaths,
}
documentPath(&path, sp, logical.TypeLogical, doc)
err := documentPath(&path, sp, logical.TypeLogical, doc)
if err != nil {
t.Fatal(err)
}
result := test.root
if doc.Paths["/"+test.pattern].Sudo != result {
t.Fatalf("Test (root) %d: Expected %v got %v", i, test.root, result)
Expand All @@ -288,11 +291,11 @@ func TestOpenAPI_Paths(t *testing.T) {
Pattern: "lookup/" + GenericNameRegex("id"),

Fields: map[string]*FieldSchema{
"id": &FieldSchema{
"id": {
Type: TypeString,
Description: "My id parameter",
},
"token": &FieldSchema{
"token": {
Type: TypeString,
Description: "My token",
},
Expand Down Expand Up @@ -442,8 +445,14 @@ func TestOpenAPI_OperationID(t *testing.T) {

for _, context := range []string{"", "bar"} {
doc := NewOASDocument()
documentPath(path1, nil, logical.TypeLogical, doc)
documentPath(path2, nil, logical.TypeLogical, doc)
err := documentPath(path1, nil, logical.TypeLogical, doc)
if err != nil {
t.Fatal(err)
}
err = documentPath(path2, nil, logical.TypeLogical, doc)
if err != nil {
t.Fatal(err)
}
doc.CreateOperationIDs(context)

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

docOrig := NewOASDocument()
documentPath(p, nil, logical.TypeLogical, docOrig)
err := documentPath(p, nil, logical.TypeLogical, docOrig)
if err != nil {
t.Fatal(err)
}

docJSON := mustJSONMarshal(t, docOrig)

Expand Down
14 changes: 5 additions & 9 deletions sdk/framework/testdata/operations.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@
"type": "string"
},
"required": true
},
{
"name": "x-abc-token",
"description": "a header value",
"in": "header",
"schema": {
"type": "string",
"enum": ["a", "b", "c"]
}
}
],
"get": {
Expand Down Expand Up @@ -95,6 +86,11 @@
"description": "the name",
"default": "Larry",
"pattern": "\\w([\\w-.]*\\w)?"
},
"x-abc-token": {
"type": "string",
"description": "a header value",
"enum": ["a", "b", "c"]
}
}
}
Expand Down