chore: update to API spec for new template endpoint response (#362)

This commit is contained in:
Dane Strandboge
2022-02-17 14:46:05 -06:00
committed by GitHub
parent 041ebf65e3
commit 85a33adf71
12 changed files with 422 additions and 96 deletions

View File

@ -193,7 +193,7 @@ func (a *TemplatesApiService) ApplyTemplateExecuteWithHttpInfo(r ApiApplyTemplat
newErr.body = localVarBody
newErr.error = localVarHTTPResponse.Status
if localVarHTTPResponse.StatusCode == 422 {
var v TemplateSummary
var v TemplateSummaryError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = _fmt.Sprintf("%s: %s", newErr.Error(), err.Error())

View File

@ -329,6 +329,8 @@ components:
$ref: "./overrides/schemas/TemplateSummaryResources.yml"
TemplateSummaryError:
$ref: "./overrides/schemas/TemplateSummaryError.yml"
TemplateSummaryErrors:
$ref: "./overrides/schemas/TemplateSummaryErrors.yml"
TemplateSummaryBucket:
$ref: "./overrides/schemas/TemplateSummaryBucket.yml"
TemplateSummaryCheck:

View File

@ -34,7 +34,7 @@ post:
content:
application/json:
schema:
$ref: "../schemas/TemplateSummary.yml"
$ref: "../schemas/TemplateSummaryError.yml"
default:
description: Unexpected error
content:

View File

@ -13,5 +13,5 @@ properties:
errors:
type: array
items:
$ref: "./TemplateSummaryError.yml"
$ref: "./TemplateSummaryErrors.yml"
required: [sources, stackID, summary, diff, errors]

View File

@ -1,16 +1,21 @@
type: object
properties:
kind:
message:
type: string
reason:
code:
type: string
fields:
sources:
type: array
items:
type: string
indexes:
stackID:
type: string
summary:
$ref: "./TemplateSummaryResources.yml"
diff:
$ref: "./TemplateSummaryDiff.yml"
errors:
type: array
items:
type: integer
x-go-field-type: '[]*int'
required: [kind, reason, fields, indexes]
$ref: "./TemplateSummaryErrors.yml"
required: [message, code]

View File

@ -0,0 +1,16 @@
type: object
properties:
kind:
type: string
reason:
type: string
fields:
type: array
items:
type: string
indexes:
type: array
items:
type: integer
x-go-field-type: '[]*int'
required: [kind, reason, fields, indexes]

View File

@ -93,14 +93,16 @@ func (o *LineProtocolLengthError) ErrorCode() ErrorCode {
}
}
func (o *TemplateSummary) Error() string {
if len(o.Errors) == 0 {
panic("error-less template summary used as an error!")
func (o *TemplateSummaryError) Error() string {
// If there are no extended errors, simply give the normal error
if o.Errors == nil || len(*o.Errors) == 0 {
return o.Message
}
// otherwise try to collect the extended error info
var errMsg []string
seenErrs := map[string]struct{}{}
for _, e := range o.Errors {
for _, e := range *o.Errors {
fieldPairs := make([]string, 0, len(e.Fields))
for i, idx := range e.Indexes {
field := e.Fields[i]
@ -121,18 +123,6 @@ func (o *TemplateSummary) Error() string {
return strings.Join(errMsg, "\n\t")
}
func (o *TemplateSummary) ErrorCode() ErrorCode {
if len(o.Errors) == 0 {
panic("error-less template summary used as an error!")
}
return ERRORCODE_UNPROCESSABLE_ENTITY
}
func (o *TemplateSummary) SetMessage(string) {
// Placeholder to satisfy interface
}
func (o TemplateSummary) GetMessage() string {
return o.Error()
func (o *TemplateSummaryError) ErrorCode() ErrorCode {
return ErrorCode(o.Code)
}

View File

@ -20,14 +20,14 @@ type TemplateSummary struct {
StackID string `json:"stackID" yaml:"stackID"`
Summary TemplateSummaryResources `json:"summary" yaml:"summary"`
Diff TemplateSummaryDiff `json:"diff" yaml:"diff"`
Errors []TemplateSummaryError `json:"errors" yaml:"errors"`
Errors []TemplateSummaryErrors `json:"errors" yaml:"errors"`
}
// NewTemplateSummary instantiates a new TemplateSummary object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewTemplateSummary(sources []string, stackID string, summary TemplateSummaryResources, diff TemplateSummaryDiff, errors []TemplateSummaryError) *TemplateSummary {
func NewTemplateSummary(sources []string, stackID string, summary TemplateSummaryResources, diff TemplateSummaryDiff, errors []TemplateSummaryErrors) *TemplateSummary {
this := TemplateSummary{}
this.Sources = sources
this.StackID = stackID
@ -142,9 +142,9 @@ func (o *TemplateSummary) SetDiff(v TemplateSummaryDiff) {
}
// GetErrors returns the Errors field value
func (o *TemplateSummary) GetErrors() []TemplateSummaryError {
func (o *TemplateSummary) GetErrors() []TemplateSummaryErrors {
if o == nil {
var ret []TemplateSummaryError
var ret []TemplateSummaryErrors
return ret
}
@ -153,7 +153,7 @@ func (o *TemplateSummary) GetErrors() []TemplateSummaryError {
// GetErrorsOk returns a tuple with the Errors field value
// and a boolean to check if the value has been set.
func (o *TemplateSummary) GetErrorsOk() (*[]TemplateSummaryError, bool) {
func (o *TemplateSummary) GetErrorsOk() (*[]TemplateSummaryErrors, bool) {
if o == nil {
return nil, false
}
@ -161,7 +161,7 @@ func (o *TemplateSummary) GetErrorsOk() (*[]TemplateSummaryError, bool) {
}
// SetErrors sets field value
func (o *TemplateSummary) SetErrors(v []TemplateSummaryError) {
func (o *TemplateSummary) SetErrors(v []TemplateSummaryErrors) {
o.Errors = v
}

View File

@ -16,22 +16,23 @@ import (
// TemplateSummaryError struct for TemplateSummaryError
type TemplateSummaryError struct {
Kind string `json:"kind" yaml:"kind"`
Reason string `json:"reason" yaml:"reason"`
Fields []string `json:"fields" yaml:"fields"`
Indexes []*int `json:"indexes" yaml:"indexes"`
Message string `json:"message" yaml:"message"`
Code string `json:"code" yaml:"code"`
Sources *[]string `json:"sources,omitempty" yaml:"sources,omitempty"`
StackID *string `json:"stackID,omitempty" yaml:"stackID,omitempty"`
Summary *TemplateSummaryResources `json:"summary,omitempty" yaml:"summary,omitempty"`
Diff *TemplateSummaryDiff `json:"diff,omitempty" yaml:"diff,omitempty"`
Errors *[]TemplateSummaryErrors `json:"errors,omitempty" yaml:"errors,omitempty"`
}
// NewTemplateSummaryError instantiates a new TemplateSummaryError object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewTemplateSummaryError(kind string, reason string, fields []string, indexes []*int) *TemplateSummaryError {
func NewTemplateSummaryError(message string, code string) *TemplateSummaryError {
this := TemplateSummaryError{}
this.Kind = kind
this.Reason = reason
this.Fields = fields
this.Indexes = indexes
this.Message = message
this.Code = code
return &this
}
@ -43,115 +44,236 @@ func NewTemplateSummaryErrorWithDefaults() *TemplateSummaryError {
return &this
}
// GetKind returns the Kind field value
func (o *TemplateSummaryError) GetKind() string {
// GetMessage returns the Message field value
func (o *TemplateSummaryError) GetMessage() string {
if o == nil {
var ret string
return ret
}
return o.Kind
return o.Message
}
// GetKindOk returns a tuple with the Kind field value
// GetMessageOk returns a tuple with the Message field value
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetKindOk() (*string, bool) {
func (o *TemplateSummaryError) GetMessageOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Kind, true
return &o.Message, true
}
// SetKind sets field value
func (o *TemplateSummaryError) SetKind(v string) {
o.Kind = v
// SetMessage sets field value
func (o *TemplateSummaryError) SetMessage(v string) {
o.Message = v
}
// GetReason returns the Reason field value
func (o *TemplateSummaryError) GetReason() string {
// GetCode returns the Code field value
func (o *TemplateSummaryError) GetCode() string {
if o == nil {
var ret string
return ret
}
return o.Reason
return o.Code
}
// GetReasonOk returns a tuple with the Reason field value
// GetCodeOk returns a tuple with the Code field value
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetReasonOk() (*string, bool) {
func (o *TemplateSummaryError) GetCodeOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Reason, true
return &o.Code, true
}
// SetReason sets field value
func (o *TemplateSummaryError) SetReason(v string) {
o.Reason = v
// SetCode sets field value
func (o *TemplateSummaryError) SetCode(v string) {
o.Code = v
}
// GetFields returns the Fields field value
func (o *TemplateSummaryError) GetFields() []string {
if o == nil {
// GetSources returns the Sources field value if set, zero value otherwise.
func (o *TemplateSummaryError) GetSources() []string {
if o == nil || o.Sources == nil {
var ret []string
return ret
}
return o.Fields
return *o.Sources
}
// GetFieldsOk returns a tuple with the Fields field value
// GetSourcesOk returns a tuple with the Sources field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetFieldsOk() (*[]string, bool) {
if o == nil {
func (o *TemplateSummaryError) GetSourcesOk() (*[]string, bool) {
if o == nil || o.Sources == nil {
return nil, false
}
return &o.Fields, true
return o.Sources, true
}
// SetFields sets field value
func (o *TemplateSummaryError) SetFields(v []string) {
o.Fields = v
// HasSources returns a boolean if a field has been set.
func (o *TemplateSummaryError) HasSources() bool {
if o != nil && o.Sources != nil {
return true
}
return false
}
// GetIndexes returns the Indexes field value
func (o *TemplateSummaryError) GetIndexes() []*int {
if o == nil {
var ret []*int
// SetSources gets a reference to the given []string and assigns it to the Sources field.
func (o *TemplateSummaryError) SetSources(v []string) {
o.Sources = &v
}
// GetStackID returns the StackID field value if set, zero value otherwise.
func (o *TemplateSummaryError) GetStackID() string {
if o == nil || o.StackID == nil {
var ret string
return ret
}
return o.Indexes
return *o.StackID
}
// GetIndexesOk returns a tuple with the Indexes field value
// GetStackIDOk returns a tuple with the StackID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetIndexesOk() (*[]*int, bool) {
if o == nil {
func (o *TemplateSummaryError) GetStackIDOk() (*string, bool) {
if o == nil || o.StackID == nil {
return nil, false
}
return &o.Indexes, true
return o.StackID, true
}
// SetIndexes sets field value
func (o *TemplateSummaryError) SetIndexes(v []*int) {
o.Indexes = v
// HasStackID returns a boolean if a field has been set.
func (o *TemplateSummaryError) HasStackID() bool {
if o != nil && o.StackID != nil {
return true
}
return false
}
// SetStackID gets a reference to the given string and assigns it to the StackID field.
func (o *TemplateSummaryError) SetStackID(v string) {
o.StackID = &v
}
// GetSummary returns the Summary field value if set, zero value otherwise.
func (o *TemplateSummaryError) GetSummary() TemplateSummaryResources {
if o == nil || o.Summary == nil {
var ret TemplateSummaryResources
return ret
}
return *o.Summary
}
// GetSummaryOk returns a tuple with the Summary field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetSummaryOk() (*TemplateSummaryResources, bool) {
if o == nil || o.Summary == nil {
return nil, false
}
return o.Summary, true
}
// HasSummary returns a boolean if a field has been set.
func (o *TemplateSummaryError) HasSummary() bool {
if o != nil && o.Summary != nil {
return true
}
return false
}
// SetSummary gets a reference to the given TemplateSummaryResources and assigns it to the Summary field.
func (o *TemplateSummaryError) SetSummary(v TemplateSummaryResources) {
o.Summary = &v
}
// GetDiff returns the Diff field value if set, zero value otherwise.
func (o *TemplateSummaryError) GetDiff() TemplateSummaryDiff {
if o == nil || o.Diff == nil {
var ret TemplateSummaryDiff
return ret
}
return *o.Diff
}
// GetDiffOk returns a tuple with the Diff field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetDiffOk() (*TemplateSummaryDiff, bool) {
if o == nil || o.Diff == nil {
return nil, false
}
return o.Diff, true
}
// HasDiff returns a boolean if a field has been set.
func (o *TemplateSummaryError) HasDiff() bool {
if o != nil && o.Diff != nil {
return true
}
return false
}
// SetDiff gets a reference to the given TemplateSummaryDiff and assigns it to the Diff field.
func (o *TemplateSummaryError) SetDiff(v TemplateSummaryDiff) {
o.Diff = &v
}
// GetErrors returns the Errors field value if set, zero value otherwise.
func (o *TemplateSummaryError) GetErrors() []TemplateSummaryErrors {
if o == nil || o.Errors == nil {
var ret []TemplateSummaryErrors
return ret
}
return *o.Errors
}
// GetErrorsOk returns a tuple with the Errors field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *TemplateSummaryError) GetErrorsOk() (*[]TemplateSummaryErrors, bool) {
if o == nil || o.Errors == nil {
return nil, false
}
return o.Errors, true
}
// HasErrors returns a boolean if a field has been set.
func (o *TemplateSummaryError) HasErrors() bool {
if o != nil && o.Errors != nil {
return true
}
return false
}
// SetErrors gets a reference to the given []TemplateSummaryErrors and assigns it to the Errors field.
func (o *TemplateSummaryError) SetErrors(v []TemplateSummaryErrors) {
o.Errors = &v
}
func (o TemplateSummaryError) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["kind"] = o.Kind
toSerialize["message"] = o.Message
}
if true {
toSerialize["reason"] = o.Reason
toSerialize["code"] = o.Code
}
if true {
toSerialize["fields"] = o.Fields
if o.Sources != nil {
toSerialize["sources"] = o.Sources
}
if true {
toSerialize["indexes"] = o.Indexes
if o.StackID != nil {
toSerialize["stackID"] = o.StackID
}
if o.Summary != nil {
toSerialize["summary"] = o.Summary
}
if o.Diff != nil {
toSerialize["diff"] = o.Diff
}
if o.Errors != nil {
toSerialize["errors"] = o.Errors
}
return json.Marshal(toSerialize)
}

View File

@ -0,0 +1,193 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// TemplateSummaryErrors struct for TemplateSummaryErrors
type TemplateSummaryErrors struct {
Kind string `json:"kind" yaml:"kind"`
Reason string `json:"reason" yaml:"reason"`
Fields []string `json:"fields" yaml:"fields"`
Indexes []*int `json:"indexes" yaml:"indexes"`
}
// NewTemplateSummaryErrors instantiates a new TemplateSummaryErrors object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewTemplateSummaryErrors(kind string, reason string, fields []string, indexes []*int) *TemplateSummaryErrors {
this := TemplateSummaryErrors{}
this.Kind = kind
this.Reason = reason
this.Fields = fields
this.Indexes = indexes
return &this
}
// NewTemplateSummaryErrorsWithDefaults instantiates a new TemplateSummaryErrors object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewTemplateSummaryErrorsWithDefaults() *TemplateSummaryErrors {
this := TemplateSummaryErrors{}
return &this
}
// GetKind returns the Kind field value
func (o *TemplateSummaryErrors) GetKind() string {
if o == nil {
var ret string
return ret
}
return o.Kind
}
// GetKindOk returns a tuple with the Kind field value
// and a boolean to check if the value has been set.
func (o *TemplateSummaryErrors) GetKindOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Kind, true
}
// SetKind sets field value
func (o *TemplateSummaryErrors) SetKind(v string) {
o.Kind = v
}
// GetReason returns the Reason field value
func (o *TemplateSummaryErrors) GetReason() string {
if o == nil {
var ret string
return ret
}
return o.Reason
}
// GetReasonOk returns a tuple with the Reason field value
// and a boolean to check if the value has been set.
func (o *TemplateSummaryErrors) GetReasonOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Reason, true
}
// SetReason sets field value
func (o *TemplateSummaryErrors) SetReason(v string) {
o.Reason = v
}
// GetFields returns the Fields field value
func (o *TemplateSummaryErrors) GetFields() []string {
if o == nil {
var ret []string
return ret
}
return o.Fields
}
// GetFieldsOk returns a tuple with the Fields field value
// and a boolean to check if the value has been set.
func (o *TemplateSummaryErrors) GetFieldsOk() (*[]string, bool) {
if o == nil {
return nil, false
}
return &o.Fields, true
}
// SetFields sets field value
func (o *TemplateSummaryErrors) SetFields(v []string) {
o.Fields = v
}
// GetIndexes returns the Indexes field value
func (o *TemplateSummaryErrors) GetIndexes() []*int {
if o == nil {
var ret []*int
return ret
}
return o.Indexes
}
// GetIndexesOk returns a tuple with the Indexes field value
// and a boolean to check if the value has been set.
func (o *TemplateSummaryErrors) GetIndexesOk() (*[]*int, bool) {
if o == nil {
return nil, false
}
return &o.Indexes, true
}
// SetIndexes sets field value
func (o *TemplateSummaryErrors) SetIndexes(v []*int) {
o.Indexes = v
}
func (o TemplateSummaryErrors) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["kind"] = o.Kind
}
if true {
toSerialize["reason"] = o.Reason
}
if true {
toSerialize["fields"] = o.Fields
}
if true {
toSerialize["indexes"] = o.Indexes
}
return json.Marshal(toSerialize)
}
type NullableTemplateSummaryErrors struct {
value *TemplateSummaryErrors
isSet bool
}
func (v NullableTemplateSummaryErrors) Get() *TemplateSummaryErrors {
return v.value
}
func (v *NullableTemplateSummaryErrors) Set(val *TemplateSummaryErrors) {
v.value = val
v.isSet = true
}
func (v NullableTemplateSummaryErrors) IsSet() bool {
return v.isSet
}
func (v *NullableTemplateSummaryErrors) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableTemplateSummaryErrors(val *TemplateSummaryErrors) *NullableTemplateSummaryErrors {
return &NullableTemplateSummaryErrors{value: val, isSet: true}
}
func (v NullableTemplateSummaryErrors) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableTemplateSummaryErrors) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -81,9 +81,7 @@ func (c Client) Validate(ctx context.Context, params *ValidateParams) error {
}
if apiErr, ok := err.(api.GenericOpenAPIError); ok {
if summary, ok := apiErr.Model().(*api.TemplateSummary); ok {
return fmt.Errorf("template failed validation:\n\t%s", summary)
}
return fmt.Errorf("template failed validation:\n\t%s", apiErr)
}
return fmt.Errorf("failed to validate template: %w", err)
}