Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 16, 2024
1 parent 0263314 commit 8c0b014
Show file tree
Hide file tree
Showing 16 changed files with 1,727 additions and 318 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1256
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-74d68374448e03b29a39bb6cdf6c39cdeaaaa691dd9c38f46a26a1d562c8ee37.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-b116e60da4a69a05bc8823c2397e4a33d111c82a6b458ea4f480d0ba52ea8de0.yml
20 changes: 11 additions & 9 deletions api.md

Large diffs are not rendered by default.

107 changes: 56 additions & 51 deletions api_gateway/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"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"
)

Expand All @@ -39,19 +38,14 @@ func NewConfigurationService(opts ...option.RequestOption) (r *ConfigurationServ
}

// Set configuration properties
func (r *ConfigurationService) Update(ctx context.Context, params ConfigurationUpdateParams, opts ...option.RequestOption) (res *ConfigurationUpdateResponseUnion, err error) {
var env ConfigurationUpdateResponseEnvelope
func (r *ConfigurationService) Update(ctx context.Context, params ConfigurationUpdateParams, opts ...option.RequestOption) (res *ConfigurationUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
if params.ZoneID.Value == "" {
err = errors.New("missing required zone_id parameter")
return
}
path := fmt.Sprintf("zones/%s/api_gateway/configuration", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &res, opts...)
return
}

Expand All @@ -73,7 +67,7 @@ func (r *ConfigurationService) Get(ctx context.Context, params ConfigurationGetP
}

type Configuration struct {
AuthIDCharacteristics []ConfigurationAuthIDCharacteristic `json:"auth_id_characteristics"`
AuthIDCharacteristics []ConfigurationAuthIDCharacteristic `json:"auth_id_characteristics,required"`
JSON configurationJSON `json:"-"`
}

Expand Down Expand Up @@ -273,7 +267,7 @@ func (r ConfigurationAuthIDCharacteristicsType) IsKnown() bool {
}

type ConfigurationParam struct {
AuthIDCharacteristics param.Field[[]ConfigurationAuthIDCharacteristicsUnionParam] `json:"auth_id_characteristics"`
AuthIDCharacteristics param.Field[[]ConfigurationAuthIDCharacteristicsUnionParam] `json:"auth_id_characteristics,required"`
}

func (r ConfigurationParam) MarshalJSON() (data []byte, err error) {
Expand Down Expand Up @@ -341,61 +335,57 @@ func (r ConfigurationAuthIDCharacteristicsAPIShieldAuthIDCharacteristicJwtClaimP
func (r ConfigurationAuthIDCharacteristicsAPIShieldAuthIDCharacteristicJwtClaimParam) implementsAPIGatewayConfigurationAuthIDCharacteristicsUnionParam() {
}

// Union satisfied by [api_gateway.ConfigurationUpdateResponseUnknown] or
// [shared.UnionString].
type ConfigurationUpdateResponseUnion interface {
ImplementsAPIGatewayConfigurationUpdateResponseUnion()
}

func init() {
apijson.RegisterUnion(
reflect.TypeOf((*ConfigurationUpdateResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}

type ConfigurationUpdateParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Configuration ConfigurationParam `json:"configuration,required"`
}

func (r ConfigurationUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Configuration)
}

type ConfigurationUpdateResponseEnvelope struct {
Errors Message `json:"errors,required"`
Messages Message `json:"messages,required"`
Result ConfigurationUpdateResponseUnion `json:"result,required"`
type ConfigurationUpdateResponse struct {
Errors Message `json:"errors,required"`
Messages Message `json:"messages,required"`
// Whether the API call was successful
Success bool `json:"success,required"`
JSON configurationUpdateResponseEnvelopeJSON `json:"-"`
Success ConfigurationUpdateResponseSuccess `json:"success,required"`
JSON configurationUpdateResponseJSON `json:"-"`
}

// configurationUpdateResponseEnvelopeJSON contains the JSON metadata for the
// struct [ConfigurationUpdateResponseEnvelope]
type configurationUpdateResponseEnvelopeJSON struct {
// configurationUpdateResponseJSON contains the JSON metadata for the struct
// [ConfigurationUpdateResponse]
type configurationUpdateResponseJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *ConfigurationUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
func (r *ConfigurationUpdateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r configurationUpdateResponseEnvelopeJSON) RawJSON() string {
func (r configurationUpdateResponseJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type ConfigurationUpdateResponseSuccess bool

const (
ConfigurationUpdateResponseSuccessTrue ConfigurationUpdateResponseSuccess = true
)

func (r ConfigurationUpdateResponseSuccess) IsKnown() bool {
switch r {
case ConfigurationUpdateResponseSuccessTrue:
return true
}
return false
}

type ConfigurationUpdateParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Configuration ConfigurationParam `json:"configuration,required"`
}

func (r ConfigurationUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Configuration)
}

type ConfigurationGetParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Expand Down Expand Up @@ -430,8 +420,8 @@ type ConfigurationGetResponseEnvelope struct {
Messages Message `json:"messages,required"`
Result Configuration `json:"result,required"`
// Whether the API call was successful
Success bool `json:"success,required"`
JSON configurationGetResponseEnvelopeJSON `json:"-"`
Success ConfigurationGetResponseEnvelopeSuccess `json:"success,required"`
JSON configurationGetResponseEnvelopeJSON `json:"-"`
}

// configurationGetResponseEnvelopeJSON contains the JSON metadata for the struct
Expand All @@ -452,3 +442,18 @@ func (r *ConfigurationGetResponseEnvelope) UnmarshalJSON(data []byte) (err error
func (r configurationGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type ConfigurationGetResponseEnvelopeSuccess bool

const (
ConfigurationGetResponseEnvelopeSuccessTrue ConfigurationGetResponseEnvelopeSuccess = true
)

func (r ConfigurationGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ConfigurationGetResponseEnvelopeSuccessTrue:
return true
}
return false
}
2 changes: 1 addition & 1 deletion api_gateway/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cloudflare/cloudflare-go/v2/option"
)

func TestConfigurationUpdateWithOptionalParams(t *testing.T) {
func TestConfigurationUpdate(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand Down
27 changes: 21 additions & 6 deletions api_gateway/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (r *DiscoveryService) Get(ctx context.Context, query DiscoveryGetParams, op
}

type DiscoveryOperation struct {
// UUID identifier
ID string `json:"id,required" format:"uuid"`
// UUID
ID string `json:"id,required"`
// The endpoint which can contain path parameter templates in curly braces, each
// will be replaced from left to right with {varN}, starting with {var1}, during
// insertion. This will further be Cloudflare-normalized upon insertion. See:
Expand Down Expand Up @@ -213,8 +213,8 @@ func (r discoveryOperationFeaturesTrafficStatsJSON) RawJSON() string {
}

type DiscoveryGetResponse struct {
Schemas []interface{} `json:"schemas"`
Timestamp time.Time `json:"timestamp" format:"date-time"`
Schemas []interface{} `json:"schemas,required"`
Timestamp time.Time `json:"timestamp,required" format:"date-time"`
JSON discoveryGetResponseJSON `json:"-"`
}

Expand Down Expand Up @@ -245,8 +245,8 @@ type DiscoveryGetResponseEnvelope struct {
Messages Message `json:"messages,required"`
Result DiscoveryGetResponse `json:"result,required"`
// Whether the API call was successful
Success bool `json:"success,required"`
JSON discoveryGetResponseEnvelopeJSON `json:"-"`
Success DiscoveryGetResponseEnvelopeSuccess `json:"success,required"`
JSON discoveryGetResponseEnvelopeJSON `json:"-"`
}

// discoveryGetResponseEnvelopeJSON contains the JSON metadata for the struct
Expand All @@ -267,3 +267,18 @@ func (r *DiscoveryGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
func (r discoveryGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type DiscoveryGetResponseEnvelopeSuccess bool

const (
DiscoveryGetResponseEnvelopeSuccessTrue DiscoveryGetResponseEnvelopeSuccess = true
)

func (r DiscoveryGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DiscoveryGetResponseEnvelopeSuccessTrue:
return true
}
return false
}
29 changes: 22 additions & 7 deletions api_gateway/discoveryoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewDiscoveryOperationService(opts ...option.RequestOption) (r *DiscoveryOpe
}

// Retrieve the most up to date view of discovered operations
func (r *DiscoveryOperationService) List(ctx context.Context, params DiscoveryOperationListParams, opts ...option.RequestOption) (res *pagination.SinglePage[DiscoveryOperation], err error) {
func (r *DiscoveryOperationService) List(ctx context.Context, params DiscoveryOperationListParams, opts ...option.RequestOption) (res *pagination.V4PagePaginationArray[DiscoveryOperation], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
Expand All @@ -59,8 +59,8 @@ func (r *DiscoveryOperationService) List(ctx context.Context, params DiscoveryOp
}

// Retrieve the most up to date view of discovered operations
func (r *DiscoveryOperationService) ListAutoPaging(ctx context.Context, params DiscoveryOperationListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[DiscoveryOperation] {
return pagination.NewSinglePageAutoPager(r.List(ctx, params, opts...))
func (r *DiscoveryOperationService) ListAutoPaging(ctx context.Context, params DiscoveryOperationListParams, opts ...option.RequestOption) *pagination.V4PagePaginationArrayAutoPager[DiscoveryOperation] {
return pagination.NewV4PagePaginationArrayAutoPager(r.List(ctx, params, opts...))
}

// Update the `state` on a discovered operation
Expand Down Expand Up @@ -155,9 +155,9 @@ type DiscoveryOperationListParams struct {
// Identifier API Discovery
Origin param.Field[DiscoveryOperationListParamsOrigin] `query:"origin"`
// Page number of paginated results.
Page param.Field[interface{}] `query:"page"`
Page param.Field[int64] `query:"page"`
// Maximum number of results per page.
PerPage param.Field[interface{}] `query:"per_page"`
PerPage param.Field[int64] `query:"per_page"`
// Filter results to only include discovery results in a particular state. States
// are as follows
//
Expand Down Expand Up @@ -296,8 +296,8 @@ type DiscoveryOperationEditResponseEnvelope struct {
Messages Message `json:"messages,required"`
Result DiscoveryOperationEditResponse `json:"result,required"`
// Whether the API call was successful
Success bool `json:"success,required"`
JSON discoveryOperationEditResponseEnvelopeJSON `json:"-"`
Success DiscoveryOperationEditResponseEnvelopeSuccess `json:"success,required"`
JSON discoveryOperationEditResponseEnvelopeJSON `json:"-"`
}

// discoveryOperationEditResponseEnvelopeJSON contains the JSON metadata for the
Expand All @@ -318,3 +318,18 @@ func (r *DiscoveryOperationEditResponseEnvelope) UnmarshalJSON(data []byte) (err
func (r discoveryOperationEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type DiscoveryOperationEditResponseEnvelopeSuccess bool

const (
DiscoveryOperationEditResponseEnvelopeSuccessTrue DiscoveryOperationEditResponseEnvelopeSuccess = true
)

func (r DiscoveryOperationEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DiscoveryOperationEditResponseEnvelopeSuccessTrue:
return true
}
return false
}
6 changes: 3 additions & 3 deletions api_gateway/discoveryoperation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestDiscoveryOperationListWithOptionalParams(t *testing.T) {
Method: cloudflare.F([]string{"GET"}),
Order: cloudflare.F(api_gateway.DiscoveryOperationListParamsOrderMethod),
Origin: cloudflare.F(api_gateway.DiscoveryOperationListParamsOriginMl),
Page: cloudflare.F[any](map[string]interface{}{}),
PerPage: cloudflare.F[any](map[string]interface{}{}),
Page: cloudflare.F(int64(1)),
PerPage: cloudflare.F(int64(5)),
State: cloudflare.F(api_gateway.DiscoveryOperationListParamsStateReview),
})
if err != nil {
Expand All @@ -64,7 +64,7 @@ func TestDiscoveryOperationEditWithOptionalParams(t *testing.T) {
)
_, err := client.APIGateway.Discovery.Operations.Edit(
context.TODO(),
"0d9bf70c-92e1-4bb3-9411-34a3bcc59003",
"f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
api_gateway.DiscoveryOperationEditParams{
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
State: cloudflare.F(api_gateway.DiscoveryOperationEditParamsStateReview),
Expand Down
Loading

0 comments on commit 8c0b014

Please sign in to comment.