Skip to content

Commit

Permalink
Updated for latest spec
Browse files Browse the repository at this point in the history
Allow arbitrary values in advanced_options.

Fix properties that were incorrectly marked as required.
  • Loading branch information
joshuaflanagan committed Oct 9, 2024
1 parent ef486d5 commit e4146a5
Show file tree
Hide file tree
Showing 13 changed files with 1,628 additions and 1,088 deletions.
3 changes: 3 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ ShipEngineSDK/Model/LabelLayout.cs
ShipEngineSDK/Model/LabelMessages.cs
ShipEngineSDK/Model/LabelPackage.cs
ShipEngineSDK/Model/LabelPackagesInner.cs
ShipEngineSDK/Model/LabelRequest.cs
ShipEngineSDK/Model/LabelStatus.cs
ShipEngineSDK/Model/Link.cs
ShipEngineSDK/Model/ListAccountImagesResponseBody.cs
Expand Down Expand Up @@ -259,6 +260,7 @@ ShipEngineSDK/Model/RateRequestOptions.cs
ShipEngineSDK/Model/RateRequestRateOptions.cs
ShipEngineSDK/Model/RateResponse.cs
ShipEngineSDK/Model/RateResponseStatus.cs
ShipEngineSDK/Model/RateShipmentRequest.cs
ShipEngineSDK/Model/RateType.cs
ShipEngineSDK/Model/RatesInformation.cs
ShipEngineSDK/Model/ReasonCode.cs
Expand All @@ -277,6 +279,7 @@ ShipEngineSDK/Model/ShipmentRequest.cs
ShipEngineSDK/Model/ShipmentStatus.cs
ShipEngineSDK/Model/ShipmentsSortBy.cs
ShipEngineSDK/Model/ShippingAddress.cs
ShipEngineSDK/Model/ShippingAddressFrom.cs
ShipEngineSDK/Model/ShippingAddressTo.cs
ShipEngineSDK/Model/SmartPostHub.cs
ShipEngineSDK/Model/SortDir.cs
Expand Down
43 changes: 10 additions & 33 deletions ShipEngineSDK.Test/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void WhenSerializing_ItShouldSerializeShipmentId()
[Fact]
public void WhenSerializing_ItShouldSerializeShipment()
{
var body = new CalculateRatesRequestBody(new ShipmentRequest
var body = new CalculateRatesRequestBody(new RateShipmentRequest
{
Shipment = new AddressValidatingShipment
{
Expand Down Expand Up @@ -183,37 +183,14 @@ public void WhenSerializing_ItShouldSerializeShipment()

var result = JsonSerializer.Serialize(body, ShipEngineClient.JsonSerializerOptions);

Assert.Equal(@"{
""rate_options"": {
""carrier_ids"": [
""se-99999""
]
},
""shipment"": {
""carrier_id"": ""se-88888"",
""service_code"": ""overnight"",
""ship_from"": {
""address_line1"": ""123 Main St."",
""address_residential_indicator"": ""no"",
""city_locality"": ""St. Louis"",
""country_code"": ""US"",
""name"": ""John Doe"",
""phone"": ""314-555-1234"",
""postal_code"": ""63102"",
""state_province"": ""MO""
},
""ship_to"": {
""address_line1"": ""456 Central"",
""address_residential_indicator"": ""yes"",
""city_locality"": ""St. Louis"",
""country_code"": ""US"",
""name"": ""Jane Doe"",
""phone"": ""314-555-5678"",
""postal_code"": ""63033"",
""state_province"": ""MO""
}
}
}", result);
// spot check some properties on the serialized value.
// comparing the serialized value to a string is too brittle, as order and indentation can change
var parsed = JsonDocument.Parse(result).RootElement;
var shipment = parsed.GetProperty("shipment");
Assert.Equal("se-88888", shipment.GetProperty("carrier_id").GetString());
Assert.Equal("overnight", shipment.GetProperty("service_code").GetString());
Assert.Equal("123 Main St.", shipment.GetProperty("ship_from").GetProperty("address_line1").GetString());
Assert.Equal("456 Central", shipment.GetProperty("ship_to").GetProperty("address_line1").GetString());
}

[Fact]
Expand Down Expand Up @@ -250,7 +227,7 @@ public void WhenDeserializing_ItShouldDeserializeShipment()

var result = JsonSerializer.Deserialize<CalculateRatesRequestBody>(json, ShipEngineClient.JsonSerializerOptions);

Assert.NotNull(result.GetShipmentRequest());
Assert.NotNull(result.GetRateShipmentRequest());
Assert.Contains("se-99999", result.RateOptions.CarrierIds);
}
}
Expand Down
76 changes: 38 additions & 38 deletions ShipEngineSDK/Model/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,34 @@ public partial class Address
[JsonPropertyName("address_line1"), JsonPropertyOrder(1)]
public required string AddressLine1 { get; set; }

/// <summary>
/// Indicates whether this is a residential address.
/// </summary>
/// <value>Indicates whether this is a residential address.</value>
[JsonPropertyName("address_residential_indicator"), JsonPropertyOrder(2)]
public required AddressResidentialIndicator AddressResidentialIndicator { get; set; }

/// <summary>
/// The name of the city or locality
/// </summary>
/// <value>The name of the city or locality</value>
/// <example>
/// Winnipeg
/// </example>
[JsonPropertyName("city_locality"), JsonPropertyOrder(3)]
[JsonPropertyName("city_locality"), JsonPropertyOrder(2)]
public required string CityLocality { get; set; }

/// <summary>
/// The two-letter [ISO 3166-1 country code](https://en.wikipedia.org/wiki/ISO_3166-1)
/// </summary>
/// <value>The two-letter [ISO 3166-1 country code](https://en.wikipedia.org/wiki/ISO_3166-1) </value>
/// <example>
/// CA
/// </example>
[JsonPropertyName("country_code"), JsonPropertyOrder(4)]
public required string CountryCode { get; set; }

/// <summary>
/// The name of a contact person at this address. This field may be set instead of - or in addition to - the &#x60;company_name&#x60; field.
/// </summary>
/// <value>The name of a contact person at this address. This field may be set instead of - or in addition to - the &#x60;company_name&#x60; field. </value>
/// <example>
/// John Doe
/// </example>
[JsonPropertyName("name"), JsonPropertyOrder(5)]
[JsonPropertyName("name"), JsonPropertyOrder(3)]
public required string Name { get; set; }

/// <summary>
/// The phone number of a contact person at this address. The format of this phone number varies depending on the country.
/// </summary>
/// <value>The phone number of a contact person at this address. The format of this phone number varies depending on the country. </value>
/// <example>
/// +1 204-253-9411 ext. 123
/// </example>
[JsonPropertyName("phone"), JsonPropertyOrder(6)]
public required string Phone { get; set; }

/// <summary>
/// postal code
/// </summary>
/// <value>postal code</value>
/// <example>
/// 78756-3717
/// </example>
[JsonPropertyName("postal_code"), JsonPropertyOrder(7)]
[JsonPropertyName("postal_code"), JsonPropertyOrder(4)]
public required string PostalCode { get; set; }

/// <summary>
Expand All @@ -100,7 +73,7 @@ public partial class Address
/// <example>
/// Manitoba
/// </example>
[JsonPropertyName("state_province"), JsonPropertyOrder(8)]
[JsonPropertyName("state_province"), JsonPropertyOrder(5)]
public required string StateProvince { get; set; }

/// <summary>
Expand All @@ -110,7 +83,7 @@ public partial class Address
/// <example>
/// Unit 408
/// </example>
[JsonPropertyName("address_line2"), JsonPropertyOrder(9)]
[JsonPropertyName("address_line2"), JsonPropertyOrder(6)]
public string? AddressLine2 { get; set; }

/// <summary>
Expand All @@ -120,29 +93,56 @@ public partial class Address
/// <example>
/// Building #7
/// </example>
[JsonPropertyName("address_line3"), JsonPropertyOrder(10)]
[JsonPropertyName("address_line3"), JsonPropertyOrder(7)]
public string? AddressLine3 { get; set; }

/// <summary>
/// Indicates whether this is a residential address.
/// </summary>
/// <value>Indicates whether this is a residential address.</value>
[JsonPropertyName("address_residential_indicator"), JsonPropertyOrder(8)]
public AddressResidentialIndicator? AddressResidentialIndicator { get; set; }

/// <summary>
/// If this is a business address, then the company name should be specified here.
/// </summary>
/// <value>If this is a business address, then the company name should be specified here. </value>
/// <example>
/// The Home Depot
/// </example>
[JsonPropertyName("company_name"), JsonPropertyOrder(11)]
[JsonPropertyName("company_name"), JsonPropertyOrder(9)]
public string? CompanyName { get; set; }

/// <summary>
/// The two-letter [ISO 3166-1 country code](https://en.wikipedia.org/wiki/ISO_3166-1)
/// </summary>
/// <value>The two-letter [ISO 3166-1 country code](https://en.wikipedia.org/wiki/ISO_3166-1) </value>
/// <example>
/// CA
/// </example>
[JsonPropertyName("country_code"), JsonPropertyOrder(10)]
public string? CountryCode { get; set; }

/// <summary>
/// Email for the address owner.
/// </summary>
/// <value>Email for the address owner. </value>
/// <example>
/// [email protected]
/// </example>
[JsonPropertyName("email"), JsonPropertyOrder(12)]
[JsonPropertyName("email"), JsonPropertyOrder(11)]
public string? Email { get; set; }

/// <summary>
/// The phone number of a contact person at this address. The format of this phone number varies depending on the country.
/// </summary>
/// <value>The phone number of a contact person at this address. The format of this phone number varies depending on the country. </value>
/// <example>
/// +1 204-253-9411 ext. 123
/// </example>
[JsonPropertyName("phone"), JsonPropertyOrder(12)]
public string? Phone { get; set; }


/// <summary>
/// Returns the string presentation of the object
Expand All @@ -154,17 +154,17 @@ public override string ToString()
sb.Append("class Address {\n");
#pragma warning disable CS0612 // Type or member is obsolete
sb.Append(" AddressLine1: ").Append(AddressLine1).Append("\n");
sb.Append(" AddressResidentialIndicator: ").Append(AddressResidentialIndicator).Append("\n");
sb.Append(" CityLocality: ").Append(CityLocality).Append("\n");
sb.Append(" CountryCode: ").Append(CountryCode).Append("\n");
sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append(" Phone: ").Append(Phone).Append("\n");
sb.Append(" PostalCode: ").Append(PostalCode).Append("\n");
sb.Append(" StateProvince: ").Append(StateProvince).Append("\n");
sb.Append(" AddressLine2: ").Append(AddressLine2).Append("\n");
sb.Append(" AddressLine3: ").Append(AddressLine3).Append("\n");
sb.Append(" AddressResidentialIndicator: ").Append(AddressResidentialIndicator).Append("\n");
sb.Append(" CompanyName: ").Append(CompanyName).Append("\n");
sb.Append(" CountryCode: ").Append(CountryCode).Append("\n");
sb.Append(" Email: ").Append(Email).Append("\n");
sb.Append(" Phone: ").Append(Phone).Append("\n");
#pragma warning restore CS0612 // Type or member is obsolete
sb.Append("}\n");
return sb.ToString();
Expand Down
7 changes: 7 additions & 0 deletions ShipEngineSDK/Model/AdvancedShipmentOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ public partial class AdvancedShipmentOptions
[JsonPropertyName("windsor_framework_details"), JsonPropertyOrder(27)]
public AdvancedShipmentOptionsWindsorFrameworkDetails? WindsorFrameworkDetails { get; set; }

/// <summary>
/// Gets or Sets additional properties
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; } = new Dictionary<string, object>();


/// <summary>
/// Returns the string presentation of the object
Expand Down Expand Up @@ -261,6 +267,7 @@ public override string ToString()
sb.Append(" ThirdPartyConsignee: ").Append(ThirdPartyConsignee).Append("\n");
sb.Append(" UseUpsGroundFreightPricing: ").Append(UseUpsGroundFreightPricing).Append("\n");
sb.Append(" WindsorFrameworkDetails: ").Append(WindsorFrameworkDetails).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
#pragma warning restore CS0612 // Type or member is obsolete
sb.Append("}\n");
return sb.ToString();
Expand Down
26 changes: 13 additions & 13 deletions ShipEngineSDK/Model/CalculateRatesRequestBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public CalculateRatesRequestBody(ShipmentIdRequest actualInstance) : base("oneOf

/// <summary>
/// Initializes a new instance of the <see cref="CalculateRatesRequestBody" /> class
/// with the <see cref="ShipmentRequest" /> class
/// with the <see cref="RateShipmentRequest" /> class
/// </summary>
/// <param name="actualInstance">An instance of ShipmentRequest.</param>
public CalculateRatesRequestBody(ShipmentRequest actualInstance) : base("oneOf")
/// <param name="actualInstance">An instance of RateShipmentRequest.</param>
public CalculateRatesRequestBody(RateShipmentRequest actualInstance) : base("oneOf")
{
this.IsNullable = false;
_actualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
Expand All @@ -77,13 +77,13 @@ public override Object ActualInstance
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(ShipmentRequest))
else if (value.GetType() == typeof(RateShipmentRequest))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: ShipmentIdRequest, ShipmentRequest");
throw new ArgumentException("Invalid instance found. Must be the following types: ShipmentIdRequest, RateShipmentRequest");
}
}
}
Expand All @@ -99,13 +99,13 @@ public ShipmentIdRequest GetShipmentIdRequest()
}

