K8s: improve openapi generation (#83796)
This commit is contained in:
@@ -5,13 +5,12 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apis/query/v0alpha1"
|
||||
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/middleware/requestmeta"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -24,51 +23,24 @@ type subQueryREST struct {
|
||||
var _ = rest.Connecter(&subQueryREST{})
|
||||
|
||||
func (r *subQueryREST) New() runtime.Object {
|
||||
return &v0alpha1.QueryDataResponse{}
|
||||
return &query.QueryDataResponse{}
|
||||
}
|
||||
|
||||
func (r *subQueryREST) Destroy() {}
|
||||
|
||||
func (r *subQueryREST) ConnectMethods() []string {
|
||||
return []string{"POST", "GET"}
|
||||
return []string{"POST"}
|
||||
}
|
||||
|
||||
func (r *subQueryREST) NewConnectOptions() (runtime.Object, bool, string) {
|
||||
return nil, false, ""
|
||||
}
|
||||
|
||||
func (r *subQueryREST) readQueries(req *http.Request) ([]backend.DataQuery, *v0alpha1.DataSourceRef, error) {
|
||||
reqDTO := v0alpha1.GenericQueryRequest{}
|
||||
// Simple URL to JSON mapping
|
||||
if req.Method == http.MethodGet {
|
||||
query := v0alpha1.GenericDataQuery{
|
||||
RefID: "A",
|
||||
MaxDataPoints: 1000,
|
||||
IntervalMS: 10,
|
||||
}
|
||||
params := req.URL.Query()
|
||||
for k := range params {
|
||||
v := params.Get(k) // the singular value
|
||||
switch k {
|
||||
case "to":
|
||||
reqDTO.To = v
|
||||
case "from":
|
||||
reqDTO.From = v
|
||||
case "maxDataPoints":
|
||||
query.MaxDataPoints, _ = strconv.ParseInt(v, 10, 64)
|
||||
case "intervalMs":
|
||||
query.IntervalMS, _ = strconv.ParseFloat(v, 64)
|
||||
case "queryType":
|
||||
query.QueryType = v
|
||||
default:
|
||||
query.AdditionalProperties()[k] = v
|
||||
}
|
||||
}
|
||||
reqDTO.Queries = []v0alpha1.GenericDataQuery{query}
|
||||
} else if err := web.Bind(req, &reqDTO); err != nil {
|
||||
func (r *subQueryREST) readQueries(req *http.Request) ([]backend.DataQuery, *query.DataSourceRef, error) {
|
||||
reqDTO := query.GenericQueryRequest{}
|
||||
if err := web.Bind(req, &reqDTO); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return legacydata.ToDataSourceQueries(reqDTO)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user