Skip to content

Commit

Permalink
fix: Fixed issue with base64 requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 29, 2024
1 parent 8468a3d commit 0759d30
Show file tree
Hide file tree
Showing 799 changed files with 43,645 additions and 7 deletions.
1 change: 1 addition & 0 deletions OpenApiGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "specs", "specs", "{7E829AE4
specs\replicate.json = specs\replicate.json
specs\special-cases.yaml = specs\special-cases.yaml
specs\twitch.json = specs\twitch.json
specs\dedoose.json = specs\dedoose.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiGenerator.IntegrationTests.Cli", "src\tests\OpenApiGenerator.IntegrationTests.Cli\OpenApiGenerator.IntegrationTests.Cli.csproj", "{41F1B4D8-5F6F-40FB-A1C2-A5E6A4B62AA7}"
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</ItemGroup>

<PropertyGroup Label="Versioning">
<Version>0.11.5</Version>
<Version>0.11.6</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ public static bool IsEnum(

return schema.Type == "string" && schema.Enum.Any();
}

public static bool IsBase64(
this OpenApiSchema schema)
{
schema = schema ?? throw new ArgumentNullException(nameof(schema));

return schema.Type == "string" && schema.Format == "byte";
}

public static bool IsComponent(
this KeyValuePair<string, OpenApiSchema> schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace {endPoint.Namespace}
{string.Empty.ToXmlDocumentationSummary(level: 4)}
internal sealed partial class JsonSerializerContextConverters
{{
private readonly global::System.Type[] _types = new[]
private readonly global::System.Type[] _types = new global::System.Type[]
{{
{endPoint.Converters.Select(x => $@"
typeof({x}),
Expand Down
11 changes: 9 additions & 2 deletions src/libs/OpenApiGenerator.Core/Generation/Sources.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ public static string GenerateMethod(
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: {GetHttpMethod(endPoint.Settings.TargetFramework, endPoint.HttpMethod)},
requestUri: new global::System.Uri(_httpClient.BaseAddress?.GetLeftPart(global::System.UriPartial.Authority) + {endPoint.Path}, global::System.UriKind.RelativeOrAbsolute));
{(string.IsNullOrWhiteSpace(endPoint.RequestType.CSharpType) ? " " : $@"
{(string.IsNullOrWhiteSpace(endPoint.RequestType.CSharpType) || endPoint.RequestType.IsBase64 ? " " : $@"
var __json = {jsonSerializer.GenerateSerializeCall(endPoint.RequestType, endPoint.Settings.JsonSerializerContext)};
httpRequest.Content = new global::System.Net.Http.StringContent(
content: __json,
encoding: global::System.Text.Encoding.UTF8,
mediaType: ""application/json"");")}
{(!endPoint.RequestType.IsBase64 ? " " : $@"
var __base64 = global::System.Convert.ToBase64String(request);
httpRequest.Content = new global::System.Net.Http.StringContent(
content: __base64,
encoding: global::System.Text.Encoding.UTF8,
mediaType: ""application/octet-stream"");")}
using var response = await _httpClient.SendAsync(
request: httpRequest,
Expand Down Expand Up @@ -149,7 +155,8 @@ public static string GenerateExtensionMethod(
{
if (string.IsNullOrWhiteSpace(endPoint.RequestType.CSharpType) ||
endPoint.RequestType.IsArray ||
endPoint.RequestType.IsEnum)
endPoint.RequestType.IsEnum ||
endPoint.RequestType.IsBase64)
{
return " ";
}
Expand Down
8 changes: 6 additions & 2 deletions src/libs/OpenApiGenerator.Core/Models/TypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public readonly record struct TypeData(
string CSharpType,
bool IsArray,
bool IsEnum,
bool IsBase64,
int AnyOfCount,
int OneOfCount,
int AllOfCount,
Expand All @@ -23,6 +24,7 @@ public readonly record struct TypeData(
CSharpType: string.Empty,
IsArray: false,
IsEnum: false,
IsBase64: false,
AnyOfCount: 0,
OneOfCount: 0,
AllOfCount: 0,
Expand Down Expand Up @@ -81,6 +83,7 @@ public static TypeData FromSchema(
CSharpType: GetCSharpType(schema, settings, parents),
IsArray: schema.Value.Type == "array",
IsEnum: schema.Value.IsEnum(),
IsBase64: schema.Value.IsBase64(),
AnyOfCount: schema.Value.AnyOf?.Count ?? 0,
OneOfCount: schema.Value.OneOf?.Count ?? 0,
AllOfCount: schema.Value.AllOf?.Count ?? 0,
Expand Down Expand Up @@ -121,6 +124,7 @@ public static TypeData FromSchemaContext(SchemaContext context, IReadOnlyCollect
CSharpType: GetCSharpType(context, children),
IsArray: context.Schema.Type == "array",
IsEnum: context.Schema.IsEnum(),
IsBase64: context.Schema.IsBase64(),
AnyOfCount: context.Schema.AnyOf?.Count ?? 0,
OneOfCount: context.Schema.OneOf?.Count ?? 0,
AllOfCount: context.Schema.AllOf?.Count ?? 0,
Expand Down Expand Up @@ -163,7 +167,7 @@ public static string GetCSharpType(SchemaContext context, IReadOnlyCollection<Sc
("integer", "int64") => ("long", false),
("number", "float") => ("float", false),
("number", "double") => ("double", false),
("string", "byte") => ("byte", false),
("string", "byte") => ("byte[]", false),
("string", "binary") => ("byte[]", true),
("string", "date") => ("global::System.DateTime", false),
("string", "date-time") => ("global::System.DateTime", false),
Expand Down Expand Up @@ -223,7 +227,7 @@ public static string GetCSharpType(
("integer", "int64") => ("long", false),
("number", "float") => ("float", false),
("number", "double") => ("double", false),
("string", "byte") => ("byte", false),
("string", "byte") => ("byte[]", true),
("string", "binary") => ("byte[]", true),
("string", "date") => ("global::System.DateTime", false),
("string", "date-time") => ("global::System.DateTime", false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//HintName: G.AccountClient.AccountDisableRecurringPayment.g.cs

#nullable enable

namespace G
{
public partial class AccountClient
{
/// <summary>
/// DisableRecurringPayment.
/// </summary>
/// <param name="token"></param>
/// <param name="accountId"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<object> AccountDisableRecurringPaymentAsync(
string token,
string accountId,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.GetLeftPart(global::System.UriPartial.Authority) + $"/api/v1/account/disablerecurringpayment?accountId={accountId}", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

var __content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<object?>(__content, _jsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//HintName: G.AccountClient.AccountGetAccountBillingLogsForCurrentUser.g.cs

#nullable enable

namespace G
{
public partial class AccountClient
{
/// <summary>
/// GetAccountBillingLogsForCurrentUser.
/// </summary>
/// <param name="token"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::G.AccountWithLogs> AccountGetAccountBillingLogsForCurrentUserAsync(
string token,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.GetLeftPart(global::System.UriPartial.Authority) + "/api/v1/account/getaccountbillinglogsforcurrentuser", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

var __content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.AccountWithLogs?>(__content, _jsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//HintName: G.AccountClient.AccountGetAccountDetailsForCurrentUser.g.cs

#nullable enable

namespace G
{
public partial class AccountClient
{
/// <summary>
/// GetAccountDetailsForCurrentUser.
/// </summary>
/// <param name="token"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::G.AccountServiceGetAccountDetailsForCurrentUserControllerOutput> AccountGetAccountDetailsForCurrentUserAsync(
string token,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.GetLeftPart(global::System.UriPartial.Authority) + "/api/v1/account/getaccountdetailsforcurrentuser", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

var __content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.AccountServiceGetAccountDetailsForCurrentUserControllerOutput?>(__content, _jsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//HintName: G.AccountClient.AccountGetAccountForCurrentUser.g.cs

#nullable enable

namespace G
{
public partial class AccountClient
{
/// <summary>
/// GetAccountForCurrentUser.
/// </summary>
/// <param name="token"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<object> AccountGetAccountForCurrentUserAsync(
string token,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.GetLeftPart(global::System.UriPartial.Authority) + "/api/v1/account/getaccountforcurrentuser", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

var __content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<object?>(__content, _jsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//HintName: G.AccountClient.AccountGetAccountProjectInfoJobResponse.g.cs

#nullable enable

namespace G
{
public partial class AccountClient
{
/// <summary>
/// GetAccountProjectInfoJobResponse.
/// </summary>
/// <param name="token"></param>
/// <param name="jobId"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::System.Collections.Generic.IList<global::G.AccountProjectInfo>> AccountGetAccountProjectInfoJobResponseAsync(
string token,
string jobId,
global::System.Threading.CancellationToken cancellationToken = default)
{
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.GetLeftPart(global::System.UriPartial.Authority) + $"/api/v1/account/getaccountprojectinfojobresponse?jobId={jobId}", global::System.UriKind.RelativeOrAbsolute));

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

var __content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::System.Collections.Generic.IList<global::G.AccountProjectInfo>?>(__content, _jsonSerializerOptions) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Loading

0 comments on commit 0759d30

Please sign in to comment.