Dashboards/search: improve openapi spec (#111575)
Co-authored-by: Clarity-89 <homes89@ukr.net>
This commit is contained in:
@@ -85,6 +85,15 @@ func (s *SearchHandler) GetAPIRoutes(defs map[string]common.OpenAPIDefinition) *
|
||||
Schema: spec.StringProperty(),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "type",
|
||||
In: "query",
|
||||
Description: "search dashboards or folders. When empty, this will search both",
|
||||
Required: false,
|
||||
Schema: spec.StringProperty().WithEnum("folder", "dashboard"),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "folder",
|
||||
@@ -94,6 +103,24 @@ func (s *SearchHandler) GetAPIRoutes(defs map[string]common.OpenAPIDefinition) *
|
||||
Schema: spec.StringProperty(),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "facet",
|
||||
In: "query",
|
||||
Description: "count distinct terms for selected fields",
|
||||
Required: false,
|
||||
Schema: spec.ArrayProperty(spec.StringProperty()),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "tags",
|
||||
In: "query",
|
||||
Description: "tag query filter",
|
||||
Required: false,
|
||||
Schema: spec.ArrayProperty(spec.StringProperty()),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "sort",
|
||||
@@ -124,6 +151,24 @@ func (s *SearchHandler) GetAPIRoutes(defs map[string]common.OpenAPIDefinition) *
|
||||
Schema: spec.StringProperty(),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
Description: "number of results to return",
|
||||
Required: false,
|
||||
Schema: spec.Int64Property(),
|
||||
},
|
||||
},
|
||||
{
|
||||
ParameterProps: spec3.ParameterProps{
|
||||
Name: "explain",
|
||||
In: "query",
|
||||
Description: "add debugging info that may help explain why the result matched",
|
||||
Required: false,
|
||||
Schema: spec.BoolProperty(),
|
||||
},
|
||||
},
|
||||
},
|
||||
Responses: &spec3.Responses{
|
||||
ResponsesProps: spec3.ResponsesProps{
|
||||
@@ -257,33 +302,25 @@ func (s *SearchHandler) DoSearch(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
searchRequest.Fields = fields
|
||||
|
||||
types := queryParams["type"]
|
||||
var federate *resourcepb.ResourceKey
|
||||
switch len(types) {
|
||||
case 0:
|
||||
// When no type specified, search for dashboards
|
||||
// Search dashboards or folders (or both)
|
||||
switch queryParams.Get("type") {
|
||||
case "folder":
|
||||
searchRequest.Options.Key, err = asResourceKey(user.GetNamespace(), folders.RESOURCE)
|
||||
case "dashboard":
|
||||
searchRequest.Options.Key, err = asResourceKey(user.GetNamespace(), dashboardv0alpha1.DASHBOARD_RESOURCE)
|
||||
// Currently a search query is across folders and dashboards
|
||||
if err == nil {
|
||||
federate, err = asResourceKey(user.GetNamespace(), folders.RESOURCE)
|
||||
}
|
||||
case 1:
|
||||
searchRequest.Options.Key, err = asResourceKey(user.GetNamespace(), types[0])
|
||||
case 2:
|
||||
searchRequest.Options.Key, err = asResourceKey(user.GetNamespace(), types[0])
|
||||
if err == nil {
|
||||
federate, err = asResourceKey(user.GetNamespace(), types[1])
|
||||
}
|
||||
default:
|
||||
err = apierrors.NewBadRequest("too many type requests")
|
||||
searchRequest.Options.Key, err = asResourceKey(user.GetNamespace(), dashboardv0alpha1.DASHBOARD_RESOURCE)
|
||||
if err == nil {
|
||||
federate, _ := asResourceKey(user.GetNamespace(), folders.RESOURCE)
|
||||
if federate != nil {
|
||||
searchRequest.Federated = []*resourcepb.ResourceKey{federate}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
errhttp.Write(ctx, err, w)
|
||||
return
|
||||
}
|
||||
if federate != nil {
|
||||
searchRequest.Federated = []*resourcepb.ResourceKey{federate}
|
||||
}
|
||||
|
||||
// Add sorting
|
||||
if queryParams.Has("sort") {
|
||||
|
||||
Reference in New Issue
Block a user