Skip to content

Commit a9c4583

Browse files
committed
fix: Fixed incorrect serialization of query enum parameters.
1 parent 7fc13ce commit a9c4583

207 files changed

Lines changed: 213 additions & 206 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/libs/OpenApiGenerator.Core/Serialization/Form/ParameterSerializer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.OpenApi.Models;
22
using OpenApiGenerator.Core.Extensions;
33
using OpenApiGenerator.Core.Models;
4+
using OpenApiGenerator.Core.Serialization.Json;
45

56
namespace OpenApiGenerator.Core.Serialization.Form;
67

@@ -42,6 +43,12 @@ public static string SerializeQueryParameter(PropertyData parameter)
4243
return string.Empty;
4344
}
4445

46+
if (parameter.Type.IsEnum)
47+
{
48+
return parameter.Settings.JsonSerializerType == JsonSerializerType.SystemTextJson
49+
? $"{parameter.Id}={{(global::System.Uri.EscapeDataString({parameter.ArgumentName}{(parameter.IsRequired ? "" : "?")}.ToValueString() ?? string.Empty))}}"
50+
: $"{parameter.Id}={{(global::System.Uri.EscapeDataString({parameter.ArgumentName}{(parameter.IsRequired ? "" : "?")}.ToString() ?? string.Empty))}}";
51+
}
4552
if (parameter.Type.IsArray)
4653
{
4754
if (parameter.ParameterExplode == true)

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Ai21/NewtonsoftJson/_#G.LibraryManagementClient.V1LibraryManagement.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ partial void ProcessV1LibraryManagementResponseContent(
8181
};
8282
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
8383
method: global::System.Net.Http.HttpMethod.Get,
84-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/studio/v1/library/files?name={name}&path={path}&status={statusValue}&{string.Join("&", label?.Select(static x => $"label={x}") ?? global::System.Array.Empty<string>())}&limit={limit}&offset={offset}", global::System.UriKind.RelativeOrAbsolute));
84+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/studio/v1/library/files?name={name}&path={path}&status={(global::System.Uri.EscapeDataString(statusValue?.ToString() ?? string.Empty))}&{string.Join("&", label?.Select(static x => $"label={x}") ?? global::System.Array.Empty<string>())}&limit={limit}&offset={offset}", global::System.UriKind.RelativeOrAbsolute));
8585

