From 6a88b1e5d07d7fb094bd09350d643f6ad1cdc0fe Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sat, 24 Aug 2024 22:51:18 +0400 Subject: [PATCH] feat: To generated apiKey constructor. --- src/helpers/FixOpenApiSpec/Program.cs | 23 +++++++++++++++++++ .../DeepInfraApi.AdditionalConstructors.cs | 18 --------------- ...ra.DeepInfraApi.Authorizations.Bearer.g.cs | 22 ++++++++++++++++++ ...nfra.DeepInfraApi.Constructors.Bearer.g.cs | 17 ++++++++++++++ .../Generated/DeepInfra.DeepInfraApi.g.cs | 2 +- src/libs/DeepInfra/generate.sh | 3 ++- src/libs/DeepInfra/openapi.yaml | 9 +++++++- 7 files changed, 73 insertions(+), 21 deletions(-) delete mode 100644 src/libs/DeepInfra/DeepInfraApi.AdditionalConstructors.cs create mode 100644 src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Authorizations.Bearer.g.cs create mode 100644 src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Constructors.Bearer.g.cs diff --git a/src/helpers/FixOpenApiSpec/Program.cs b/src/helpers/FixOpenApiSpec/Program.cs index 5d1d635..157351a 100644 --- a/src/helpers/FixOpenApiSpec/Program.cs +++ b/src/helpers/FixOpenApiSpec/Program.cs @@ -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]; @@ -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(), +}); + openApiDocument.Components.Schemas["TimeInterval"]!.Properties["to"].Format = "int64"; if (long.TryParse( (openApiDocument.Components.Schemas["TimeInterval"]!.Properties["to"].Default as OpenApiString)?.Value ?? string.Empty, diff --git a/src/libs/DeepInfra/DeepInfraApi.AdditionalConstructors.cs b/src/libs/DeepInfra/DeepInfraApi.AdditionalConstructors.cs deleted file mode 100644 index 64e18b0..0000000 --- a/src/libs/DeepInfra/DeepInfraApi.AdditionalConstructors.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Net.Http; - -namespace DeepInfra; - -public partial class DeepInfraApi -{ - /// - public DeepInfraApi( - string apiKey, - HttpClient? httpClient = null, - Uri? baseUri = null) : this(httpClient, baseUri ?? new Uri("https://api.deepinfra.com/v1/")) - { - //AuthorizeUsingBearer(apiKey); - _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( - scheme: "Bearer", - parameter: apiKey); - } -} \ No newline at end of file diff --git a/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Authorizations.Bearer.g.cs b/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Authorizations.Bearer.g.cs new file mode 100644 index 0000000..f476787 --- /dev/null +++ b/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Authorizations.Bearer.g.cs @@ -0,0 +1,22 @@ + +#nullable enable + +namespace DeepInfra +{ + public sealed partial class DeepInfraApi + { + /// + /// Authorize using bearer authentication. + /// + /// + 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); + } + } +} \ No newline at end of file diff --git a/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Constructors.Bearer.g.cs b/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Constructors.Bearer.g.cs new file mode 100644 index 0000000..df17c33 --- /dev/null +++ b/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.Constructors.Bearer.g.cs @@ -0,0 +1,17 @@ + +#nullable enable + +namespace DeepInfra +{ + public sealed partial class DeepInfraApi + { + /// + public DeepInfraApi( + string apiKey, + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null) : this(httpClient, baseUri) + { + AuthorizeUsingBearer(apiKey); + } + } +} \ No newline at end of file diff --git a/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.g.cs b/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.g.cs index 88aae71..3b5eca4 100644 --- a/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.g.cs +++ b/src/libs/DeepInfra/Generated/DeepInfra.DeepInfraApi.g.cs @@ -12,7 +12,7 @@ public sealed partial class DeepInfraApi : global::System.IDisposable /// /// /// - public const string BaseUrl = ""; + public const string BaseUrl = "https://api.deepinfra.com/v1/"; private readonly global::System.Net.Http.HttpClient _httpClient; diff --git a/src/libs/DeepInfra/generate.sh b/src/libs/DeepInfra/generate.sh index d4b8e08..cb47605 100755 --- a/src/libs/DeepInfra/generate.sh +++ b/src/libs/DeepInfra/generate.sh @@ -10,4 +10,5 @@ oag generate openapi.yaml \ --namespace DeepInfra \ --clientClassName DeepInfraApi \ --targetFramework net8.0 \ - --output Generated \ No newline at end of file + --output Generated \ + --exclude-deprecated-operations \ No newline at end of file diff --git a/src/libs/DeepInfra/openapi.yaml b/src/libs/DeepInfra/openapi.yaml index 3c11976..740b635 100644 --- a/src/libs/DeepInfra/openapi.yaml +++ b/src/libs/DeepInfra/openapi.yaml @@ -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: @@ -4096,4 +4098,9 @@ components: securitySchemes: HTTPBearer: type: http - scheme: bearer \ No newline at end of file + scheme: bearer + Bearer: + type: http + scheme: bearer +security: + - Bearer: [ ] \ No newline at end of file