Skip to content

Commit

Permalink
Merge pull request #806 from dmelendezhikrutech/feature
Browse files Browse the repository at this point in the history
Create CamelCaseAttribute attribute for class and properties
  • Loading branch information
abuzuhri authored Dec 16, 2024
2 parents 66715d4 + 4f7a2ca commit 61ff6f5
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Source/FikaAmazonAPI/Parameter/CamelCaseAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace FikaAmazonAPI.Parameter
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
public class CamelCaseAttribute : Attribute
{
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace FikaAmazonAPI.Parameter.FulFillmentInbound
public class ParameterGetLabels : ParameterBased
{
public string MarketplaceId { get; set; }

[CamelCase]
public string ShipmentId { get; set; }
public PageType PageType { get; set; }
public LabelType LabelType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterConfirmPackingOption : ParameterBased
{
public string InboundPlanId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListInboundPlanBase : PaginationParameter
{
public string InboundPlanId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListInboundPlans : PaginationParameter
{
public string PaginationToken { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListPackingGroupBoxes : PaginationParameter
{
{
public string InboundPlanId { get; set; }
public string PackingGroupId { get; set; }
public string PaginationToken { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListPackingGroupItems : PaginationParameter
{
{
public string InboundPlanId { get; set; }
public string PackingGroupId { get; set; }
public string PaginationToken { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListPrepDetails : ParameterBased
{
public string MarketplaceId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListShipmentBase : PaginationParameter
{
{
public string InboundPlanId { get; set; }
public string ShipmentId { get; set; }
public string PaginationToken { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterListTransportationOptions : PaginationParameter
{
public string PlacementOptionId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParameterUpdateItemComplianceDetails : ParameterBased
{
public string MarketplaceId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace FikaAmazonAPI.Parameter.FulFillmentInbound.v20240320
{
[CamelCase]
public class ParematerListItemComplianceDetails : ParameterBased
{
public ICollection<string> MSkus { get; set; }
Expand Down
9 changes: 7 additions & 2 deletions Source/FikaAmazonAPI/Parameter/ParameterBased.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

namespace FikaAmazonAPI.Search
{
Expand All @@ -21,6 +22,9 @@ public class ParameterBased

public virtual List<KeyValuePair<string, string>> getParameters()
{
// Check if the class is marked with the CamelCase attribute
var isClassCamelCase = Attribute.IsDefined(this.GetType(), typeof(CamelCaseAttribute));

List<KeyValuePair<string, string>> queryParameters = new List<KeyValuePair<string, string>>();
if (!string.IsNullOrEmpty(TestCase))
{
Expand Down Expand Up @@ -76,8 +80,9 @@ public virtual List<KeyValuePair<string, string>> getParameters()
output = JsonConvert.SerializeObject(value, settings);
}

// Convert to cammelCase to avoid issues with properties not being properly mapped
var propName = char.ToLowerInvariant(p.Name[0]) + p.Name.Substring(1);
// Check if property should be converted to cammel case
var isPropertyCamelCase = isClassCamelCase || Attribute.IsDefined(p, typeof(CamelCaseAttribute));
var propName = isPropertyCamelCase ? char.ToLowerInvariant(p.Name[0]) + p.Name.Substring(1) : p.Name;

queryParameters.Add(new KeyValuePair<string, string>(propName, output));
}
Expand Down

0 comments on commit 61ff6f5

Please sign in to comment.