func (p QueryParameterQuery) MarshalJSON() ([]byte, error) {
	p.QueryParameter.Type = queryParameterQueryTypeName
	var err error
	if p.Multi == nil {
		p.Value, err = json.Marshal(p.Values[0])
		if err != nil {
			return nil, err
		}
	} else {
		p.Value, err = json.Marshal(p.Values)
		if err != nil {
			return nil, err
		}
	}
	type localQueryParameter QueryParameterQuery
	return json.Marshal((localQueryParameter)(p))
}
MarshalJSON sets the type before marshaling.
package api
import (
	"encoding/json"
)
type Query struct {
	ID             string            `json:"id,omitempty"`
	DataSourceID   string            `json:"data_source_id"`
	Name           string            `json:"name"`
	Description    string            `json:"description"`
	Query          string            `json:"query"`
	Schedule       *QuerySchedule    `json:"schedule"`
	Options        *QueryOptions     `json:"options,omitempty"`
	Tags           []string          `json:"tags,omitempty"`
	Visualizations []json.RawMessage `json:"visualizations,omitempty"`
}
type QuerySchedule struct {
	Interval int `json:"interval"`
	Time *string `json:"time"`
	DayOfWeek *string `json:"day_of_week"`
	Until *string `json:"until"`
}
type QueryOptions struct {
	Parameters    []interface{}     `json:"-"`
	RawParameters []json.RawMessage `json:"parameters,omitempty"`
	RunAsRole string `json:"run_as_role,omitempty"`
}
func (o *QueryOptions) MarshalJSON() ([]byte, error) {
	if o.Parameters != nil {
		o.RawParameters = []json.RawMessage{}
		for _, p := range o.Parameters {
			b, err := json.Marshal(p)
			if err != nil {
				return nil, err
			}
			o.RawParameters = append(o.RawParameters, b)
		}
	}
	type localQueryOptions QueryOptions
	return json.Marshal((*localQueryOptions)(o))
}
func (o *QueryOptions) UnmarshalJSON(b []byte) error {
	type localQueryOptions QueryOptions
	err := json.Unmarshal(b, (*localQueryOptions)(o))
	if err != nil {
		return err
	}
	o.Parameters = []interface{}{}
	for _, rp := range o.RawParameters {
		var qp QueryParameter
		err = json.Unmarshal(rp, &qp)
		if err != nil {
			return err
		}
		var i interface{}
		switch qp.Type {
		case queryParameterTextTypeName:
			i = &QueryParameterText{}
		case queryParameterNumberTypeName:
			i = &QueryParameterNumber{}
		case queryParameterEnumTypeName:
			i = &QueryParameterEnum{}
		case queryParameterQueryTypeName:
			i = &QueryParameterQuery{}
		case queryParameterDateTypeName:
			i = &QueryParameterDate{}
		case queryParameterDateTimeTypeName:
			i = &QueryParameterDateTime{}
		case queryParameterDateTimeSecTypeName:
			i = &QueryParameterDateTimeSec{}
		case queryParameterDateRangeTypeName:
			i = &QueryParameterDateRange{}
		case queryParameterDateTimeRangeTypeName:
			i = &QueryParameterDateTimeRange{}
		case queryParameterDateTimeSecRangeTypeName:
			i = &QueryParameterDateTimeSecRange{}
		default:
			panic("don't know what to do...")
		}
		err = json.Unmarshal(rp, &i)
		if err != nil {
			return err
		}
		o.Parameters = append(o.Parameters, i)
	}
	return nil
}
type QueryParameter struct {
	Name  string `json:"name"`
	Title string `json:"title,omitempty"`
	Type  string `json:"type"`
}
const (
	queryParameterTextTypeName             = "text"
	queryParameterNumberTypeName           = "number"
	queryParameterEnumTypeName             = "enum"
	queryParameterQueryTypeName            = "query"
	queryParameterDateTypeName             = "date"
	queryParameterDateTimeTypeName         = "datetime-local"
	queryParameterDateTimeSecTypeName      = "datetime-with-seconds"
	queryParameterDateRangeTypeName        = "date-range"
	queryParameterDateTimeRangeTypeName    = "datetime-range"
	queryParameterDateTimeSecRangeTypeName = "datetime-range-with-seconds"
)
type QueryParameterText struct {
	QueryParameter
	Value string `json:"value"`
}
func (p QueryParameterText) MarshalJSON() ([]byte, error) {
	p.QueryParameter.Type = queryParameterTextTypeName
	type localQueryParameter QueryParameterText
	return json.Marshal((localQueryParameter)(p))
}
func (p *QueryParameterText) UnmarshalJSON(b []byte) error {
	type localQueryParameter QueryParameterText
	if err := json.Unmarshal(b, (*localQueryParameter)(p)); err != nil {
		return err
	}
	p.Type = ""
	return nil
}
type QueryParameterNumber struct {
	QueryParameter
	Value float64 `json:"value"`
}
func (p QueryParameterNumber) MarshalJSON() ([]byte, error) {
	p.QueryParameter.Type = queryParameterNumberTypeName
	type localQueryParameter QueryParameterNumber
	return json.Marshal((localQueryParameter)(p))
}
func (p *QueryParameterNumber) UnmarshalJSON(b []byte) error {
	type localQueryParameter QueryParameterNumber
	if err := json.Unmarshal(b, (*localQueryParameter)(p)); err != nil {
		return err
	}
	p.Type = ""
	return nil
}
type QueryParameterMultipleValuesOptions struct {
	Prefix    string `json:"prefix"`
	Suffix    string `json:"suffix"`
	Separator string `json:"separator"`
}
type QueryParameterEnum struct {
	QueryParameter
	Values []string `json:"-"`
	Value   json.RawMessage                      `json:"value"`
	Options string                               `json:"enumOptions"`
	Multi   *QueryParameterMultipleValuesOptions `json:"multiValuesOptions,omitempty"`
}
func (p QueryParameterEnum) MarshalJSON() ([]byte, error) {
	p.QueryParameter.Type = queryParameterEnumTypeName
	var err error
	if p.Multi == nil {
		p.Value, err = json.Marshal(p.Values[0])
		if err != nil {
			return nil, err
		}
	} else {
		p.Value, err = json.Marshal(p.Values)
		if err != nil {
			return nil, err
		}
	}
	type localQueryParameter QueryParameterEnum
	return json.Marshal((localQueryParameter)(p))
}
func (p *QueryParameterEnum) UnmarshalJSON(b []byte) error {
	type localQueryParameter QueryParameterEnum
	err := json.Unmarshal(b, (*localQueryParameter)(p))
	if err != nil {
		return err
	}
	if p.Multi == nil {
		var v string
		err = json.Unmarshal(p.Value, &v)
		if err != nil {
			return nil
		}
		p.Values = []string{v}
	} else {
		var vs []string
		err = json.Unmarshal(p.Value, &vs)
		if err != nil {
			return nil
		}
		p.Values = vs
	}
	p.Type = ""
	p.Value = nil
	return nil
}
type QueryParameterQuery struct {
	QueryParameter
	Values []string `json:"-"`
	Value   json.RawMessage                      `json:"value"`
	QueryID string                               `json:"queryId"`
	Multi   *QueryParameterMultipleValuesOptions `json:"multiValuesOptions,omitempty"`
}