OpenAPI: Define default response structure for ListOperations (#21934)

* OpenAPI: Define default response structure for ListOperations

Almost all Vault ListOperation responses have an identical response
schema. Update the OpenAPI generator to know this, and remove a few
instances where that standard response schema had been manually
copy/pasted into place in individual endpoints.

* changelog

* Only render StandardListResponse schema, if an operation uses it

* Teach the response schema validation test helper about the default list schema too

---------

Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com>
This commit is contained in:
Max Bowsher
2023-07-25 16:22:33 +01:00
committed by GitHub
parent 7398afcc9a
commit e057ee0750
11 changed files with 51 additions and 93 deletions

View File

@@ -197,6 +197,29 @@ var OASStdRespNoContent = &OASResponse{
Description: "empty body",
}
var OASStdRespListOK = &OASResponse{
Description: "OK",
Content: OASContent{
"application/json": &OASMediaTypeObject{
Schema: &OASSchema{
Ref: "#/components/schemas/StandardListResponse",
},
},
},
}
var OASStdSchemaStandardListResponse = &OASSchema{
Type: "object",
Properties: map[string]*OASSchema{
"keys": {
Type: "array",
Items: &OASSchema{
Type: "string",
},
},
},
}
// Regex for handling fields in paths, and string cleanup.
// Predefined here to avoid substantial recompilation.
@@ -456,6 +479,9 @@ func documentPath(p *Path, backend *Backend, requestResponsePrefix string, doc *
if len(props.Responses) == 0 {
if opType == logical.DeleteOperation {
op.Responses[204] = OASStdRespNoContent
} else if opType == logical.ListOperation {
op.Responses[200] = OASStdRespListOK
doc.Components.Schemas["StandardListResponse"] = OASStdSchemaStandardListResponse
} else {
op.Responses[200] = OASStdRespOK
}