Skip to content

Commit 7f1811a

Browse files
feat(api): api update
1 parent f109cc7 commit 7f1811a

File tree

28 files changed

+1170
-40
lines changed

28 files changed

+1170
-40
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 118
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-cbce25283cb9c3282e03e08b7ee81395436af7d0eb480ffcbab307b5bf1c92a0.yml
3-
openapi_spec_hash: c286edf46db95dee05eb6f180ac24ab0
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-ef726ad139fa29757029206ee08150434fc6c52005fec6d42c7d2bcd3aa7ab47.yml
3+
openapi_spec_hash: e622beb7c26f9b0dd641bd5c92735a5b
44
config_hash: dd4343ce95871032ef6e0735a4ca038c

src/Orb/Core/ModelBase.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Collections.Generic;
22
using System.Text.Json;
33
using Orb.Models;
4+
using Orb.Models.AllocationProperties.FilterProperties;
45
using Orb.Models.AmountDiscountProperties;
5-
using Orb.Models.AmountDiscountProperties.FilterProperties;
66
using Orb.Models.BillingCycleConfigurationProperties;
77
using Orb.Models.ChangedSubscriptionResourcesProperties.CreatedInvoiceProperties.CustomerBalanceTransactionProperties;
88
using Orb.Models.ChangedSubscriptionResourcesProperties.CreatedInvoiceProperties.PaymentAttemptProperties;
@@ -34,7 +34,6 @@
3434
using BalanceTransactionCreateParamsProperties = Orb.Models.Customers.BalanceTransactions.BalanceTransactionCreateParamsProperties;
3535
using BalanceTransactionCreateResponseProperties = Orb.Models.Customers.BalanceTransactions.BalanceTransactionCreateResponseProperties;
3636
using BillableMetricProperties = Orb.Models.Metrics.BillableMetricProperties;
37-
using BlockFilterProperties = Orb.Models.Customers.Credits.Ledger.AffectedBlockProperties.BlockFilterProperties;
3837
using BulkProperties = Orb.Models.PriceProperties.BulkProperties;
3938
using BulkWithFiltersProperties = Orb.Models.PriceProperties.BulkWithFiltersProperties;
4039
using BulkWithProrationProperties = Orb.Models.PriceProperties.BulkWithProrationProperties;
@@ -58,7 +57,7 @@
5857
using EventOutputProperties = Orb.Models.PriceProperties.EventOutputProperties;
5958
using ExpirationChangeLedgerEntryProperties = Orb.Models.Customers.Credits.Ledger.ExpirationChangeLedgerEntryProperties;
6059
using ExternalConnectionProperties = Orb.Models.Items.ItemUpdateParamsProperties.ExternalConnectionProperties;
61-
using FilterProperties = Orb.Models.AmountDiscountIntervalProperties.FilterProperties;
60+
using FilterProperties = Orb.Models.AmountDiscountProperties.FilterProperties;
6261
using GroupedAllocationProperties = Orb.Models.PriceProperties.GroupedAllocationProperties;
6362
using GroupedTieredPackageProperties = Orb.Models.PriceProperties.GroupedTieredPackageProperties;
6463
using GroupedTieredProperties = Orb.Models.PriceProperties.GroupedTieredProperties;
@@ -227,12 +226,20 @@ public abstract record class ModelBase
227226
{
228227
Converters =
229228
{
230-
new ApiEnumConverter<string, DiscountType>(),
231229
new ApiEnumConverter<string, Field>(),
232230
new ApiEnumConverter<string, Operator>(),
233-
new ApiEnumConverter<string, AmountDiscountIntervalProperties::DiscountType>(),
231+
new ApiEnumConverter<string, DiscountType>(),
234232
new ApiEnumConverter<string, FilterProperties::Field>(),
235233
new ApiEnumConverter<string, FilterProperties::Operator>(),
234+
new ApiEnumConverter<string, AmountDiscountIntervalProperties::DiscountType>(),
235+
new ApiEnumConverter<
236+
string,
237+
global::Orb.Models.AmountDiscountIntervalProperties.FilterProperties.Field
238+
>(),
239+
new ApiEnumConverter<
240+
string,
241+
global::Orb.Models.AmountDiscountIntervalProperties.FilterProperties.Operator
242+
>(),
236243
new ApiEnumConverter<string, DurationUnit>(),
237244
new ApiEnumConverter<string, BillingCycleRelativeDate>(),
238245
new ApiEnumConverter<string, Action>(),
@@ -1119,8 +1126,14 @@ public abstract record class ModelBase
11191126
new ApiEnumConverter<string, CostListByExternalIDParamsProperties::ViewMode>(),
11201127
new ApiEnumConverter<string, Status>(),
11211128
new ApiEnumConverter<string, DataProperties::Status>(),
1122-
new ApiEnumConverter<string, BlockFilterProperties::Field>(),
1123-
new ApiEnumConverter<string, BlockFilterProperties::Operator>(),
1129+
new ApiEnumConverter<
1130+
string,
1131+
global::Orb.Models.Customers.Credits.Ledger.AffectedBlockProperties.FilterProperties.Field
1132+
>(),
1133+
new ApiEnumConverter<
1134+
string,
1135+
global::Orb.Models.Customers.Credits.Ledger.AffectedBlockProperties.FilterProperties.Operator
1136+
>(),
11241137
new ApiEnumConverter<string, EntryStatus>(),
11251138
new ApiEnumConverter<string, EntryType>(),
11261139
new ApiEnumConverter<string, CreditBlockExpiryLedgerEntryProperties::EntryStatus>(),

src/Orb/Models/Allocation.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text.Json.Serialization;
66
using Orb.Core;
77
using Orb.Exceptions;
8+
using Orb.Models.AllocationProperties;
89

910
namespace Orb.Models;
1011

@@ -78,11 +79,33 @@ public required CustomExpiration? CustomExpiration
7879
}
7980
}
8081

