amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
618 stars 741 forks source link

[BUG] [SP-API] C# MerchantFulfillmentAPI Swagger Generated Cannot Set Address Variables #2592

Closed dathat closed 1 year ago

dathat commented 1 year ago

I'm submitting a...

[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

SP-API Name and Version or Report/Feed Type

The project code generated with swagger for the C# MerchantFulfillmentAPI (using merchantFulfillmentV0.json) does not allow creating addresses to make API requests. The required Address class variables (AddressName, AddressLine1, AddressLine2, etc) do not seem to have methods to initialize them with strings (or anything else) in the generated model files.

Expected Behavior

To construct an address for ShipmentRequestDetails I would expect to do something like: Address shipFromAddress = new SellingPartnerAPI.MerchantFulfillmentAPI.Model.Address(); shipFromAddress.Name = "My Name"; shipFromAddress.AddressLine1 = "123 Fake St."; ...

Current Behavior

Each variable (Name, AddressLine1, etc) being assigned has an error "Cannot implicitly convert type 'string' to 'SellingPartnerAPI.MerchantFulfillmentAPI.Model.{variable name}'"

image

Context/Screenshots

There does not appear to be any way to construct or set the value of the field other than empty. Adding three big blocks of code here, sorry for the mess.

1. MerchantFulfillmentAPI.Model.AddressName (to show no string or other input constructor for individual field) ``` /* * Selling Partner API for Merchant Fulfillment * * The Selling Partner API for Merchant Fulfillment helps you build applications that let sellers purchase shipping for non-Prime and Prime orders using Amazon’s Buy Shipping Services. * * OpenAPI spec version: v0 * * Generated by: https://github.com/swagger-api/swagger-codegen.git */ using System; using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System.ComponentModel.DataAnnotations; using SwaggerDateConverter = SellingPartnerAPI.MerchantFulfillmentAPI.Client.SwaggerDateConverter; namespace SellingPartnerAPI.MerchantFulfillmentAPI.Model { /// /// The name of the addressee, or business name. /// [DataContract] public partial class AddressName : IEquatable, IValidatableObject { /// /// Initializes a new instance of the class. /// [JsonConstructorAttribute] public AddressName() { } /// /// Returns the string presentation of the object /// /// String presentation of the object public override string ToString() { var sb = new StringBuilder(); sb.Append("class AddressName {\n"); sb.Append("}\n"); return sb.ToString(); } /// /// Returns the JSON string presentation of the object /// /// JSON string presentation of the object public virtual string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); } /// /// Returns true if objects are equal /// /// Object to be compared /// Boolean public override bool Equals(object input) { return this.Equals(input as AddressName); } /// /// Returns true if AddressName instances are equal /// /// Instance of AddressName to be compared /// Boolean public bool Equals(AddressName input) { if (input == null) return false; return false; } /// /// Gets the hash code /// /// Hash code public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; return hashCode; } } /// /// To validate all properties of the instance /// /// Validation context /// Validation Result IEnumerable IValidatableObject.Validate(ValidationContext validationContext) { yield break; } } } ```
2. MerchantFulfillmentAPI.Model.Address (to show no string constructor for class) ``` /* * Selling Partner API for Merchant Fulfillment * * The Selling Partner API for Merchant Fulfillment helps you build applications that let sellers purchase shipping for non-Prime and Prime orders using Amazon’s Buy Shipping Services. * * OpenAPI spec version: v0 * * Generated by: https://github.com/swagger-api/swagger-codegen.git */ using System; using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System.ComponentModel.DataAnnotations; using SwaggerDateConverter = SellingPartnerAPI.MerchantFulfillmentAPI.Client.SwaggerDateConverter; namespace SellingPartnerAPI.MerchantFulfillmentAPI.Model { /// /// The postal address information. /// [DataContract] public partial class Address : IEquatable
, IValidatableObject { /// /// Initializes a new instance of the class. /// [JsonConstructorAttribute] protected Address() { } /// /// Initializes a new instance of the class. /// /// name (required). /// addressLine1 (required). /// addressLine2. /// addressLine3. /// districtOrCounty. /// email (required). /// city (required). /// stateOrProvinceCode. /// postalCode (required). /// countryCode (required). /// phone (required). public Address(AddressName name = default(AddressName), AddressLine1 addressLine1 = default(AddressLine1), AddressLine2 addressLine2 = default(AddressLine2), AddressLine3 addressLine3 = default(AddressLine3), DistrictOrCounty districtOrCounty = default(DistrictOrCounty), EmailAddress email = default(EmailAddress), City city = default(City), StateOrProvinceCode stateOrProvinceCode = default(StateOrProvinceCode), PostalCode postalCode = default(PostalCode), CountryCode countryCode = default(CountryCode), PhoneNumber phone = default(PhoneNumber)) { // to ensure "name" is required (not null) if (name == null) { throw new InvalidDataException("name is a required property for Address and cannot be null"); } else { this.Name = name; } // to ensure "addressLine1" is required (not null) if (addressLine1 == null) { throw new InvalidDataException("addressLine1 is a required property for Address and cannot be null"); } else { this.AddressLine1 = addressLine1; } // to ensure "email" is required (not null) if (email == null) { throw new InvalidDataException("email is a required property for Address and cannot be null"); } else { this.Email = email; } // to ensure "city" is required (not null) if (city == null) { throw new InvalidDataException("city is a required property for Address and cannot be null"); } else { this.City = city; } // to ensure "postalCode" is required (not null) if (postalCode == null) { throw new InvalidDataException("postalCode is a required property for Address and cannot be null"); } else { this.PostalCode = postalCode; } // to ensure "countryCode" is required (not null) if (countryCode == null) { throw new InvalidDataException("countryCode is a required property for Address and cannot be null"); } else { this.CountryCode = countryCode; } // to ensure "phone" is required (not null) if (phone == null) { throw new InvalidDataException("phone is a required property for Address and cannot be null"); } else { this.Phone = phone; } this.AddressLine2 = addressLine2; this.AddressLine3 = addressLine3; this.DistrictOrCounty = districtOrCounty; this.StateOrProvinceCode = stateOrProvinceCode; } /// /// Gets or Sets Name /// [DataMember(Name="Name", EmitDefaultValue=false)] public AddressName Name { get; set; } /// /// Gets or Sets AddressLine1 /// [DataMember(Name="AddressLine1", EmitDefaultValue=false)] public AddressLine1 AddressLine1 { get; set; } /// /// Gets or Sets AddressLine2 /// [DataMember(Name="AddressLine2", EmitDefaultValue=false)] public AddressLine2 AddressLine2 { get; set; } /// /// Gets or Sets AddressLine3 /// [DataMember(Name="AddressLine3", EmitDefaultValue=false)] public AddressLine3 AddressLine3 { get; set; } /// /// Gets or Sets DistrictOrCounty /// [DataMember(Name="DistrictOrCounty", EmitDefaultValue=false)] public DistrictOrCounty DistrictOrCounty { get; set; } /// /// Gets or Sets Email /// [DataMember(Name="Email", EmitDefaultValue=false)] public EmailAddress Email { get; set; } /// /// Gets or Sets City /// [DataMember(Name="City", EmitDefaultValue=false)] public City City { get; set; } /// /// Gets or Sets StateOrProvinceCode /// [DataMember(Name="StateOrProvinceCode", EmitDefaultValue=false)] public StateOrProvinceCode StateOrProvinceCode { get; set; } /// /// Gets or Sets PostalCode /// [DataMember(Name="PostalCode", EmitDefaultValue=false)] public PostalCode PostalCode { get; set; } /// /// Gets or Sets CountryCode /// [DataMember(Name="CountryCode", EmitDefaultValue=false)] public CountryCode CountryCode { get; set; } /// /// Gets or Sets Phone /// [DataMember(Name="Phone", EmitDefaultValue=false)] public PhoneNumber Phone { get; set; } /// /// Returns the string presentation of the object /// /// String presentation of the object public override string ToString() { var sb = new StringBuilder(); sb.Append("class Address {\n"); sb.Append(" Name: ").Append(Name).Append("\n"); sb.Append(" AddressLine1: ").Append(AddressLine1).Append("\n"); sb.Append(" AddressLine2: ").Append(AddressLine2).Append("\n"); sb.Append(" AddressLine3: ").Append(AddressLine3).Append("\n"); sb.Append(" DistrictOrCounty: ").Append(DistrictOrCounty).Append("\n"); sb.Append(" Email: ").Append(Email).Append("\n"); sb.Append(" City: ").Append(City).Append("\n"); sb.Append(" StateOrProvinceCode: ").Append(StateOrProvinceCode).Append("\n"); sb.Append(" PostalCode: ").Append(PostalCode).Append("\n"); sb.Append(" CountryCode: ").Append(CountryCode).Append("\n"); sb.Append(" Phone: ").Append(Phone).Append("\n"); sb.Append("}\n"); return sb.ToString(); } /// /// Returns the JSON string presentation of the object /// /// JSON string presentation of the object public virtual string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); } /// /// Returns true if objects are equal /// /// Object to be compared /// Boolean public override bool Equals(object input) { return this.Equals(input as Address); } /// /// Returns true if Address instances are equal /// /// Instance of Address to be compared /// Boolean public bool Equals(Address input) { if (input == null) return false; return ( this.Name == input.Name || (this.Name != null && this.Name.Equals(input.Name)) ) && ( this.AddressLine1 == input.AddressLine1 || (this.AddressLine1 != null && this.AddressLine1.Equals(input.AddressLine1)) ) && ( this.AddressLine2 == input.AddressLine2 || (this.AddressLine2 != null && this.AddressLine2.Equals(input.AddressLine2)) ) && ( this.AddressLine3 == input.AddressLine3 || (this.AddressLine3 != null && this.AddressLine3.Equals(input.AddressLine3)) ) && ( this.DistrictOrCounty == input.DistrictOrCounty || (this.DistrictOrCounty != null && this.DistrictOrCounty.Equals(input.DistrictOrCounty)) ) && ( this.Email == input.Email || (this.Email != null && this.Email.Equals(input.Email)) ) && ( this.City == input.City || (this.City != null && this.City.Equals(input.City)) ) && ( this.StateOrProvinceCode == input.StateOrProvinceCode || (this.StateOrProvinceCode != null && this.StateOrProvinceCode.Equals(input.StateOrProvinceCode)) ) && ( this.PostalCode == input.PostalCode || (this.PostalCode != null && this.PostalCode.Equals(input.PostalCode)) ) && ( this.CountryCode == input.CountryCode || (this.CountryCode != null && this.CountryCode.Equals(input.CountryCode)) ) && ( this.Phone == input.Phone || (this.Phone != null && this.Phone.Equals(input.Phone)) ); } /// /// Gets the hash code /// /// Hash code public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (this.Name != null) hashCode = hashCode * 59 + this.Name.GetHashCode(); if (this.AddressLine1 != null) hashCode = hashCode * 59 + this.AddressLine1.GetHashCode(); if (this.AddressLine2 != null) hashCode = hashCode * 59 + this.AddressLine2.GetHashCode(); if (this.AddressLine3 != null) hashCode = hashCode * 59 + this.AddressLine3.GetHashCode(); if (this.DistrictOrCounty != null) hashCode = hashCode * 59 + this.DistrictOrCounty.GetHashCode(); if (this.Email != null) hashCode = hashCode * 59 + this.Email.GetHashCode(); if (this.City != null) hashCode = hashCode * 59 + this.City.GetHashCode(); if (this.StateOrProvinceCode != null) hashCode = hashCode * 59 + this.StateOrProvinceCode.GetHashCode(); if (this.PostalCode != null) hashCode = hashCode * 59 + this.PostalCode.GetHashCode(); if (this.CountryCode != null) hashCode = hashCode * 59 + this.CountryCode.GetHashCode(); if (this.Phone != null) hashCode = hashCode * 59 + this.Phone.GetHashCode(); return hashCode; } } /// /// To validate all properties of the instance /// /// Validation context /// Validation Result IEnumerable IValidatableObject.Validate(ValidationContext validationContext) { yield break; } } } ```
3. OrdersAPI.Model.Model.Address (to compare how this one allows for string constructors of each variable): ``` /* * Selling Partner API for Orders * * The Selling Partner API for Orders helps you programmatically retrieve order information. These APIs let you develop fast, flexible, custom applications in areas like order synchronization, order research, and demand-based decision support tools. * * OpenAPI spec version: v0 * * Generated by: https://github.com/swagger-api/swagger-codegen.git */ using System; using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System.ComponentModel.DataAnnotations; using SwaggerDateConverter = SellingPartnerAPI.OrdersAPI.Client.SwaggerDateConverter; namespace SellingPartnerAPI.OrdersAPI.Model { /// /// The shipping address for the order. /// [DataContract] public partial class Address : IEquatable
, IValidatableObject { /// /// The address type of the shipping address. /// /// The address type of the shipping address. [JsonConverter(typeof(StringEnumConverter))] public enum AddressTypeEnum { /// /// Enum Residential for value: Residential /// [EnumMember(Value = "Residential")] Residential = 1, /// /// Enum Commercial for value: Commercial /// [EnumMember(Value = "Commercial")] Commercial = 2 } /// /// The address type of the shipping address. /// /// The address type of the shipping address. [DataMember(Name="AddressType", EmitDefaultValue=false)] public AddressTypeEnum? AddressType { get; set; } /// /// Initializes a new instance of the class. /// [JsonConstructorAttribute] protected Address() { } /// /// Initializes a new instance of the class. /// /// The name. (required). /// The street address.. /// Additional street address information, if required.. /// Additional street address information, if required.. /// The city . /// The county.. /// The district.. /// The state or region.. /// The municipality.. /// The postal code.. /// The country code. A two-character country code, in ISO 3166-1 alpha-2 format.. /// The phone number. Not returned for Fulfillment by Amazon (FBA) orders.. /// The address type of the shipping address.. public Address(string name = default(string), string addressLine1 = default(string), string addressLine2 = default(string), string addressLine3 = default(string), string city = default(string), string county = default(string), string district = default(string), string stateOrRegion = default(string), string municipality = default(string), string postalCode = default(string), string countryCode = default(string), string phone = default(string), AddressTypeEnum? addressType = default(AddressTypeEnum?)) { // to ensure "name" is required (not null) if (name == null) { throw new InvalidDataException("name is a required property for Address and cannot be null"); } else { this.Name = name; } this.AddressLine1 = addressLine1; this.AddressLine2 = addressLine2; this.AddressLine3 = addressLine3; this.City = city; this.County = county; this.District = district; this.StateOrRegion = stateOrRegion; this.Municipality = municipality; this.PostalCode = postalCode; this.CountryCode = countryCode; this.Phone = phone; this.AddressType = addressType; } /// /// The name. /// /// The name. [DataMember(Name="Name", EmitDefaultValue=false)] public string Name { get; set; } /// /// The street address. /// /// The street address. [DataMember(Name="AddressLine1", EmitDefaultValue=false)] public string AddressLine1 { get; set; } /// /// Additional street address information, if required. /// /// Additional street address information, if required. [DataMember(Name="AddressLine2", EmitDefaultValue=false)] public string AddressLine2 { get; set; } /// /// Additional street address information, if required. /// /// Additional street address information, if required. [DataMember(Name="AddressLine3", EmitDefaultValue=false)] public string AddressLine3 { get; set; } /// /// The city /// /// The city [DataMember(Name="City", EmitDefaultValue=false)] public string City { get; set; } /// /// The county. /// /// The county. [DataMember(Name="County", EmitDefaultValue=false)] public string County { get; set; } /// /// The district. /// /// The district. [DataMember(Name="District", EmitDefaultValue=false)] public string District { get; set; } /// /// The state or region. /// /// The state or region. [DataMember(Name="StateOrRegion", EmitDefaultValue=false)] public string StateOrRegion { get; set; } /// /// The municipality. /// /// The municipality. [DataMember(Name="Municipality", EmitDefaultValue=false)] public string Municipality { get; set; } /// /// The postal code. /// /// The postal code. [DataMember(Name="PostalCode", EmitDefaultValue=false)] public string PostalCode { get; set; } /// /// The country code. A two-character country code, in ISO 3166-1 alpha-2 format. /// /// The country code. A two-character country code, in ISO 3166-1 alpha-2 format. [DataMember(Name="CountryCode", EmitDefaultValue=false)] public string CountryCode { get; set; } /// /// The phone number. Not returned for Fulfillment by Amazon (FBA) orders. /// /// The phone number. Not returned for Fulfillment by Amazon (FBA) orders. [DataMember(Name="Phone", EmitDefaultValue=false)] public string Phone { get; set; } /// /// Returns the string presentation of the object /// /// String presentation of the object public override string ToString() { var sb = new StringBuilder(); sb.Append("class Address {\n"); sb.Append(" Name: ").Append(Name).Append("\n"); sb.Append(" AddressLine1: ").Append(AddressLine1).Append("\n"); sb.Append(" AddressLine2: ").Append(AddressLine2).Append("\n"); sb.Append(" AddressLine3: ").Append(AddressLine3).Append("\n"); sb.Append(" City: ").Append(City).Append("\n"); sb.Append(" County: ").Append(County).Append("\n"); sb.Append(" District: ").Append(District).Append("\n"); sb.Append(" StateOrRegion: ").Append(StateOrRegion).Append("\n"); sb.Append(" Municipality: ").Append(Municipality).Append("\n"); sb.Append(" PostalCode: ").Append(PostalCode).Append("\n"); sb.Append(" CountryCode: ").Append(CountryCode).Append("\n"); sb.Append(" Phone: ").Append(Phone).Append("\n"); sb.Append(" AddressType: ").Append(AddressType).Append("\n"); sb.Append("}\n"); return sb.ToString(); } /// /// Returns the JSON string presentation of the object /// /// JSON string presentation of the object public virtual string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); } /// /// Returns true if objects are equal /// /// Object to be compared /// Boolean public override bool Equals(object input) { return this.Equals(input as Address); } /// /// Returns true if Address instances are equal /// /// Instance of Address to be compared /// Boolean public bool Equals(Address input) { if (input == null) return false; return ( this.Name == input.Name || (this.Name != null && this.Name.Equals(input.Name)) ) && ( this.AddressLine1 == input.AddressLine1 || (this.AddressLine1 != null && this.AddressLine1.Equals(input.AddressLine1)) ) && ( this.AddressLine2 == input.AddressLine2 || (this.AddressLine2 != null && this.AddressLine2.Equals(input.AddressLine2)) ) && ( this.AddressLine3 == input.AddressLine3 || (this.AddressLine3 != null && this.AddressLine3.Equals(input.AddressLine3)) ) && ( this.City == input.City || (this.City != null && this.City.Equals(input.City)) ) && ( this.County == input.County || (this.County != null && this.County.Equals(input.County)) ) && ( this.District == input.District || (this.District != null && this.District.Equals(input.District)) ) && ( this.StateOrRegion == input.StateOrRegion || (this.StateOrRegion != null && this.StateOrRegion.Equals(input.StateOrRegion)) ) && ( this.Municipality == input.Municipality || (this.Municipality != null && this.Municipality.Equals(input.Municipality)) ) && ( this.PostalCode == input.PostalCode || (this.PostalCode != null && this.PostalCode.Equals(input.PostalCode)) ) && ( this.CountryCode == input.CountryCode || (this.CountryCode != null && this.CountryCode.Equals(input.CountryCode)) ) && ( this.Phone == input.Phone || (this.Phone != null && this.Phone.Equals(input.Phone)) ) && ( this.AddressType == input.AddressType || (this.AddressType != null && this.AddressType.Equals(input.AddressType)) ); } /// /// Gets the hash code /// /// Hash code public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (this.Name != null) hashCode = hashCode * 59 + this.Name.GetHashCode(); if (this.AddressLine1 != null) hashCode = hashCode * 59 + this.AddressLine1.GetHashCode(); if (this.AddressLine2 != null) hashCode = hashCode * 59 + this.AddressLine2.GetHashCode(); if (this.AddressLine3 != null) hashCode = hashCode * 59 + this.AddressLine3.GetHashCode(); if (this.City != null) hashCode = hashCode * 59 + this.City.GetHashCode(); if (this.County != null) hashCode = hashCode * 59 + this.County.GetHashCode(); if (this.District != null) hashCode = hashCode * 59 + this.District.GetHashCode(); if (this.StateOrRegion != null) hashCode = hashCode * 59 + this.StateOrRegion.GetHashCode(); if (this.Municipality != null) hashCode = hashCode * 59 + this.Municipality.GetHashCode(); if (this.PostalCode != null) hashCode = hashCode * 59 + this.PostalCode.GetHashCode(); if (this.CountryCode != null) hashCode = hashCode * 59 + this.CountryCode.GetHashCode(); if (this.Phone != null) hashCode = hashCode * 59 + this.Phone.GetHashCode(); if (this.AddressType != null) hashCode = hashCode * 59 + this.AddressType.GetHashCode(); return hashCode; } } /// /// To validate all properties of the instance /// /// Validation context /// Validation Result IEnumerable IValidatableObject.Validate(ValidationContext validationContext) { yield break; } } } ```
dathat commented 1 year ago

I wasted way more time than necessary on this. For anyone stumbling across this issue, updating to swagger-codegen-2.4.32 fixes it.

The SP-API migration guide (https://developer-docs.amazon.com/sp-api/docs/generating-a-java-sdk-with-lwa-token-exchange-and-authentication) links to the older swagger-codegen-2.4.13 version, which caused this issue (and possibly others I've been slowly struggling through).