Skip to content

Commit

Permalink
c#, improvement: Add header suppliers to RawClient constructor para…
Browse files Browse the repository at this point in the history
…meters (#4119)
  • Loading branch information
dcb6 committed Jul 25, 2024
1 parent 3aaeba9 commit 4c0a159
Show file tree
Hide file tree
Showing 293 changed files with 1,221 additions and 121 deletions.
11 changes: 10 additions & 1 deletion generators/csharp/codegen/src/asIs/RawClient.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace <%= namespace%>;
/// <summary>
/// Utility class for making raw HTTP requests to the API.
/// </summary>
public class RawClient(Dictionary<string, string> headers, ClientOptions clientOptions)
public class RawClient(
Dictionary<string, string> headers,
Dictionary<string, Func<string>> headerSuppliers,
ClientOptions clientOptions
)
{
/// <summary>
/// The http client used to make requests.
Expand All @@ -33,6 +37,11 @@ public async Task<ApiResponse> MakeRequestAsync(BaseApiRequest request)
{
httpRequest.Headers.Add(header.Key, header.Value);
}
// Add global headers to the request from supplier
foreach (var header in headerSuppliers)
{
httpRequest.Headers.Add(header.Key, header.Value.Invoke());
}
// Add request headers to the request
foreach (var header in request.Headers)
{
Expand Down
16 changes: 11 additions & 5 deletions generators/csharp/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.2 - 2024-07-25]

- Improvement: Add header suppliers to `RawClient` constructor parameters.

## [0.2.1 - 2024-07-25]
- Fix: MultURL environment classes now compile, previously there was a fix that broke compilation.

- Fix: MultURL environment classes now compile, previously there was a fix that broke compilation.

## [0.2.0 - 2024-07-25]

- Break: The `Environments.cs` class is now renamed to be `{OrgName}Environment`. For example, if your
org name was Imdb then the environment class would be `ImdbEnvironment`.
org name was Imdb then the environment class would be `ImdbEnvironment`.

- Feature: If the SDK has endpoints that each hit different URLs then the following class is generated.

- Feature: If the SDK has endpoints that each hit different URLs then the following class is generated.
```csharp
public record AWSEnvironment
{
Expand All @@ -22,13 +28,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
S3 = "https://s3.awsamazon.com",
EC2 = "https://ec2.awsamazon.com"
};

public static AWSEnvironment Staging = new AWSEnvironment()
{
S3 = "https://staging.s3.awsamazon.com",
EC2 = "https://stagng.ec2.awsamazon.com"
};

public required string S3 { get; init; }
public required string EC2 { get; init; }
}
Expand Down
15 changes: 15 additions & 0 deletions generators/csharp/sdk/src/root-client/RootClientGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ export class RootClientGenerator extends FileGenerator<CSharpFile, SdkCustomConf
valueType: csharp.Types.string(),
entries: headerEntries
});

const headerSupplierDictionary = csharp.dictionary({
keyType: csharp.Types.string(),
valueType: csharp.Types.reference(
csharp.classReference({
name: "Func",
namespace: "System",
generics: [csharp.Types.string()]
})
),
entries: []
});
return {
access: "public",
parameters,
Expand All @@ -205,6 +217,9 @@ export class RootClientGenerator extends FileGenerator<CSharpFile, SdkCustomConf
csharp.codeblock((writer) => {
writer.writeNode(headerDictionary);
}),
csharp.codeblock((writer) => {
writer.writeNode(headerSupplierDictionary);
}),
csharp.codeblock("clientOptions ?? new ClientOptions()")
]
})
Expand Down
9 changes: 8 additions & 1 deletion seed/csharp-sdk/alias/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file removed seed/csharp-sdk/alias/snippet.json
Empty file.
11 changes: 10 additions & 1 deletion seed/csharp-sdk/alias/src/SeedAlias/Core/RawClient.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions seed/csharp-sdk/alias/src/SeedAlias/SeedAliasClient.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion seed/csharp-sdk/api-wide-base-path/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion seed/csharp-sdk/audiences/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
11 changes: 10 additions & 1 deletion seed/csharp-sdk/audiences/src/SeedAudiences/Core/RawClient.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion seed/csharp-sdk/auth-environment-variables/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion seed/csharp-sdk/basic-auth-environment-variables/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Loading

0 comments on commit 4c0a159

Please sign in to comment.