82+
public List<Filter>? Filters
83+
{
84+
get
85+
{
86+
if (!this.Properties.TryGetValue("filters", out JsonElement element))
87+
return null;
88+
89+
return JsonSerializer.Deserialize<List<Filter>?>(element, ModelBase.SerializerOptions);
90+
}
91+
set
92+
{
93+
this.Properties["filters"] = JsonSerializer.SerializeToElement(
94+
value,
95+
ModelBase.SerializerOptions
96+
);
97+
}
98+
}
99+
81100
public override void Validate()
82101
{
83102
_ = this.AllowsRollover;
84103
_ = this.Currency;
85104
this.CustomExpiration?.Validate();
105+
foreach (var item in this.Filters ?? [])
106+
{
107+
item.Validate();
108+
}
86109
}
87110

88111
public Allocation() { }
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
using Orb.Core;
7+
using Orb.Exceptions;
8+
using Orb.Models.AllocationProperties.FilterProperties;
9+
10+
namespace Orb.Models.AllocationProperties;
11+
12+
[JsonConverter(typeof(ModelConverter<Filter>))]
13+
public sealed record class Filter : ModelBase, IFromRaw<Filter>
14+
{
15+
/// <summary>
16+
/// The property of the price to filter on.
17+
/// </summary>
18+
public required ApiEnum<string, Field> Field
19+
{
20+
get
21+
{
22+
if (!this.Properties.TryGetValue("field", out JsonElement element))
23+
throw new OrbInvalidDataException(
24+
"'field' cannot be null",
25+
new ArgumentOutOfRangeException("field", "Missing required argument")
26+
);
27+
28+
return JsonSerializer.Deserialize<ApiEnum<string, Field>>(
29+
element,
30+
ModelBase.SerializerOptions
31+
);
32+
}
33+
set
34+
{
35+
this.Properties["field"] = JsonSerializer.SerializeToElement(
36+
value,
37+
ModelBase.SerializerOptions
38+
);
39+
}
40+
}
41+
42+
/// <summary>
43+
/// Should prices that match the filter be included or excluded.
44+
/// </summary>
45+
public required ApiEnum<string, Operator> Operator
46+
{
47+
get
48+
{
49+
if (!this.Properties.TryGetValue("operator", out JsonElement element))
50+
throw new OrbInvalidDataException(
51+
"'operator' cannot be null",
52+
new ArgumentOutOfRangeException("operator", "Missing required argument")
53+
);
54+
55+
return JsonSerializer.Deserialize<ApiEnum<string, Operator>>(
56+
element,
57+
ModelBase.SerializerOptions
58+
);
59+
}
60+
set
61+
{
62+
this.Properties["operator"] = JsonSerializer.SerializeToElement(
63+
value,
64+
ModelBase.SerializerOptions
65+
);
66+
}
67+
}
68+
69+
/// <summary>
70+
/// The IDs or values that match this filter.
71+
/// </summary>
72+
public required List<string> Values
73+
{
74+
get
75+
{
76+
if (!this.Properties.TryGetValue("values", out JsonElement element))
77+
throw new OrbInvalidDataException(
78+
"'values' cannot be null",
79+
new ArgumentOutOfRangeException("values", "Missing required argument")
80+
);
81+
82+
return JsonSerializer.Deserialize<List<string>>(element, ModelBase.SerializerOptions)
83+
?? throw new OrbInvalidDataException(
84+
"'values' cannot be null",
85+
new ArgumentNullException("values")
86+
);
87+
}
88+
set
89+
{
90+
this.Properties["values"] = JsonSerializer.SerializeToElement(
91+
value,
92+
ModelBase.SerializerOptions
93+
);
94+
}
95+
}
96+
97+
public override void Validate()
98+
{
99+
this.Field.Validate();
100+
this.Operator.Validate();
101+
foreach (var item in this.Values)
102+
{
103+
_ = item;
104+
}
105+
}
106+
107+
public Filter() { }
108+
109+
#pragma warning disable CS8618
110+
[SetsRequiredMembers]
111+
Filter(Dictionary<string, JsonElement> properties)
112+
{
113+
Properties = properties;
114+
}
115+
#pragma warning restore CS8618
116+
117+
public static Filter FromRawUnchecked(Dictionary<string, JsonElement> properties)
118+
{
119+
return new(properties);
120+
}
121+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
using Orb.Exceptions;
5+
6+
namespace Orb.Models.AllocationProperties.FilterProperties;
7+
8+
/// <summary>
9+
/// The property of the price to filter on.
10+
/// </summary>
11+
[JsonConverter(typeof(FieldConverter))]
12+
public enum Field
13+
{
14+
PriceID,
15+
ItemID,
16+
PriceType,
17+
Currency,
18+
PricingUnitID,
19+
}
20+
21+
sealed class FieldConverter : JsonConverter<Field>
22+
{
23+
public override Field Read(
24+
ref Utf8JsonReader reader,
25+
Type typeToConvert,
26+
JsonSerializerOptions options
27+
)
28+
{
29+
return JsonSerializer.Deserialize<string>(ref reader, options) switch
30+
{
31+
"price_id" => Field.PriceID,
32+
"item_id" => Field.ItemID,
33+
"price_type" => Field.PriceType,
34+
"currency" => Field.Currency,
35+
"pricing_unit_id" => Field.PricingUnitID,
36+
_ => (Field)(-1),
37+
};
38+
}
39+
40+
public override void Write(Utf8JsonWriter writer, Field value, JsonSerializerOptions options)
41+
{
42+
JsonSerializer.Serialize(
43+
writer,
44+
value switch
45+
{
46+
Field.PriceID => "price_id",
47+
Field.ItemID => "item_id",
48+
Field.PriceType => "price_type",
49+
Field.Currency => "currency",
50+
Field.PricingUnitID => "pricing_unit_id",
51+
_ => throw new OrbInvalidDataException(
52+
string.Format("Invalid value '{0}' in {1}", value, nameof(value))
53+
),
54+
},
55+
options
56+
);
57+
}
58+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
using Orb.Exceptions;
5+
6+
namespace Orb.Models.AllocationProperties.FilterProperties;
7+
8+
/// <summary>
9+
/// Should prices that match the filter be included or excluded.
10+
/// </summary>
11+
[JsonConverter(typeof(OperatorConverter))]
12+
public enum Operator
13+
{
14+
Includes,
15+
Excludes,
16+
}
17+
18+
sealed class OperatorConverter : JsonConverter<Operator>
19+
{
20+
public override Operator Read(
21+
ref Utf8JsonReader reader,
22+
Type typeToConvert,
23+
JsonSerializerOptions options
24+
)
25+
{
26+
return JsonSerializer.Deserialize<string>(ref reader, options) switch
27+
{
28+
"includes" => Operator.Includes,
29+
"excludes" => Operator.Excludes,
30+
_ => (Operator)(-1),
31+
};
32+
}
33+
34+
public override void Write(Utf8JsonWriter writer, Operator value, JsonSerializerOptions options)
35+
{
36+
JsonSerializer.Serialize(
37+
writer,
38+
value switch
39+
{
40+
Operator.Includes => "includes",
41+
Operator.Excludes => "excludes",
42+
_ => throw new OrbInvalidDataException(
43+
string.Format("Invalid value '{0}' in {1}", value, nameof(value))
44+
),
45+
},
46+
options
47+
);
48+
}
49+
}

0 commit comments

Comments
 (0)