mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-23 10:46:51 -04:00
Merge c3f6bc937e into 0a5e29e96f
This commit is contained in:
commit
0c112f28cc
3 changed files with 59 additions and 0 deletions
3
changelog/30715.txt
Normal file
3
changelog/30715.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
openapi: fix missing request schema for custom plugins
|
||||
```
|
||||
|
|
@ -64,10 +64,20 @@ func NewOASDocumentFromMap(input map[string]interface{}) (*OASDocument, error) {
|
|||
return inputRaw, nil
|
||||
}
|
||||
|
||||
// mapstructure does a strings.EqualFold check between a struct key and a map key.
|
||||
// This does not work for $ref key, a custom match is needed to cover this edge case.
|
||||
matchName := func(mapKey, fieldName string) bool {
|
||||
if strings.HasPrefix(mapKey, "$") {
|
||||
return strings.EqualFold(mapKey[1:], fieldName)
|
||||
}
|
||||
return strings.EqualFold(mapKey, fieldName)
|
||||
}
|
||||
|
||||
doc := new(OASDocument)
|
||||
|
||||
config := &mapstructure.DecoderConfig{
|
||||
DecodeHook: decodeHook,
|
||||
MatchName: matchName,
|
||||
Result: doc,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -744,6 +744,52 @@ func TestOpenAPI_CustomDecoder(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOpenAPI_CustomNameMatcher(t *testing.T) {
|
||||
p := &Path{
|
||||
Pattern: "foo",
|
||||
HelpSynopsis: "Synopsis",
|
||||
Fields: map[string]*FieldSchema{
|
||||
"foo": {
|
||||
Type: TypeString,
|
||||
Description: "foo description",
|
||||
},
|
||||
"bar": {
|
||||
Type: TypeString,
|
||||
Description: "bar description",
|
||||
},
|
||||
},
|
||||
Operations: map[logical.Operation]OperationHandler{
|
||||
logical.UpdateOperation: &PathOperation{
|
||||
Summary: "My Summary",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
docOrig := NewOASDocument("version")
|
||||
err := documentPath(p, &Backend{BackendType: logical.TypeLogical}, "kv", docOrig)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
docJSON := mustJSONMarshal(t, docOrig)
|
||||
|
||||
var intermediate map[string]interface{}
|
||||
if err := jsonutil.DecodeJSON(docJSON, &intermediate); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
docNew, err := NewOASDocumentFromMap(intermediate)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
docNewJSON := mustJSONMarshal(t, docNew)
|
||||
|
||||
if diff := deep.Equal(docJSON, docNewJSON); diff != nil {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAPI_CleanResponse(t *testing.T) {
|
||||
// Verify that an all-null input results in empty JSON
|
||||
orig := &logical.Response{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue