This commit is contained in:
Tamás Berki 2026-05-19 06:26:39 -07:00 committed by GitHub
commit 0c112f28cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 0 deletions

3
changelog/30715.txt Normal file
View file

@ -0,0 +1,3 @@
```release-note:bug
openapi: fix missing request schema for custom plugins
```

View file

@ -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,
}

View file

@ -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{}