Skip to content

Commit 090a2e3

Browse files
feat(api): api update
1 parent d2723fb commit 090a2e3

File tree

244 files changed

+13698
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+13698
-206
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-cc3ad3383dd73a4bf35b91b19baf855439ec29635ee500163e0bd972faef7bea.yml
3-
openapi_spec_hash: 671698714962b7a17f2f1fc308ad9434
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-828c91953d2351040fdd4d90a3d9eafd09f9d240c4f6ce0441b7a10c06c1c722.yml
3+
openapi_spec_hash: c82bc88563f80f600e59e22014d4cec4
44
config_hash: 1f73a949b649ecfe6ec68ba1bb459dc2

src/Orb/Core/ModelBase.cs

Lines changed: 441 additions & 5 deletions
Large diffs are not rendered by default.

src/Orb/Models/AmountDiscount.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,14 @@ public List<string>? AppliesToPriceIDs
8989
/// <summary>
9090
/// The filters that determine which prices to apply this discount to.
9191
/// </summary>
92-
public List<TransformPriceFilter>? Filters
92+
public List<Filter>? Filters
9393
{
9494
get
9595
{
9696
if (!this.Properties.TryGetValue("filters", out JsonElement element))
9797
return null;
9898

99-
return JsonSerializer.Deserialize<List<TransformPriceFilter>?>(
100-
element,
101-
ModelBase.SerializerOptions
102-
);
99+
return JsonSerializer.Deserialize<List<Filter>?>(element, ModelBase.SerializerOptions);
103100
}
104101
set
105102
{

src/Orb/Models/AmountDiscountInterval.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public required DateTime? EndDate
124124
/// <summary>
125125
/// The filters that determine which prices this discount interval applies to.
126126
/// </summary>
127-
public required List<TransformPriceFilter> Filters
127+
public required List<Filter> Filters
128128
{
129129
get
130130
{
@@ -134,10 +134,7 @@ public required List<TransformPriceFilter> Filters
134134
new ArgumentOutOfRangeException("filters", "Missing required argument")
135135
);
136136

137-
return JsonSerializer.Deserialize<List<TransformPriceFilter>>(
138-
element,
139-
ModelBase.SerializerOptions
140-
)
137+
return JsonSerializer.Deserialize<List<Filter>>(element, ModelBase.SerializerOptions)
141138
?? throw new OrbInvalidDataException(
142139
"'filters' cannot be null",
143140
new ArgumentNullException("filters")
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.AmountDiscountIntervalProperties.FilterProperties;
9+
10+
namespace Orb.Models.AmountDiscountIntervalProperties;
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.AmountDiscountIntervalProperties.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.AmountDiscountIntervalProperties.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)