Skip to content

Commit

Permalink
feat: Updated OpenAPI spec
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 1, 2024
1 parent f24bc3f commit 6378ce5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ public sealed partial class AnthropicApi
/// Authorize using ApiKey authentication.
/// </summary>
/// <param name="apiKey"></param>
public void AuthorizeUsingApiKey(
public void AuthorizeUsingApiKeyInHeader(
string apiKey)
{
apiKey = apiKey ?? throw new global::System.ArgumentNullException(nameof(apiKey));

_httpClient.DefaultRequestHeaders.Add("x-api-key", apiKey);
_authorization = new global::Anthropic.EndPointAuthorization
{
Name = "x-api-key",
Value = apiKey,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ namespace Anthropic
{
public sealed partial class AnthropicApi
{
/// <inheritdoc cref="AnthropicApi(global::System.Net.Http.HttpClient?, global::System.Uri?)"/>
/// <inheritdoc cref="AnthropicApi(global::System.Net.Http.HttpClient?, global::System.Uri?, global::Anthropic.EndPointAuthorization?)"/>
public AnthropicApi(
string apiKey,
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null) : this(httpClient, baseUri)
global::System.Uri? baseUri = null,
global::Anthropic.EndPointAuthorization? authorization = null) : this(httpClient, baseUri, authorization)
{
Authorizing(_httpClient, ref apiKey);

AuthorizeUsingApiKey(apiKey);
AuthorizeUsingApiKeyInHeader(apiKey);

Authorized(_httpClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ partial void ProcessCreateMessageResponseContent(
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));

if (_authorization != null)
{{
httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: _authorization.Name,
parameter: _authorization.Value);
}}
var __httpRequestContentBody = global::System.Text.Json.JsonSerializer.Serialize(request, request.GetType(), JsonSerializerContext);
var __httpRequestContent = new global::System.Net.Http.StringContent(
content: __httpRequestContentBody,
Expand Down
8 changes: 6 additions & 2 deletions src/libs/Anthropic/Generated/Anthropic.AnthropicApi.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed partial class AnthropicApi : global::Anthropic.IAnthropicApi, glob
public const string BaseUrl = "https://api.anthropic.com/v1";

private readonly global::System.Net.Http.HttpClient _httpClient;
private global::Anthropic.EndPointAuthorization? _authorization;

/// <summary>
///
Expand All @@ -29,13 +30,16 @@ public sealed partial class AnthropicApi : global::Anthropic.IAnthropicApi, glob
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
/// <param name="httpClient"></param>
/// <param name="baseUri"></param>
/// <param name="baseUri"></param>
/// <param name="authorization"></param>
public AnthropicApi(
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null)
global::System.Uri? baseUri = null,
global::Anthropic.EndPointAuthorization? authorization = null)
{
_httpClient = httpClient ?? new global::System.Net.Http.HttpClient();
_httpClient.BaseAddress ??= baseUri ?? new global::System.Uri(BaseUrl);
_authorization = authorization;

Initialized(_httpClient);
}
Expand Down
16 changes: 16 additions & 0 deletions src/libs/Anthropic/Generated/Anthropic.PathBuilder.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,20 @@ public PathBuilder AddOptionalParameter<T>(
/// <returns>The constructed URL.</returns>
public override string ToString() => _stringBuilder.ToString();
}

/// <summary>
///
/// </summary>
public class EndPointAuthorization
{
/// <summary>
///
/// </summary>
public string Name { get; set; } = string.Empty;

/// <summary>
///
/// </summary>
public string Value { get; set; } = string.Empty;
}
}

0 comments on commit 6378ce5

Please sign in to comment.