Skip to content

Commit 67e0f99

Browse files
authored
Merge pull request #118 from CyberSource/feature/handing-links-field-in-api
Feature/handing links field in api
2 parents 2168d93 + 76897a8 commit 67e0f99

File tree

6 files changed

+156
-93
lines changed

6 files changed

+156
-93
lines changed

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/Client/ApiClient.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,19 @@ public object Deserialize(RestResponse response, Type type) // CHANGED
711711
// at this point, it must be a model (json)
712712
try
713713
{
714-
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
714+
if (type == typeof(Model.PblPaymentLinksAllGet200Response))
715+
{
716+
JsonSerializerSettings customSerializerSettings = new JsonSerializerSettings
717+
{
718+
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
719+
ContractResolver = new Utilities.CustomContractResolver()
720+
};
721+
return JsonConvert.DeserializeObject(response.Content, type, customSerializerSettings);
722+
}
723+
else
724+
{
725+
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
726+
}
715727
}
716728
catch (Exception e)
717729
{

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/Model/PblPaymentLinksAllGet200Response.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,4 @@ public override int GetHashCode()
175175
}
176176

177177
}
178+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Newtonsoft.Json.Serialization;
2+
3+
namespace CyberSource.Utilities
4+
{
5+
public class CustomContractResolver : DefaultContractResolver
6+
{
7+
protected override string ResolvePropertyName(string propertyName)
8+
{
9+
if (propertyName == "Links")
10+
{
11+
return "_links";
12+
}
13+
/*if (propertyName == "SdkLinks")
14+
{
15+
return "links";
16+
}*/
17+
return base.ResolvePropertyName(propertyName);
18+
}
19+
20+
}
21+
}

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,19 @@ namespace {{packageName}}.Client
765765
// at this point, it must be a model (json)
766766
try
767767
{
768-
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
768+
if (type == typeof(Model.PblPaymentLinksAllGet200Response))
769+
{
770+
JsonSerializerSettings customSerializerSettings = new JsonSerializerSettings
771+
{
772+
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
773+
ContractResolver = new Utilities.CustomContractResolver()
774+
};
775+
return JsonConvert.DeserializeObject(response.Content, type, customSerializerSettings);
776+
}
777+
else
778+
{
779+
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
780+
}
769781
}
770782
catch (Exception e)
771783
{

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/generator/cybersource_dotnet_sdk_gen.bat

Lines changed: 10 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ rd /s /q ..\docs
77
rd /s /q ..\..\cybersource-rest-client-netstandard.Test\Api
88
rd /s /q ..\..\cybersource-rest-client-netstandard.Test\Model
99

10+
setlocal enabledelayedexpansion
11+
python replaceFieldNamesForPaths.py -i cybersource-rest-spec.json -o cybersource-rest-spec-netstandard.json > replaceFieldLogs.log
12+
del replaceFieldLogs.log
13+
endlocal
14+
1015
java -jar swagger-codegen-cli-2.4.38.jar generate -t cybersource-csharp-template -i cybersource-rest-spec-netstandard.json -l csharp -o ..\..\..\ -c cybersource-csharp-config.json
1116

1217
powershell -Command "Get-ChildItem '..\..\..\src\CyberSource\Api\*.cs' -Recurse | ForEach-Object { (Get-Content $_).Replace('Method.POST','Method.Post').Replace('Method.GET','Method.Get').Replace('Method.PATCH','Method.Patch').Replace('Method.DELETE','Method.Delete').Replace('Method.PUT','Method.Put') | Set-Content $_ }"
@@ -26,111 +31,25 @@ FOR /f "tokens=* delims=\n" %%a in ('type "excludelist.txt"') do (
2631
SET excludeList=!excludeList! %%a
2732
)
2833

29-
REM Need to shorten filenames
30-
31-
powershell Rename-Item ..\..\..\src\CyberSource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.cs Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedMerchantInitiatedTransaction.cs
32-
33-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransactionTests.cs Tmsv2customersEmbeddedMerchantInitiatedTransactionTests.cs
34-
35-
powershell Rename-Item ..\..\..\docs\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.md Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedMerchantInitiatedTransaction.md
36-
37-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorTests.cs Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedAuthorizationOptionsInitiatorTests.cs
38-
39-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsTests.cs Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedAuthorizationOptionsTests.cs
40-
41-
powershell Rename-Item ..\..\..\src\CyberSource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptions.cs Tmsv2customersEmbeddedAuthorizationOptions.cs
42-
43-
powershell Rename-Item ..\..\..\docs\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptions.md Tmsv2customersEmbeddedAuthorizationOptions.md
44-
4534
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\RiskV1AddressVerificationsPost201ResponseAddressVerificationInformationStandardAddressAddress1Tests.cs RiskV1AddressVerificationsPost201ResponseStandardAddressAddress1Tests.cs
4635

4736
powershell Rename-Item ..\..\..\src\CyberSource\Model\RiskV1AddressVerificationsPost201ResponseAddressVerificationInformationStandardAddressAddress1.cs RiskV1AddressVerificationsPost201ResponseAddress1.cs
4837

4938
powershell Rename-Item ..\..\..\docs\RiskV1AddressVerificationsPost201ResponseAddressVerificationInformationStandardAddressAddress1.md RiskV1AddressVerificationsPost201ResponseAddress1.md
5039

51-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierLinksPaymentInstrumentsTests.cs Tmsv2customersEmbeddedPaymentInstrumentsTests.cs
52-
53-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationTests.cs Tmsv2customersEmbeddedDefaultProcessingInformationTests.cs
54-
55-
powershell Rename-Item ..\..\..\src\CyberSource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierLinksPaymentInstruments.cs Tmsv2customersEmbeddedLinksPaymentInstruments.cs
56-
5740
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransactionTests.cs Ptsv2paymentsMerchantInitiatedTransactionTests.cs
5841

59-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PtsV2PaymentsPost201ResponseConsumerAuthenticationInformationStrongAuthenticationIssuerInformationTests.cs PtsV2PaymentsPost201ResponseStrongAuthenticationIssuerInformationTests.cs
60-
61-
@REM powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\RiskV1ExportComplianceInquiriesPost201ResponseExportComplianceInformationWatchListMatchesTests.cs RiskV1ExportComplianceWatchListMatchesTests.cs
62-
63-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierTokenizedCardCardTests.cs Tmsv2customersTokenizedCardCardTests.cs
64-
65-
powershell Rename-Item ..\..\..\src\CyberSource\Model\PtsV2PaymentsPost201ResponseConsumerAuthenticationInformationStrongAuthenticationIssuerInformation.cs PtsV2PaymentsPost201ResponseStrongAuthenticationIssuerInformation.cs
66-
67-
powershell Rename-Item ..\..\..\docs\PtsV2PaymentsPost201ResponseConsumerAuthenticationInformationStrongAuthenticationIssuerInformation.md PtsV2PaymentsPost201ResponseStrongAuthenticationIssuerInformation.md
68-
69-
powershell Rename-Item ..\..\..\src\CyberSource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiator.cs Tmsv2customersEmbeddedAuthorizationOptionsInitiator.cs
70-
71-
powershell Rename-Item ..\..\..\docs\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiator.md Tmsv2customersEmbeddedAuthorizationOptionsInitiator.md
72-
73-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsCardProcessingConfigurationInformationConfigurationsCommonMerchantDescriptorInformationTests.cs PaymentProductsCardProcessingMerchantDescriptorInformationTests.cs
74-
75-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsCardProcessingConfigurationInformationConfigurationsFeaturesCardNotPresentPayoutsCurrenciesTests.cs PaymentProductsCardProcessingPayoutsCurrenciesTests.cs
76-
77-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsECheckConfigurationInformationConfigurationsFeaturesAccountValidationServiceInternalOnlyTests.cs PaymentProductsECheckServiceInternalOnlyTests.cs
78-
79-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsECheckConfigurationInformationConfigurationsFeaturesAccountValidationServiceProcessorsTests.cs PaymentProductsECheckProcessorsTests.cs
80-
81-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsPayerAuthenticationConfigurationInformationConfigurationsCardTypesVerifiedByVisaCurrenciesTests.cs PaymentProductsPayerAuthVerifiedByVisaCurrenciesTests.cs
82-
83-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsSecureAcceptanceConfigurationInformationConfigurationsNotificationsCustomerNotificationsTests.cs PaymentProductsSecureAcceptanceCustomerNotificationsTests.cs
84-
85-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsSecureAcceptanceConfigurationInformationConfigurationsNotificationsMerchantNotificationsTests.cs PaymentProductsSecureAcceptanceMerchantNotificationsTests.cs
86-
87-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationBasicInformationTests.cs PaymentProductsVirtualTerminalPaymentInformationBasicInformationTests.cs
88-
89-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationMerchantDefinedDataFieldsTests.cs PaymentProductsVirtualTerminalMerchantDefinedDataFieldsTests.cs
90-
91-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationPaymentInformationTests.cs PaymentProductsVirtualTerminalPaymentInformationTests.cs
92-
93-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationTests.cs PaymentProductsVirtualTerminalCardNotPresentGlobalPaymentInformationTests.cs
94-
95-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationEmailReceiptTests.cs PaymentProductsVirtualTerminalReceiptInformationEmailReceiptTests.cs
96-
97-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationHeaderTests.cs PaymentProductsVirtualTerminalReceiptInformationHeaderTests.cs
98-
99-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationOrderInformationTests.cs PaymentProductsVirtualTerminalReceiptInformationOrderInformationTests.cs
100-
101-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\RiskProductsDecisionManagerConfigurationInformationConfigurationsThirdpartyProviderAccurintCredentialsTests.cs RiskProductsDecisionManagerThirdpartyAccurintCredentialsTests.cs
102-
103-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\RiskProductsDecisionManagerConfigurationInformationConfigurationsThirdpartyProviderCredilinkCredentialsTests.cs RiskProductsDecisionManagerThirdpartyCredilinkCredentialsTests.cs
104-
105-
powershell Rename-Item ..\..\..\src\CyberSource.Test\Model\RiskProductsDecisionManagerConfigurationInformationConfigurationsThirdpartyProviderSignifydCredentialsTests.cs RiskProductsDecisionManagerThirdpartySignifydCredentialsTests.cs
106-
107-
powershell Rename-Item ..\..\..\src\CyberSource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationBasicInformation.cs PaymentProductsVirtualTerminalPaymentInformationBasicInformation.cs
108-
109-
powershell Rename-Item ..\..\..\src\CyberSource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationMerchantDefinedDataFields.cs PaymentProductsVirtualTerminalMerchantDefinedDataFields.cs
110-
111-
powershell Rename-Item ..\..\..\src\CyberSource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationPaymentInformation.cs PaymentProductsVirtualTerminalPaymentInformation.cs
112-
113-
powershell Rename-Item ..\..\..\src\CyberSource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationEmailReceipt.cs PaymentProductsVirtualTerminalReceiptInformationEmailReceipt.cs
114-
115-
powershell Rename-Item ..\..\..\src\CyberSource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationOrderInformation.cs PaymentProductsVirtualTerminalReceiptInformationOrderInformation.cs
116-
117-
powershell Rename-Item ..\..\..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationBasicInformation.md PaymentProductsVirtualTerminalPaymentInformationBasicInformation.md
118-
119-
powershell Rename-Item ..\..\..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationMerchantDefinedDataFields.md PaymentProductsVirtualTerminalMerchantDefinedDataFields.md
120-
121-
powershell Rename-Item ..\..\..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationPaymentInformation.md PaymentProductsVirtualTerminalPaymentInformation.md
122-
123-
powershell Rename-Item ..\..\..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationEmailReceipt.md PaymentProductsVirtualTerminalReceiptInformationEmailReceipt.md
124-
125-
powershell Rename-Item ..\..\..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationOrderInformation.md PaymentProductsVirtualTerminalReceiptInformationOrderInformation.md
126-
127-
12842
robocopy ..\..\..\src\cybersource ..\ /S /XF %excludeList%
12943

13044
robocopy ..\..\..\src\cybersource.test ..\..\cybersource-rest-client-netstandard.Test /S /XF %excludeList%
13145

13246
robocopy ..\..\..\docs ..\docs /S
13347

48+
@REM replace sdkLinks fieldName to links for supporting links field name in request/response body
49+
echo "starting of replacing the links keyword in PblPaymentLinksAllGet200Response.cs model"
50+
powershell -Command "Set-Content ..\Model\PblPaymentLinksAllGet200Response.cs ((Get-Content ..\Model\PblPaymentLinksAllGet200Response.cs -Raw) -replace '\[DataMember\(Name=\"sdkLinks\", EmitDefaultValue=false\)\]', '[DataMember(Name=\"links\", EmitDefaultValue=false)]')"
51+
echo "completed the task of replacing the links keyword in PblPaymentLinksAllGet200Response.cs model"
52+
13453
del ..\..\..\CyberSource.sln
13554
del ..\..\..\*ignore
13655
git checkout ..\..\..\.gitignore
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import json
2+
import os
3+
import argparse
4+
5+
6+
def traverse_and_replace(obj, path, new_field_name):
7+
if len(path) == 1:
8+
if path[0] in obj:
9+
keys = list(obj.keys())
10+
index = keys.index(path[0])
11+
obj[new_field_name] = obj.pop(path[0])
12+
keys = list(obj.keys()) # Update keys after replacing the key
13+
reordered = {k: obj[k] for k in keys[:index] + [new_field_name] + keys[index:]}
14+
obj.clear()
15+
obj.update(reordered)
16+
else:
17+
if path[0] in obj and isinstance(obj[path[0]], dict):
18+
traverse_and_replace(obj[path[0]], path[1:], new_field_name)
19+
elif path[0] in obj and isinstance(obj[path[0]], list):
20+
if len(path) > 1 and isinstance(path[1], int) and path[1] < len(obj[path[0]]):
21+
traverse_and_replace(obj[path[0]][path[1]], path[2:], new_field_name)
22+
23+
def replace_field_names(input_file_path, output_file_path, changes):
24+
"""
25+
Replace field names in the JSON file based on the given changes.
26+
27+
:param input_file: Path to the input JSON file.
28+
:param output_file: Path to the output JSON file.
29+
:param changes: List of dictionaries containing paths and new field names.
30+
"""
31+
32+
with open(input_file_path, 'r', encoding='utf-8') as file:
33+
data = json.load(file)
34+
35+
for change in changes:
36+
key_path = change['path']
37+
new_field_name = change['new_name']
38+
traverse_and_replace(data, key_path, new_field_name)
39+
40+
with open(output_file_path, 'w', encoding='utf-8') as file:
41+
json.dump(data, file, indent=4)
42+
43+
def convert_input_paths_to_changes(input_paths):
44+
"""
45+
Convert input paths to a list of changes with parsed paths and new field names.
46+
47+
:param input_paths: List of dictionaries containing string paths and new field names.
48+
:return: List of dictionaries with parsed paths and new field names.
49+
"""
50+
changes = []
51+
for item in input_paths:
52+
path_str = item["path"]
53+
path_parts = []
54+
for part in path_str.split('.'):
55+
if '[' in part and ']' in part:
56+
field, index = part.split('[')
57+
path_parts.append(field)
58+
path_parts.append(int(index.strip(']')))
59+
else:
60+
path_parts.append(part)
61+
changes.append({
62+
"path": path_parts,
63+
"new_name": item["new_field_name"]
64+
})
65+
return changes
66+
67+
68+
if __name__ == "__main__":
69+
parser = argparse.ArgumentParser(description="Replace field names in a JSON file.")
70+
parser.add_argument("-i", "--input", help="Path to the input JSON file.")
71+
parser.add_argument("-o", "--output", help="Path to the output JSON file.")
72+
args = parser.parse_args()
73+
74+
input_file = args.input if args.input else "cybersource-rest-spec.json"
75+
76+
output_file = args.output if args.output else "cybersource-rest-spec-output.json"
77+
78+
79+
inputPaths =[
80+
{
81+
"path": "paths./ipl/v2/payment-links.get.responses.200.schema.properties.links",
82+
"new_field_name": "sdkLinks"
83+
}
84+
85+
# example of how to add more paths
86+
# ,{
87+
# "path": "paths./pts/v2/payments.post.parameters[0].schema.properties.clientReferenceInformation.properties.code",
88+
# "new_field_name": "sdkCode"
89+
# }
90+
]
91+
92+
# Convert inputPaths to changes
93+
changes = convert_input_paths_to_changes(inputPaths)
94+
95+
script_dir = os.path.dirname(os.path.abspath(__file__))
96+
input_file_path = os.path.join(script_dir, input_file)
97+
output_file_path = os.path.join(script_dir, output_file)
98+
replace_field_names(input_file_path, output_file_path, changes)

0 commit comments

Comments
 (0)