Skip to content

Commit 90b4668

Browse files
committed
Updated "Integrating with OpenAPI Generator API Client Libraries" with the new interface
1 parent 7c5f290 commit 90b4668

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

README.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -578,58 +578,59 @@ Generators currently supported:
578578
Client libraries can be generated using the following command:
579579

580580
```shell
581-
java -jar openapi-generator-cli.jar generate -i openapi-spec.yaml -g csharp-netcore -c config.json -o out
581+
openapi-generator-cli generate -i openapi-spec.yaml -g csharp-netcore -c config.json -o out
582582
```
583583
config.json:
584584

585585
```json
586-
{ "targetFramework": "netstandard2.0" }
586+
{ "targetFramework": "netstandard2.1" }
587587
```
588588

589589
See also:
590-
* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
590+
* [OpenAPI Generator CLI Installation](https://openapi-generator.tech/docs/installation)
591591
* [Config Options for csharp-netcore](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/csharp-netcore.md)
592592

593-
##### Usage of the `RestSharpFieldLevelEncryptionInterceptor`
593+
##### Usage of the `RestSharpEncryptionInterceptor`
594594

595-
`RestSharpFieldLevelEncryptionInterceptor` is located in the [`ClientEncryption.RestSharpV2`](https://www.nuget.org/packages/Mastercard.Developer.ClientEncryption.RestSharpV2/) package.
595+
`RestSharpEncryptionInterceptor` is located in the [`ClientEncryption.RestSharpV2`](https://www.nuget.org/packages/Mastercard.Developer.ClientEncryption.RestSharpV2/) package.
596596

597597
##### Usage
598598

599-
1. Create a new file (for instance, `ApiClientWithEncryption.cs`) extending the definition of the generated `ApiClient` class:
599+
1. Create a new file (for instance, `MastercardApiClient.cs`) extending the definition of the generated `ApiClient` class:
600600

601601
```cs
602602
partial class ApiClient
603603
{
604-
public RestSharpFieldLevelEncryptionInterceptor EncryptionInterceptor { private get; set; }
605-
606-
public ApiClient(RSA signingKey, string basePath, string consumerKey)
604+
private readonly Uri _basePath;
605+
private readonly RestSharpSigner _signer;
606+
private readonly RestSharpEncryptionInterceptor _encryptionInterceptor;
607+
608+
/// <summary>
609+
/// Construct an ApiClient which will automatically:
610+
/// - Sign requests
611+
/// - Encrypt/decrypt requests and responses
612+
/// </summary>
613+
public ApiClient(RSA signingKey, string basePath, string consumerKey, EncryptionConfig config)
607614
{
608-
this._baseUrl = basePath;
609-
this.BasePath = new Uri(basePath);
610-
this.Signer = new RestSharpSigner(consumerKey, signingKey);
615+
_baseUrl = basePath;
616+
_basePath = new Uri(basePath);
617+
_signer = new RestSharpSigner(consumerKey, signingKey);
618+
_encryptionInterceptor = RestSharpEncryptionInterceptor.From(config);
611619
}
612-
613-
partial void InterceptRequest(IRestRequest request) {
614-
EncryptionInterceptor.InterceptRequest(request);
615-
Signer.Sign(this.BasePath, request);
620+
621+
partial void InterceptRequest(IRestRequest request)
622+
{
623+
_encryptionInterceptor.InterceptRequest(request);
624+
_signer.Sign(_basePath, request);
616625
}
617626
}
618627
```
619628

620629
2. Configure your `ApiClient` instance the following way:
621630

622631
```cs
623-
var serviceApi = new ServiceApi();
624-
var client = new ApiClient(SigningKey, BasePath, ConsumerKey);
625-
626-
var fieldLevelEncryptionConfig = FieldLevelEncryptionConfigBuilder
627-
.AFieldLevelEncryptionConfig()
628-
//
629-
.Build();
630-
631-
client.EncryptionInterceptor = new RestSharpFieldLevelEncryptionInterceptor(fieldLevelEncryptionConfig)
632-
serviceApi.Client = client;
632+
var client = new ApiClient(SigningKey, BasePath, ConsumerKey, config);
633+
var serviceApi = new ServiceApi() { Client = client };
633634
//
634635
```
635636

@@ -651,15 +652,15 @@ config.json:
651652
⚠️ `v5.0` was used for `targetFramework` in OpenAPI Generator versions prior 5.0.0.
652653

653654
See also:
654-
* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
655+
* [OpenAPI Generator CLI Installation](https://openapi-generator.tech/docs/installation)
655656
* [Config Options for csharp](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/csharp.md)
656657

657658
##### Usage of the `RestSharpFieldLevelEncryptionInterceptor`
658659

659660
`RestSharpFieldLevelEncryptionInterceptor` is located in the [`ClientEncryption.RestSharp`](https://www.nuget.org/packages/Mastercard.Developer.ClientEncryption.RestSharp/) package.
660661

661662
##### Usage:
662-
1. Create a new file (for instance, `ApiClientWithEncryption.cs`) extending the definition of the generated `ApiClient` class:
663+
1. Create a new file (for instance, `MastercardApiClient.cs`) extending the definition of the generated `ApiClient` class:
663664

664665
```cs
665666
partial class ApiClient
@@ -676,11 +677,11 @@ partial class ApiClient
676677
var config = Configuration.Default;
677678
config.BasePath = "https://sandbox.api.mastercard.com";
678679
config.ApiClient.RestClient.Authenticator = new RestSharpOAuth1Authenticator(ConsumerKey, signingKey, new Uri(config.BasePath));
679-
var fieldLevelEncryptionConfig = FieldLevelEncryptionConfigBuilder
680+
var encryptionConfig = FieldLevelEncryptionConfigBuilder
680681
.AFieldLevelEncryptionConfig()
681682
//
682683
.Build();
683-
config.ApiClient.EncryptionInterceptor = new RestSharpFieldLevelEncryptionInterceptor(fieldLevelEncryptionConfig);
684+
config.ApiClient.EncryptionInterceptor = new RestSharpFieldLevelEncryptionInterceptor(encryptionConfig);
684685
var serviceApi = new ServiceApi(config);
685686
//
686687
```

0 commit comments

Comments
 (0)