mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user