Skip to content

Commit

Permalink
feat: To generated apiKey constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 24, 2024
1 parent 83ccba1 commit 6a88b1e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 21 deletions.
23 changes: 23 additions & 0 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;

var path = args[0];
Expand All @@ -13,6 +14,28 @@

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);

openApiDocument.Servers.Add(new OpenApiServer
{
Url = "https://api.deepinfra.com/v1/",
});

openApiDocument.Components.SecuritySchemes.Add("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
Scheme = "bearer",
});
openApiDocument.SecurityRequirements.Add(new OpenApiSecurityRequirement
{
[new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Id = "Bearer",
Type = ReferenceType.SecurityScheme
}
}] = new List<string>(),
});

openApiDocument.Components.Schemas["TimeInterval"]!.Properties["to"].Format = "int64";
if (long.TryParse(
(openApiDocument.Components.Schemas["TimeInterval"]!.Properties["to"].Default as OpenApiString)?.Value ?? string.Empty,
Expand Down
18 changes: 0 additions & 18 deletions src/libs/DeepInfra/DeepInfraApi.AdditionalConstructors.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#nullable enable

namespace DeepInfra
{
public sealed partial class DeepInfraApi
{
/// <summary>
/// Authorize using bearer authentication.
/// </summary>
/// <param name="apiKey"></param>
public void AuthorizeUsingBearer(
string apiKey)
{
apiKey = apiKey ?? throw new global::System.ArgumentNullException(nameof(apiKey));

_httpClient.DefaultRequestHeaders.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: "Bearer",
parameter: apiKey);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#nullable enable

namespace DeepInfra
{
public sealed partial class DeepInfraApi
{
/// <inheritdoc cref="DeepInfraApi(global::System.Net.Http.HttpClient?, global::System.Uri?)"/>
public DeepInfraApi(
string apiKey,
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null) : this(httpClient, baseUri)
{
AuthorizeUsingBearer(apiKey);
}
}
}
2 changes: 1 addition & 1 deletion src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed partial class DeepInfraApi : global::System.IDisposable
/// <summary>
///
/// </summary>
public const string BaseUrl = "";
public const string BaseUrl = "https://api.deepinfra.com/v1/";

private readonly global::System.Net.Http.HttpClient _httpClient;

Expand Down
3 changes: 2 additions & 1 deletion src/libs/DeepInfra/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ oag generate openapi.yaml \
--namespace DeepInfra \
--clientClassName DeepInfraApi \
--targetFramework net8.0 \
--output Generated
--output Generated \
--exclude-deprecated-operations
9 changes: 8 additions & 1 deletion src/libs/DeepInfra/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ openapi: 3.0.1
info:
title: DeepApi
version: 0.1.0
servers:
- url: https://api.deepinfra.com/v1/
paths:
/cli/version:
get:
Expand Down Expand Up @@ -4096,4 +4098,9 @@ components:
securitySchemes:
HTTPBearer:
type: http
scheme: bearer
scheme: bearer
Bearer:
type: http
scheme: bearer
security:
- Bearer: [ ]

0 comments on commit 6a88b1e

Please sign in to comment.