/// <summary>
/// Get the actual instance of `ShipmentRequest`. If the actual instance is not `ShipmentRequest`,
/// Get the actual instance of `RateShipmentRequest`. If the actual instance is not `RateShipmentRequest`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of ShipmentRequest</returns>
public ShipmentRequest GetShipmentRequest()
/// <returns>An instance of RateShipmentRequest</returns>
public RateShipmentRequest GetRateShipmentRequest()
{
return (ShipmentRequest)this.ActualInstance;
return (RateShipmentRequest)this.ActualInstance;
}

/// <summary>
Expand Down Expand Up @@ -138,7 +138,7 @@ public override string ToJson()
/// </summary>
public class CalculateRatesRequestBodyJsonConverter : JsonConverter<CalculateRatesRequestBody>
{
private static readonly HashSet<Type> OneOfTypes = [typeof(ShipmentIdRequest), typeof(ShipmentRequest)];
private static readonly HashSet<Type> OneOfTypes = [typeof(ShipmentIdRequest), typeof(RateShipmentRequest)];
private static readonly HashSet<string> MandatoryFields = ["Shipment", "ShipmentId"];
private static readonly JsonSerializerOptions DeserializingOptions = new(AbstractOpenAPISchema.SerializerSettings)
{
Expand Down Expand Up @@ -236,18 +236,18 @@ public override void Write(Utf8JsonWriter writer, CalculateRatesRequestBody valu

try
{
newCalculateRatesRequestBody = new CalculateRatesRequestBody(jsonDoc.Deserialize<ShipmentRequest>(DeserializingOptions)!)
newCalculateRatesRequestBody = new CalculateRatesRequestBody(jsonDoc.Deserialize<RateShipmentRequest>(DeserializingOptions)!)
{
RateOptions = rateOptions,
};

matchedTypes.Add("ShipmentRequest");
matchedTypes.Add("RateShipmentRequest");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine("Failed to deserialize `{0}` into ShipmentRequest: {1}", jsonDoc, exception);
System.Diagnostics.Debug.WriteLine("Failed to deserialize `{0}` into RateShipmentRequest: {1}", jsonDoc, exception);
}

if (match == 0)
Expand Down
Loading

0 comments on commit e4146a5

Please sign in to comment.