From b7ca353acdd6f839aca746cad05c2acf08aad587 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 May 2024 11:12:29 +0000 Subject: [PATCH] feat(api): OpenAPI spec update via Stainless API (#2260) --- .stats.yml | 2 +- api.md | 12 +-- cloudforce_one/request.go | 132 +++++++++++++++++++----------- cloudforce_one/requestmessage.go | 119 +++++++++++++++++---------- cloudforce_one/requestpriority.go | 123 ++++++++++++++++++---------- intel/whois.go | 4 +- shared/union.go | 3 + 7 files changed, 251 insertions(+), 144 deletions(-) diff --git a/.stats.yml b/.stats.yml index a157cc5cf6b..9a6098c023f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 1321 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-faaa81dda06d091c58d19e3aba3fc1609f647c8af561f2aa645b484412805084.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-2d96bf16635986ad2cf00e1d6b6e108e3c6a069d19ef1285400b28af9d958af3.yml diff --git a/api.md b/api.md index 3a6e570c511..af572e4e28e 100644 --- a/api.md +++ b/api.md @@ -7022,14 +7022,14 @@ Response Types: - cloudforce_one.Quota - cloudforce_one.RequestConstants - cloudforce_one.RequestTypes -- cloudforce_one.RequestDeleteResponse +- cloudforce_one.RequestDeleteResponseUnion Methods: - client.CloudforceOne.Requests.New(ctx context.Context, accountIdentifier string, body cloudforce_one.RequestNewParams) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.Update(ctx context.Context, accountIdentifier string, requestIdentifier string, body cloudforce_one.RequestUpdateParams) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.List(ctx context.Context, accountIdentifier string, body cloudforce_one.RequestListParams) (pagination.V4PagePaginationArray[cloudforce_one.ListItem], error) -- client.CloudforceOne.Requests.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string) (cloudforce_one.RequestDeleteResponse, error) +- client.CloudforceOne.Requests.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string) (cloudforce_one.RequestDeleteResponseUnion, error) - client.CloudforceOne.Requests.Constants(ctx context.Context, accountIdentifier string) (cloudforce_one.RequestConstants, error) - client.CloudforceOne.Requests.Get(ctx context.Context, accountIdentifier string, requestIdentifier string) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.Quota(ctx context.Context, accountIdentifier string) (cloudforce_one.Quota, error) @@ -7040,13 +7040,13 @@ Methods: Response Types: - cloudforce_one.Message -- cloudforce_one.RequestMessageDeleteResponse +- cloudforce_one.RequestMessageDeleteResponseUnion Methods: - client.CloudforceOne.Requests.Message.New(ctx context.Context, accountIdentifier string, requestIdentifier string, body cloudforce_one.RequestMessageNewParams) (cloudforce_one.Message, error) - client.CloudforceOne.Requests.Message.Update(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64, body cloudforce_one.RequestMessageUpdateParams) (cloudforce_one.Message, error) -- client.CloudforceOne.Requests.Message.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64) (cloudforce_one.RequestMessageDeleteResponse, error) +- client.CloudforceOne.Requests.Message.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64) (cloudforce_one.RequestMessageDeleteResponseUnion, error) - client.CloudforceOne.Requests.Message.Get(ctx context.Context, accountIdentifier string, requestIdentifier string, body cloudforce_one.RequestMessageGetParams) ([]cloudforce_one.Message, error) ### Priority @@ -7060,13 +7060,13 @@ Response Types: - cloudforce_one.Label - cloudforce_one.Priority -- cloudforce_one.RequestPriorityDeleteResponse +- cloudforce_one.RequestPriorityDeleteResponseUnion Methods: - client.CloudforceOne.Requests.Priority.New(ctx context.Context, accountIdentifier string, body cloudforce_one.RequestPriorityNewParams) (cloudforce_one.Priority, error) - client.CloudforceOne.Requests.Priority.Update(ctx context.Context, accountIdentifier string, priorityIdentifer string, body cloudforce_one.RequestPriorityUpdateParams) (cloudforce_one.Item, error) -- client.CloudforceOne.Requests.Priority.Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string) (cloudforce_one.RequestPriorityDeleteResponse, error) +- client.CloudforceOne.Requests.Priority.Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string) (cloudforce_one.RequestPriorityDeleteResponseUnion, error) - client.CloudforceOne.Requests.Priority.Get(ctx context.Context, accountIdentifier string, priorityIdentifer string) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.Priority.Quota(ctx context.Context, accountIdentifier string) (cloudforce_one.Quota, error) diff --git a/cloudforce_one/request.go b/cloudforce_one/request.go index 1241d196ad8..24f51e78b9d 100644 --- a/cloudforce_one/request.go +++ b/cloudforce_one/request.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net/http" + "reflect" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" @@ -15,6 +16,7 @@ import ( "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" "github.com/cloudflare/cloudflare-go/v2/shared" + "github.com/tidwall/gjson" ) // RequestService contains methods and other services that help with interacting @@ -106,8 +108,9 @@ func (r *RequestService) ListAutoPaging(ctx context.Context, accountIdentifier s } // Delete a Request -func (r *RequestService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, opts ...option.RequestOption) (res *RequestDeleteResponse, err error) { +func (r *RequestService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, opts ...option.RequestOption) (res *RequestDeleteResponseUnion, err error) { opts = append(r.Options[:], opts...) + var env RequestDeleteResponseEnvelope if accountIdentifier == "" { err = errors.New("missing required account_identifier parameter") return @@ -117,7 +120,11 @@ func (r *RequestService) Delete(ctx context.Context, accountIdentifier string, r return } path := fmt.Sprintf("accounts/%s/cloudforce-one/requests/%s", accountIdentifier, requestIdentifier) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result return } @@ -505,46 +512,30 @@ func (r RequestConstantsTlp) IsKnown() bool { type RequestTypes []string -type RequestDeleteResponse struct { - Errors []shared.ResponseInfo `json:"errors,required"` - Messages []shared.ResponseInfo `json:"messages,required"` - // Whether the API call was successful - Success RequestDeleteResponseSuccess `json:"success,required"` - JSON requestDeleteResponseJSON `json:"-"` -} - -// requestDeleteResponseJSON contains the JSON metadata for the struct -// [RequestDeleteResponse] -type requestDeleteResponseJSON struct { - Errors apijson.Field - Messages apijson.Field - Success apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *RequestDeleteResponse) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) +// Union satisfied by [cloudforce_one.RequestDeleteResponseUnknown], +// [cloudforce_one.RequestDeleteResponseArray] or [shared.UnionString]. +type RequestDeleteResponseUnion interface { + ImplementsCloudforceOneRequestDeleteResponseUnion() } -func (r requestDeleteResponseJSON) RawJSON() string { - return r.raw +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*RequestDeleteResponseUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(RequestDeleteResponseArray{}), + }, + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(shared.UnionString("")), + }, + ) } -// Whether the API call was successful -type RequestDeleteResponseSuccess bool +type RequestDeleteResponseArray []interface{} -const ( - RequestDeleteResponseSuccessTrue RequestDeleteResponseSuccess = true -) - -func (r RequestDeleteResponseSuccess) IsKnown() bool { - switch r { - case RequestDeleteResponseSuccessTrue: - return true - } - return false -} +func (r RequestDeleteResponseArray) ImplementsCloudforceOneRequestDeleteResponseUnion() {} type RequestNewParams struct { // Request content @@ -585,9 +576,9 @@ func (r RequestNewParamsTlp) IsKnown() bool { type RequestNewResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Item `json:"result,required"` // Whether the API call was successful Success RequestNewResponseEnvelopeSuccess `json:"success,required"` - Result Item `json:"result"` JSON requestNewResponseEnvelopeJSON `json:"-"` } @@ -596,8 +587,8 @@ type RequestNewResponseEnvelope struct { type requestNewResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -664,9 +655,9 @@ func (r RequestUpdateParamsTlp) IsKnown() bool { type RequestUpdateResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Item `json:"result,required"` // Whether the API call was successful Success RequestUpdateResponseEnvelopeSuccess `json:"success,required"` - Result Item `json:"result"` JSON requestUpdateResponseEnvelopeJSON `json:"-"` } @@ -675,8 +666,8 @@ type RequestUpdateResponseEnvelope struct { type requestUpdateResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -767,12 +758,55 @@ func (r RequestListParamsStatus) IsKnown() bool { return false } +type RequestDeleteResponseEnvelope struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + Result RequestDeleteResponseUnion `json:"result,required"` + // Whether the API call was successful + Success RequestDeleteResponseEnvelopeSuccess `json:"success,required"` + JSON requestDeleteResponseEnvelopeJSON `json:"-"` +} + +// requestDeleteResponseEnvelopeJSON contains the JSON metadata for the struct +// [RequestDeleteResponseEnvelope] +type requestDeleteResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RequestDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r requestDeleteResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RequestDeleteResponseEnvelopeSuccess bool + +const ( + RequestDeleteResponseEnvelopeSuccessTrue RequestDeleteResponseEnvelopeSuccess = true +) + +func (r RequestDeleteResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RequestDeleteResponseEnvelopeSuccessTrue: + return true + } + return false +} + type RequestConstantsResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result RequestConstants `json:"result,required"` // Whether the API call was successful Success RequestConstantsResponseEnvelopeSuccess `json:"success,required"` - Result RequestConstants `json:"result"` JSON requestConstantsResponseEnvelopeJSON `json:"-"` } @@ -781,8 +815,8 @@ type RequestConstantsResponseEnvelope struct { type requestConstantsResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -813,9 +847,9 @@ func (r RequestConstantsResponseEnvelopeSuccess) IsKnown() bool { type RequestGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Item `json:"result,required"` // Whether the API call was successful Success RequestGetResponseEnvelopeSuccess `json:"success,required"` - Result Item `json:"result"` JSON requestGetResponseEnvelopeJSON `json:"-"` } @@ -824,8 +858,8 @@ type RequestGetResponseEnvelope struct { type requestGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -856,9 +890,9 @@ func (r RequestGetResponseEnvelopeSuccess) IsKnown() bool { type RequestQuotaResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Quota `json:"result,required"` // Whether the API call was successful Success RequestQuotaResponseEnvelopeSuccess `json:"success,required"` - Result Quota `json:"result"` JSON requestQuotaResponseEnvelopeJSON `json:"-"` } @@ -867,8 +901,8 @@ type RequestQuotaResponseEnvelope struct { type requestQuotaResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -899,9 +933,9 @@ func (r RequestQuotaResponseEnvelopeSuccess) IsKnown() bool { type RequestTypesResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result RequestTypes `json:"result,required"` // Whether the API call was successful Success RequestTypesResponseEnvelopeSuccess `json:"success,required"` - Result RequestTypes `json:"result"` JSON requestTypesResponseEnvelopeJSON `json:"-"` } @@ -910,8 +944,8 @@ type RequestTypesResponseEnvelope struct { type requestTypesResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/cloudforce_one/requestmessage.go b/cloudforce_one/requestmessage.go index 1f24de63b39..0b155fa7a3c 100644 --- a/cloudforce_one/requestmessage.go +++ b/cloudforce_one/requestmessage.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net/http" + "reflect" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" @@ -14,6 +15,7 @@ import ( "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" "github.com/cloudflare/cloudflare-go/v2/shared" + "github.com/tidwall/gjson" ) // RequestMessageService contains methods and other services that help with @@ -80,8 +82,9 @@ func (r *RequestMessageService) Update(ctx context.Context, accountIdentifier st } // Delete a Request Message -func (r *RequestMessageService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64, opts ...option.RequestOption) (res *RequestMessageDeleteResponse, err error) { +func (r *RequestMessageService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64, opts ...option.RequestOption) (res *RequestMessageDeleteResponseUnion, err error) { opts = append(r.Options[:], opts...) + var env RequestMessageDeleteResponseEnvelope if accountIdentifier == "" { err = errors.New("missing required account_identifier parameter") return @@ -91,7 +94,11 @@ func (r *RequestMessageService) Delete(ctx context.Context, accountIdentifier st return } path := fmt.Sprintf("accounts/%s/cloudforce-one/requests/%s/message/%v", accountIdentifier, requestIdentifier, messageIdentifer) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result return } @@ -152,45 +159,30 @@ func (r messageJSON) RawJSON() string { return r.raw } -type RequestMessageDeleteResponse struct { - Errors []shared.ResponseInfo `json:"errors,required"` - Messages []shared.ResponseInfo `json:"messages,required"` - // Whether the API call was successful - Success RequestMessageDeleteResponseSuccess `json:"success,required"` - JSON requestMessageDeleteResponseJSON `json:"-"` -} - -// requestMessageDeleteResponseJSON contains the JSON metadata for the struct -// [RequestMessageDeleteResponse] -type requestMessageDeleteResponseJSON struct { - Errors apijson.Field - Messages apijson.Field - Success apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *RequestMessageDeleteResponse) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) +// Union satisfied by [cloudforce_one.RequestMessageDeleteResponseUnknown], +// [cloudforce_one.RequestMessageDeleteResponseArray] or [shared.UnionString]. +type RequestMessageDeleteResponseUnion interface { + ImplementsCloudforceOneRequestMessageDeleteResponseUnion() } -func (r requestMessageDeleteResponseJSON) RawJSON() string { - return r.raw +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*RequestMessageDeleteResponseUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(RequestMessageDeleteResponseArray{}), + }, + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(shared.UnionString("")), + }, + ) } -// Whether the API call was successful -type RequestMessageDeleteResponseSuccess bool - -const ( - RequestMessageDeleteResponseSuccessTrue RequestMessageDeleteResponseSuccess = true -) +type RequestMessageDeleteResponseArray []interface{} -func (r RequestMessageDeleteResponseSuccess) IsKnown() bool { - switch r { - case RequestMessageDeleteResponseSuccessTrue: - return true - } - return false +func (r RequestMessageDeleteResponseArray) ImplementsCloudforceOneRequestMessageDeleteResponseUnion() { } type RequestMessageNewParams struct { @@ -205,9 +197,9 @@ func (r RequestMessageNewParams) MarshalJSON() (data []byte, err error) { type RequestMessageNewResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Message `json:"result,required"` // Whether the API call was successful Success RequestMessageNewResponseEnvelopeSuccess `json:"success,required"` - Result Message `json:"result"` JSON requestMessageNewResponseEnvelopeJSON `json:"-"` } @@ -216,8 +208,8 @@ type RequestMessageNewResponseEnvelope struct { type requestMessageNewResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -284,9 +276,9 @@ func (r RequestMessageUpdateParamsTlp) IsKnown() bool { type RequestMessageUpdateResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Message `json:"result,required"` // Whether the API call was successful Success RequestMessageUpdateResponseEnvelopeSuccess `json:"success,required"` - Result Message `json:"result"` JSON requestMessageUpdateResponseEnvelopeJSON `json:"-"` } @@ -295,8 +287,8 @@ type RequestMessageUpdateResponseEnvelope struct { type requestMessageUpdateResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -324,6 +316,49 @@ func (r RequestMessageUpdateResponseEnvelopeSuccess) IsKnown() bool { return false } +type RequestMessageDeleteResponseEnvelope struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + Result RequestMessageDeleteResponseUnion `json:"result,required"` + // Whether the API call was successful + Success RequestMessageDeleteResponseEnvelopeSuccess `json:"success,required"` + JSON requestMessageDeleteResponseEnvelopeJSON `json:"-"` +} + +// requestMessageDeleteResponseEnvelopeJSON contains the JSON metadata for the +// struct [RequestMessageDeleteResponseEnvelope] +type requestMessageDeleteResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RequestMessageDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r requestMessageDeleteResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RequestMessageDeleteResponseEnvelopeSuccess bool + +const ( + RequestMessageDeleteResponseEnvelopeSuccessTrue RequestMessageDeleteResponseEnvelopeSuccess = true +) + +func (r RequestMessageDeleteResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RequestMessageDeleteResponseEnvelopeSuccessTrue: + return true + } + return false +} + type RequestMessageGetParams struct { // Page number of results Page param.Field[int64] `json:"page,required"` @@ -362,9 +397,9 @@ func (r RequestMessageGetParamsSortOrder) IsKnown() bool { type RequestMessageGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result []Message `json:"result,required"` // Whether the API call was successful Success RequestMessageGetResponseEnvelopeSuccess `json:"success,required"` - Result []Message `json:"result"` JSON requestMessageGetResponseEnvelopeJSON `json:"-"` } @@ -373,8 +408,8 @@ type RequestMessageGetResponseEnvelope struct { type requestMessageGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/cloudforce_one/requestpriority.go b/cloudforce_one/requestpriority.go index d3076af3f81..cb24f7c4b83 100644 --- a/cloudforce_one/requestpriority.go +++ b/cloudforce_one/requestpriority.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net/http" + "reflect" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" @@ -14,6 +15,7 @@ import ( "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" "github.com/cloudflare/cloudflare-go/v2/shared" + "github.com/tidwall/gjson" ) // RequestPriorityService contains methods and other services that help with @@ -74,8 +76,9 @@ func (r *RequestPriorityService) Update(ctx context.Context, accountIdentifier s } // Delete a Priority Intelligence Report -func (r *RequestPriorityService) Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string, opts ...option.RequestOption) (res *RequestPriorityDeleteResponse, err error) { +func (r *RequestPriorityService) Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string, opts ...option.RequestOption) (res *RequestPriorityDeleteResponseUnion, err error) { opts = append(r.Options[:], opts...) + var env RequestPriorityDeleteResponseEnvelope if accountIdentifier == "" { err = errors.New("missing required account_identifier parameter") return @@ -85,7 +88,11 @@ func (r *RequestPriorityService) Delete(ctx context.Context, accountIdentifier s return } path := fmt.Sprintf("accounts/%s/cloudforce-one/requests/priority/%s", accountIdentifier, priorityIdentifer) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result return } @@ -223,45 +230,30 @@ func (r PriorityEditTlp) IsKnown() bool { return false } -type RequestPriorityDeleteResponse struct { - Errors []shared.ResponseInfo `json:"errors,required"` - Messages []shared.ResponseInfo `json:"messages,required"` - // Whether the API call was successful - Success RequestPriorityDeleteResponseSuccess `json:"success,required"` - JSON requestPriorityDeleteResponseJSON `json:"-"` +// Union satisfied by [cloudforce_one.RequestPriorityDeleteResponseUnknown], +// [cloudforce_one.RequestPriorityDeleteResponseArray] or [shared.UnionString]. +type RequestPriorityDeleteResponseUnion interface { + ImplementsCloudforceOneRequestPriorityDeleteResponseUnion() } -// requestPriorityDeleteResponseJSON contains the JSON metadata for the struct -// [RequestPriorityDeleteResponse] -type requestPriorityDeleteResponseJSON struct { - Errors apijson.Field - Messages apijson.Field - Success apijson.Field - raw string - ExtraFields map[string]apijson.Field +func init() { + apijson.RegisterUnion( + reflect.TypeOf((*RequestPriorityDeleteResponseUnion)(nil)).Elem(), + "", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(RequestPriorityDeleteResponseArray{}), + }, + apijson.UnionVariant{ + TypeFilter: gjson.String, + Type: reflect.TypeOf(shared.UnionString("")), + }, + ) } -func (r *RequestPriorityDeleteResponse) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} +type RequestPriorityDeleteResponseArray []interface{} -func (r requestPriorityDeleteResponseJSON) RawJSON() string { - return r.raw -} - -// Whether the API call was successful -type RequestPriorityDeleteResponseSuccess bool - -const ( - RequestPriorityDeleteResponseSuccessTrue RequestPriorityDeleteResponseSuccess = true -) - -func (r RequestPriorityDeleteResponseSuccess) IsKnown() bool { - switch r { - case RequestPriorityDeleteResponseSuccessTrue: - return true - } - return false +func (r RequestPriorityDeleteResponseArray) ImplementsCloudforceOneRequestPriorityDeleteResponseUnion() { } type RequestPriorityNewParams struct { @@ -275,9 +267,9 @@ func (r RequestPriorityNewParams) MarshalJSON() (data []byte, err error) { type RequestPriorityNewResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Priority `json:"result,required"` // Whether the API call was successful Success RequestPriorityNewResponseEnvelopeSuccess `json:"success,required"` - Result Priority `json:"result"` JSON requestPriorityNewResponseEnvelopeJSON `json:"-"` } @@ -286,8 +278,8 @@ type RequestPriorityNewResponseEnvelope struct { type requestPriorityNewResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -326,9 +318,9 @@ func (r RequestPriorityUpdateParams) MarshalJSON() (data []byte, err error) { type RequestPriorityUpdateResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Item `json:"result,required"` // Whether the API call was successful Success RequestPriorityUpdateResponseEnvelopeSuccess `json:"success,required"` - Result Item `json:"result"` JSON requestPriorityUpdateResponseEnvelopeJSON `json:"-"` } @@ -337,8 +329,8 @@ type RequestPriorityUpdateResponseEnvelope struct { type requestPriorityUpdateResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -366,12 +358,55 @@ func (r RequestPriorityUpdateResponseEnvelopeSuccess) IsKnown() bool { return false } +type RequestPriorityDeleteResponseEnvelope struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + Result RequestPriorityDeleteResponseUnion `json:"result,required"` + // Whether the API call was successful + Success RequestPriorityDeleteResponseEnvelopeSuccess `json:"success,required"` + JSON requestPriorityDeleteResponseEnvelopeJSON `json:"-"` +} + +// requestPriorityDeleteResponseEnvelopeJSON contains the JSON metadata for the +// struct [RequestPriorityDeleteResponseEnvelope] +type requestPriorityDeleteResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RequestPriorityDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r requestPriorityDeleteResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RequestPriorityDeleteResponseEnvelopeSuccess bool + +const ( + RequestPriorityDeleteResponseEnvelopeSuccessTrue RequestPriorityDeleteResponseEnvelopeSuccess = true +) + +func (r RequestPriorityDeleteResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RequestPriorityDeleteResponseEnvelopeSuccessTrue: + return true + } + return false +} + type RequestPriorityGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Item `json:"result,required"` // Whether the API call was successful Success RequestPriorityGetResponseEnvelopeSuccess `json:"success,required"` - Result Item `json:"result"` JSON requestPriorityGetResponseEnvelopeJSON `json:"-"` } @@ -380,8 +415,8 @@ type RequestPriorityGetResponseEnvelope struct { type requestPriorityGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -412,9 +447,9 @@ func (r RequestPriorityGetResponseEnvelopeSuccess) IsKnown() bool { type RequestPriorityQuotaResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result Quota `json:"result,required"` // Whether the API call was successful Success RequestPriorityQuotaResponseEnvelopeSuccess `json:"success,required"` - Result Quota `json:"result"` JSON requestPriorityQuotaResponseEnvelopeJSON `json:"-"` } @@ -423,8 +458,8 @@ type RequestPriorityQuotaResponseEnvelope struct { type requestPriorityQuotaResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/intel/whois.go b/intel/whois.go index 65290b3410e..cf321dd9d6f 100644 --- a/intel/whois.go +++ b/intel/whois.go @@ -264,9 +264,9 @@ func (r WhoisGetParams) URLQuery() (v url.Values) { type WhoisGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` + Result WhoisGetResponse `json:"result,required"` // Whether the API call was successful Success WhoisGetResponseEnvelopeSuccess `json:"success,required"` - Result WhoisGetResponse `json:"result"` JSON whoisGetResponseEnvelopeJSON `json:"-"` } @@ -275,8 +275,8 @@ type WhoisGetResponseEnvelope struct { type whoisGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Success apijson.Field Result apijson.Field + Success apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/shared/union.go b/shared/union.go index c6d8ab57795..9048bf7e9f0 100644 --- a/shared/union.go +++ b/shared/union.go @@ -179,6 +179,9 @@ func (UnionString) ImplementsOriginPostQuantumEncryptionOriginPostQuantumEncrypt } func (UnionString) ImplementsHostnamesSettingValueUnionParam() {} func (UnionString) ImplementsHostnamesSettingValueUnion() {} +func (UnionString) ImplementsCloudforceOneRequestDeleteResponseUnion() {} +func (UnionString) ImplementsCloudforceOneRequestMessageDeleteResponseUnion() {} +func (UnionString) ImplementsCloudforceOneRequestPriorityDeleteResponseUnion() {} func (UnionString) ImplementsEventNotificationsR2ConfigurationQueueDeleteResponseUnion() {} type UnionInt int64