8686
PrepareRequest(
8787
client: _httpClient,

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Ai21/SystemTextJson/_#G.LibraryManagementClient.V1LibraryManagement.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ partial void ProcessV1LibraryManagementResponseContent(
7272

7373
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
7474
method: global::System.Net.Http.HttpMethod.Get,
75-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/studio/v1/library/files?name={name}&path={path}&status={status}&{string.Join("&", label?.Select(static x => $"label={x}") ?? global::System.Array.Empty<string>())}&limit={limit}&offset={offset}", global::System.UriKind.RelativeOrAbsolute));
75+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/studio/v1/library/files?name={name}&path={path}&status={(global::System.Uri.EscapeDataString(status?.ToValueString() ?? string.Empty))}&{string.Join("&", label?.Select(static x => $"label={x}") ?? global::System.Array.Empty<string>())}&limit={limit}&offset={offset}", global::System.UriKind.RelativeOrAbsolute));
7676

7777
PrepareRequest(
7878
client: _httpClient,

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Cohere/NewtonsoftJson/_#G.DatasetsClient.CreateDataset.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ partial void ProcessCreateDatasetResponseContent(
103103
};
104104
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
105105
method: global::System.Net.Http.HttpMethod.Post,
106-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?name={name}&type={typeValue}&keep_original_file={keepOriginalFile}&skip_malformed_input={skipMalformedInput}&{string.Join("&", keepFields?.Select(static x => $"keepFields={x}") ?? global::System.Array.Empty<string>())}&{string.Join("&", optionalFields?.Select(static x => $"optionalFields={x}") ?? global::System.Array.Empty<string>())}&text_separator={textSeparator}&csv_delimiter={csvDelimiter}", global::System.UriKind.RelativeOrAbsolute));
106+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?name={name}&type={(global::System.Uri.EscapeDataString(typeValue.ToString() ?? string.Empty))}&keep_original_file={keepOriginalFile}&skip_malformed_input={skipMalformedInput}&{string.Join("&", keepFields?.Select(static x => $"keepFields={x}") ?? global::System.Array.Empty<string>())}&{string.Join("&", optionalFields?.Select(static x => $"optionalFields={x}") ?? global::System.Array.Empty<string>())}&text_separator={textSeparator}&csv_delimiter={csvDelimiter}", global::System.UriKind.RelativeOrAbsolute));
107107
using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent();
108108
__httpRequestContent.Add(
109109
content: new global::System.Net.Http.StringContent($"{name}"),

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Cohere/NewtonsoftJson/_#G.DatasetsClient.ListDatasets.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ partial void ProcessListDatasetsResponseContent(
8383
};
8484
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
8585
method: global::System.Net.Http.HttpMethod.Get,
86-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?datasetType={datasetType}&before={before:yyyy-MM-ddTHH:mm:ssZ}&after={after:yyyy-MM-ddTHH:mm:ssZ}&limit={limit}&offset={offset}&validationStatus={validationStatusValue}", global::System.UriKind.RelativeOrAbsolute));
86+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?datasetType={datasetType}&before={before:yyyy-MM-ddTHH:mm:ssZ}&after={after:yyyy-MM-ddTHH:mm:ssZ}&limit={limit}&offset={offset}&validationStatus={(global::System.Uri.EscapeDataString(validationStatusValue?.ToString() ?? string.Empty))}", global::System.UriKind.RelativeOrAbsolute));
8787

8888
PrepareRequest(
8989
client: _httpClient,

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Cohere/NewtonsoftJson/_#G.ModelsClient.ListModels.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ partial void ProcessListModelsResponseContent(
6969
};
7070
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
7171
method: global::System.Net.Http.HttpMethod.Get,
72-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/models?page_size={pageSize}&page_token={pageToken}&endpoint={endpointValue}&default_only={defaultOnly}", global::System.UriKind.RelativeOrAbsolute));
72+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/models?page_size={pageSize}&page_token={pageToken}&endpoint={(global::System.Uri.EscapeDataString(endpointValue?.ToString() ?? string.Empty))}&default_only={defaultOnly}", global::System.UriKind.RelativeOrAbsolute));
7373

7474
PrepareRequest(
7575
client: _httpClient,

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Cohere/SystemTextJson/_#G.DatasetsClient.CreateDataset.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ partial void ProcessCreateDatasetResponseContent(
9191

9292
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
9393
method: global::System.Net.Http.HttpMethod.Post,
94-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?name={name}&type={type}&keep_original_file={keepOriginalFile}&skip_malformed_input={skipMalformedInput}&{string.Join("&", keepFields?.Select(static x => $"keepFields={x}") ?? global::System.Array.Empty<string>())}&{string.Join("&", optionalFields?.Select(static x => $"optionalFields={x}") ?? global::System.Array.Empty<string>())}&text_separator={textSeparator}&csv_delimiter={csvDelimiter}", global::System.UriKind.RelativeOrAbsolute));
94+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?name={name}&type={(global::System.Uri.EscapeDataString(type.ToValueString() ?? string.Empty))}&keep_original_file={keepOriginalFile}&skip_malformed_input={skipMalformedInput}&{string.Join("&", keepFields?.Select(static x => $"keepFields={x}") ?? global::System.Array.Empty<string>())}&{string.Join("&", optionalFields?.Select(static x => $"optionalFields={x}") ?? global::System.Array.Empty<string>())}&text_separator={textSeparator}&csv_delimiter={csvDelimiter}", global::System.UriKind.RelativeOrAbsolute));
9595
using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent();
9696
__httpRequestContent.Add(
9797
content: new global::System.Net.Http.StringContent($"{name}"),

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Cohere/SystemTextJson/_#G.DatasetsClient.ListDatasets.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ partial void ProcessListDatasetsResponseContent(
7373

7474
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
7575
method: global::System.Net.Http.HttpMethod.Get,
76-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?datasetType={datasetType}&before={before:yyyy-MM-ddTHH:mm:ssZ}&after={after:yyyy-MM-ddTHH:mm:ssZ}&limit={limit}&offset={offset}&validationStatus={validationStatus}", global::System.UriKind.RelativeOrAbsolute));
76+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/datasets?datasetType={datasetType}&before={before:yyyy-MM-ddTHH:mm:ssZ}&after={after:yyyy-MM-ddTHH:mm:ssZ}&limit={limit}&offset={offset}&validationStatus={(global::System.Uri.EscapeDataString(validationStatus?.ToValueString() ?? string.Empty))}", global::System.UriKind.RelativeOrAbsolute));
7777

7878
PrepareRequest(
7979
client: _httpClient,

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/Cohere/SystemTextJson/_#G.ModelsClient.ListModels.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ partial void ProcessListModelsResponseContent(
5858

5959
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
6060
method: global::System.Net.Http.HttpMethod.Get,
61-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/models?page_size={pageSize}&page_token={pageToken}&endpoint={endpoint}&default_only={defaultOnly}", global::System.UriKind.RelativeOrAbsolute));
61+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1/models?page_size={pageSize}&page_token={pageToken}&endpoint={(global::System.Uri.EscapeDataString(endpoint?.ToValueString() ?? string.Empty))}&default_only={defaultOnly}", global::System.UriKind.RelativeOrAbsolute));
6262

6363
PrepareRequest(
6464
client: _httpClient,

src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ActionsClient.ActionsGetActionsCacheList.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ partial void ProcessActionsGetActionsCacheListResponseContent(
9898
};
9999
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
100100
method: global::System.Net.Http.HttpMethod.Get,
101-
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/repos/{owner}/{repo}/actions/caches?per_page={perPage}&page={page}&ref={@ref}&key={key}&sort={sortValue}&direction={directionValue}", global::System.UriKind.RelativeOrAbsolute));
101+
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/repos/{owner}/{repo}/actions/caches?per_page={perPage}&page={page}&ref={@ref}&key={key}&sort={(global::System.Uri.EscapeDataString(sortValue?.ToString() ?? string.Empty))}&direction={(global::System.Uri.EscapeDataString(directionValue?.ToString() ?? string.Empty))}", global::System.UriKind.RelativeOrAbsolute));
102102

103103
PrepareRequest(
104104
client: _httpClient,

0 commit comments

Comments
 (0)