From 5321208871df1058ab6018c49c5385c1a2fae470 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 12:42:06 -0400 Subject: [PATCH 01/10] (feature, csharp): Add support for allow-multiple query params --- .../codegen/src/asIs/RawClient.Template.cs | 19 ++++- generators/csharp/codegen/src/ast/index.ts | 1 + generators/csharp/codegen/src/csharp.ts | 3 +- .../request/WrappedEndpointRequest.ts | 72 ++++++++++++++----- .../WrappedRequestGenerator.ts | 6 +- .../enum/src/SeedEnum/Core/RawClient.cs | 20 +++++- .../SeedEnum/QueryParam/QueryParamClient.cs | 50 +++++++++---- .../SendEnumListAsQueryParamRequest.cs | 10 +-- 8 files changed, 141 insertions(+), 40 deletions(-) diff --git a/generators/csharp/codegen/src/asIs/RawClient.Template.cs b/generators/csharp/codegen/src/asIs/RawClient.Template.cs index 95077020656..2c8129b0212 100644 --- a/generators/csharp/codegen/src/asIs/RawClient.Template.cs +++ b/generators/csharp/codegen/src/asIs/RawClient.Template.cs @@ -121,7 +121,24 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/generators/csharp/codegen/src/ast/index.ts b/generators/csharp/codegen/src/ast/index.ts index 0f7e2de6217..0b7018663b7 100644 --- a/generators/csharp/codegen/src/ast/index.ts +++ b/generators/csharp/codegen/src/ast/index.ts @@ -3,6 +3,7 @@ export { Class } from "./Class"; export { ClassInstantiation } from "./ClassInstantiation"; export { ClassReference } from "./ClassReference"; export { CodeBlock } from "./CodeBlock"; +export { Writer } from "./core/Writer"; export { CoreClassReference } from "./CoreClassReference"; export * as dependencies from "./dependencies"; export { Dictionary } from "./Dictionary"; diff --git a/generators/csharp/codegen/src/csharp.ts b/generators/csharp/codegen/src/csharp.ts index ff69ee89dc6..52a3dd5f2be 100644 --- a/generators/csharp/codegen/src/csharp.ts +++ b/generators/csharp/codegen/src/csharp.ts @@ -102,6 +102,7 @@ export { MethodInvocation, MethodType, Parameter, - Type + Type, + Writer } from "./ast"; export { AstNode } from "./ast/core/AstNode"; diff --git a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts index 363594836da..dc9fb03f9e7 100644 --- a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts +++ b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts @@ -28,6 +28,7 @@ export declare namespace WrappedEndpointRequest { } } +const VALUES_LIST_VAR_NAME = "_values"; const QUERY_PARAMETER_BAG_NAME = "_query"; const HEADER_BAG_NAME = "_headers"; @@ -52,7 +53,7 @@ export class WrappedEndpointRequest extends EndpointRequest { const requiredQueryParameters: QueryParameter[] = []; const optionalQueryParameters: QueryParameter[] = []; for (const queryParameter of this.endpoint.queryParameters) { - if (this.context.isOptional(queryParameter.valueType)) { + if (!queryParameter.allowMultiple && this.context.isOptional(queryParameter.valueType)) { optionalQueryParameters.push(queryParameter); } else { requiredQueryParameters.push(queryParameter); @@ -66,29 +67,53 @@ export class WrappedEndpointRequest extends EndpointRequest { csharp.dictionary({ keyType: csharp.Type.string(), valueType: csharp.Type.object(), - entries: requiredQueryParameters.map((queryParameter) => { - return { - key: csharp.codeblock(`"${queryParameter.name.wireValue}"`), - value: this.stringify({ - reference: queryParameter.valueType, - name: queryParameter.name.name - }) - }; - }) + entries: [] }) ); + for (const query of requiredQueryParameters) { + this.writeQueryParameter(writer, query); + } for (const query of optionalQueryParameters) { const queryParameterReference = `${this.getParameterName()}.${query.name.name.pascalCase.safeName}`; + writer.writeLine(); writer.controlFlow("if", `${queryParameterReference} != null`); - writer.write(`${QUERY_PARAMETER_BAG_NAME}["${query.name.wireValue}"] = `); - writer.writeNodeStatement(this.stringify({ reference: query.valueType, name: query.name.name })); + this.writeQueryParameter(writer, query); writer.endControlFlow(); + writer.writeLine(); } }), queryParameterBagReference: QUERY_PARAMETER_BAG_NAME }; } + private writeQueryParameter(writer: csharp.Writer, query: QueryParameter): void { + if (!query.allowMultiple) { + writer.write(`${QUERY_PARAMETER_BAG_NAME}["${query.name.wireValue}"] = `); + writer.writeNodeStatement(this.stringify({ reference: query.valueType, name: query.name.name })); + return; + } + const queryParameterReference = `${this.getParameterName()}.${query.name.name.pascalCase.safeName}`; + const valuesListVarName = `_${query.name.name.camelCase.safeName}`; + const isOptional = this.context.isOptional(query.valueType); + writer.writeLine(); + writer.writeLine(`var ${valuesListVarName} = new List();`); + writer.controlFlow("foreach", `var _value in ${queryParameterReference}`); + if (isOptional) { + writer.controlFlow("if", `_value != null`); + } + writer.write(`${valuesListVarName}.Add(`); + writer.writeNode( + this.stringify({ reference: query.valueType, name: query.name.name, parameterOverride: "_value" }) + ); + writer.writeLine(");"); + if (isOptional) { + writer.endControlFlow(); + } + writer.endControlFlow(); + writer.writeLine(`${QUERY_PARAMETER_BAG_NAME}["${query.name.wireValue}"] = ${valuesListVarName};`); + writer.writeLine(); + } + public getHeaderParameterCodeBlock(): HeaderParameterCodeBlock | undefined { if (this.endpoint.headers.length === 0) { return undefined; @@ -144,18 +169,27 @@ export class WrappedEndpointRequest extends EndpointRequest { return undefined; } - private stringify({ reference, name }: { reference: TypeReference; name: Name }): csharp.CodeBlock { + private stringify({ + reference, + name, + parameterOverride + }: { + reference: TypeReference; + name: Name; + parameterOverride?: string; + }): csharp.CodeBlock { + const parameter = parameterOverride ?? `${this.getParameterName()}.${name.pascalCase.safeName}`; if (this.isString(reference)) { - return csharp.codeblock(`${this.getParameterName()}.${name.pascalCase.safeName}`); + return csharp.codeblock(`${parameter}`); } else if (this.isDatetime({ typeReference: reference, allowOptionals: false })) { return csharp.codeblock((writer) => { - writer.write(`${this.getParameterName()}.${name.pascalCase.safeName}.ToString(`); + writer.write(`${parameter}.ToString(`); writer.writeNode(this.context.getConstantsClassReference()); writer.write(".DateTimeFormat)"); }); } else if (this.isDatetime({ typeReference: reference, allowOptionals: true })) { return csharp.codeblock((writer) => { - writer.write(`${this.getParameterName()}.${name.pascalCase.safeName}.Value.ToString(`); + writer.write(`${parameter}.Value.ToString(`); writer.writeNode(this.context.getConstantsClassReference()); writer.write(".DateTimeFormat)"); }); @@ -167,7 +201,7 @@ export class WrappedEndpointRequest extends EndpointRequest { namespace: "System.Text.Json" }) ); - writer.write(`.Serialize(${this.getParameterName()}.${name.pascalCase.safeName})`); + writer.write(`.Serialize(${parameter})`); }); } else if (this.isEnum({ typeReference: reference, allowOptionals: true })) { return csharp.codeblock((writer) => { @@ -177,10 +211,10 @@ export class WrappedEndpointRequest extends EndpointRequest { namespace: "System.Text.Json" }) ); - writer.write(`.Serialize(${this.getParameterName()}.${name.pascalCase.safeName}.Value)`); + writer.write(`.Serialize(${parameter}.Value)`); }); } else { - return csharp.codeblock(`${this.getParameterName()}.${name.pascalCase.safeName}.ToString()`); + return csharp.codeblock(`${parameter}.ToString()`); } } diff --git a/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts b/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts index 3cae4e24557..a0e370e6f8e 100644 --- a/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts +++ b/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts @@ -46,10 +46,14 @@ export class WrappedRequestGenerator extends FileGenerator current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs index 85d464042c0..22c3fa933a1 100644 --- a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs +++ b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs @@ -18,19 +18,20 @@ public QueryParamClient(RawClient client) public async Task SendAsync(SendEnumAsQueryParamRequest request) { - var _query = new Dictionary() - { - { "operand", JsonSerializer.Serialize(request.Operand) }, - { "operandOrColor", request.OperandOrColor.ToString() }, - }; + var _query = new Dictionary() { }; + _query["operand"] = JsonSerializer.Serialize(request.Operand); + _query["operandOrColor"] = request.OperandOrColor.ToString(); + if (request.MaybeOperand != null) { _query["maybeOperand"] = JsonSerializer.Serialize(request.MaybeOperand.Value); } + if (request.MaybeOperandOrColor != null) { _query["maybeOperandOrColor"] = request.MaybeOperandOrColor.ToString(); } + await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -44,19 +45,42 @@ await _client.MakeRequestAsync( public async Task SendListAsync(SendEnumListAsQueryParamRequest request) { - var _query = new Dictionary() + var _query = new Dictionary() { }; + + var _operand = new List(); + foreach (var _value in request.Operand) { - { "operand", JsonSerializer.Serialize(request.Operand) }, - { "operandOrColor", request.OperandOrColor.ToString() }, - }; - if (request.MaybeOperand != null) + _operand.Add(JsonSerializer.Serialize(_value)); + } + _query["operand"] = _operand; + + var _maybeOperand = new List(); + foreach (var _value in request.MaybeOperand) { - _query["maybeOperand"] = JsonSerializer.Serialize(request.MaybeOperand.Value); + if (_value != null) + { + _maybeOperand.Add(JsonSerializer.Serialize(_value.Value)); + } } - if (request.MaybeOperandOrColor != null) + _query["maybeOperand"] = _maybeOperand; + + var _operandOrColor = new List(); + foreach (var _value in request.OperandOrColor) { - _query["maybeOperandOrColor"] = request.MaybeOperandOrColor.ToString(); + _operandOrColor.Add(_value.ToString()); + } + _query["operandOrColor"] = _operandOrColor; + + var _maybeOperandOrColor = new List(); + foreach (var _value in request.MaybeOperandOrColor) + { + if (_value != null) + { + _maybeOperandOrColor.Add(_value.ToString()); + } } + _query["maybeOperandOrColor"] = _maybeOperandOrColor; + await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs index ca610928dd6..8a03f85b65c 100644 --- a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs +++ b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs @@ -7,11 +7,13 @@ namespace SeedEnum; public record SendEnumListAsQueryParamRequest { - public required Operand Operand { get; set; } + public IEnumerable Operand { get; set; } = new List(); - public Operand? MaybeOperand { get; set; } + public IEnumerable MaybeOperand { get; set; } = new List(); - public required OneOf OperandOrColor { get; set; } + public IEnumerable> OperandOrColor { get; set; } = + new List>(); - public OneOf? MaybeOperandOrColor { get; set; } + public IEnumerable?> MaybeOperandOrColor { get; set; } = + new List?>(); } From 6146c608047a43497e1f8ae69906bf047e9cd4e8 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 18:00:43 -0400 Subject: [PATCH 02/10] Use LINQ approach --- .../request/WrappedEndpointRequest.ts | 21 ++------ .../SeedEnum/QueryParam/QueryParamClient.cs | 49 ++++++------------- 2 files changed, 18 insertions(+), 52 deletions(-) diff --git a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts index dc9fb03f9e7..41a58622d0d 100644 --- a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts +++ b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts @@ -87,31 +87,18 @@ export class WrappedEndpointRequest extends EndpointRequest { } private writeQueryParameter(writer: csharp.Writer, query: QueryParameter): void { + writer.write(`${QUERY_PARAMETER_BAG_NAME}["${query.name.wireValue}"] = `); if (!query.allowMultiple) { - writer.write(`${QUERY_PARAMETER_BAG_NAME}["${query.name.wireValue}"] = `); writer.writeNodeStatement(this.stringify({ reference: query.valueType, name: query.name.name })); return; } const queryParameterReference = `${this.getParameterName()}.${query.name.name.pascalCase.safeName}`; - const valuesListVarName = `_${query.name.name.camelCase.safeName}`; - const isOptional = this.context.isOptional(query.valueType); - writer.writeLine(); - writer.writeLine(`var ${valuesListVarName} = new List();`); - writer.controlFlow("foreach", `var _value in ${queryParameterReference}`); - if (isOptional) { - writer.controlFlow("if", `_value != null`); - } - writer.write(`${valuesListVarName}.Add(`); + const maybeOptionalCheck = this.context.isOptional(query.valueType) ? ".Where(_value => _value != null)" : ""; + writer.write(`${queryParameterReference}${maybeOptionalCheck}.Select(_value => `); writer.writeNode( this.stringify({ reference: query.valueType, name: query.name.name, parameterOverride: "_value" }) ); - writer.writeLine(");"); - if (isOptional) { - writer.endControlFlow(); - } - writer.endControlFlow(); - writer.writeLine(`${QUERY_PARAMETER_BAG_NAME}["${query.name.wireValue}"] = ${valuesListVarName};`); - writer.writeLine(); + writer.writeLine(").ToList();"); } public getHeaderParameterCodeBlock(): HeaderParameterCodeBlock | undefined { diff --git a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs index 22c3fa933a1..c6e1c337e1b 100644 --- a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs +++ b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs @@ -46,41 +46,20 @@ await _client.MakeRequestAsync( public async Task SendListAsync(SendEnumListAsQueryParamRequest request) { var _query = new Dictionary() { }; - - var _operand = new List(); - foreach (var _value in request.Operand) - { - _operand.Add(JsonSerializer.Serialize(_value)); - } - _query["operand"] = _operand; - - var _maybeOperand = new List(); - foreach (var _value in request.MaybeOperand) - { - if (_value != null) - { - _maybeOperand.Add(JsonSerializer.Serialize(_value.Value)); - } - } - _query["maybeOperand"] = _maybeOperand; - - var _operandOrColor = new List(); - foreach (var _value in request.OperandOrColor) - { - _operandOrColor.Add(_value.ToString()); - } - _query["operandOrColor"] = _operandOrColor; - - var _maybeOperandOrColor = new List(); - foreach (var _value in request.MaybeOperandOrColor) - { - if (_value != null) - { - _maybeOperandOrColor.Add(_value.ToString()); - } - } - _query["maybeOperandOrColor"] = _maybeOperandOrColor; - + _query["operand"] = request + .Operand.Select(_value => JsonSerializer.Serialize(_value)) + .ToList(); + _query["maybeOperand"] = request + .MaybeOperand.Where(_value => _value != null) + .Select(_value => JsonSerializer.Serialize(_value.Value)) + .ToList(); + _query["operandOrColor"] = request + .OperandOrColor.Select(_value => _value.ToString()) + .ToList(); + _query["maybeOperandOrColor"] = request + .MaybeOperandOrColor.Where(_value => _value != null) + .Select(_value => _value.ToString()) + .ToList(); await _client.MakeRequestAsync( new RawClient.JsonApiRequest { From ff7aecc5de2c5a274ae0da22b41b08153d665149 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 18:04:19 -0400 Subject: [PATCH 03/10] Add CHANGELOG.md; update snapshots --- generators/csharp/sdk/CHANGELOG.md | 12 +++++++- generators/csharp/sdk/VERSION | 2 +- .../alias/src/SeedAlias/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedApiWideBasePath/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedAudiences/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedAudiences/Foo/FooClient.cs | 2 ++ .../Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../src/SeedBasicAuth/Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../bytes/src/SeedBytes/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedApi/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedApi/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedCodeSamples/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedCustomAuth/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedErrorProperty/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedExamples/Core/RawClient.cs | 20 ++++++++++++- .../Service/Requests/GetMetadataRequest.cs | 2 +- .../src/SeedExamples/Service/ServiceClient.cs | 10 ++++--- .../src/SeedExhaustive/Core/RawClient.cs | 20 ++++++++++++- .../Endpoints/Params/ParamsClient.cs | 19 +++++------- .../Params/Requests/GetWithMultipleQuery.cs | 4 +-- .../extends/src/SeedExtends/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedExtraProperties/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedFileDownload/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedFileUpload/Core/RawClient.cs | 20 ++++++++++++- .../Requests/JustFileWithQueryParamsRequet.cs | 4 +-- .../SeedFileUpload/Service/ServiceClient.cs | 19 ++++++------ .../folders/src/SeedApi/Core/RawClient.cs | 20 ++++++++++++- .../SeedIdempotencyHeaders/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedApi/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedApi/Core/RawClient.cs | 20 ++++++++++++- .../literal/src/SeedLiteral/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedLiteral/Query/QueryClient.cs | 10 +++---- .../src/SeedMixedCase/Core/RawClient.cs | 20 ++++++++++++- .../SeedMixedCase/Service/ServiceClient.cs | 8 ++--- .../src/SeedMultiLineDocs/Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../SeedMultiUrlEnvironment/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedNoEnvironment/Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../object/src/SeedObject/Core/RawClient.cs | 20 ++++++++++++- .../SeedObjectsWithImports/Core/RawClient.cs | 20 ++++++++++++- .../SeedObjectsWithImports/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedPackageYml/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedPagination/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedPagination/Users/UsersClient.cs | 20 +++++++++++++ .../src/SeedPlainText/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedQueryParameters/Core/RawClient.cs | 20 ++++++++++++- .../User/Requests/GetUsersRequest.cs | 4 +-- .../SeedQueryParameters/User/UserClient.cs | 30 ++++++++++--------- .../src/SeedNurseryApi/Core/RawClient.cs | 20 ++++++++++++- .../SeedNurseryApi/Package/PackageClient.cs | 3 +- .../SeedResponseProperty/Core/RawClient.cs | 20 ++++++++++++- .../SeedServerSentEvents/Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../Core/RawClient.cs | 20 ++++++++++++- .../src/SeedStreaming/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedStreaming/Core/RawClient.cs | 20 ++++++++++++- .../trace/src/SeedTrace/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedTrace/Playlist/PlaylistClient.cs | 28 ++++++++--------- .../Playlist/Requests/GetPlaylistsRequest.cs | 4 +-- .../Core/RawClient.cs | 20 ++++++++++++- .../unions/src/SeedUnions/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedUnknownAsAny/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedValidation/Core/RawClient.cs | 20 ++++++++++++- .../SeedValidation/SeedValidationClient.cs | 10 +++---- .../src/SeedVariables/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedVersion/Core/RawClient.cs | 20 ++++++++++++- .../version/src/SeedVersion/Core/RawClient.cs | 20 ++++++++++++- .../src/SeedWebsocket/Core/RawClient.cs | 20 ++++++++++++- 74 files changed, 1174 insertions(+), 137 deletions(-) diff --git a/generators/csharp/sdk/CHANGELOG.md b/generators/csharp/sdk/CHANGELOG.md index ad007eaa490..b06b2585cc8 100644 --- a/generators/csharp/sdk/CHANGELOG.md +++ b/generators/csharp/sdk/CHANGELOG.md @@ -5,7 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## [0.4.0 - 2024-07-30] + +- Feature: Add support for `allow-multiple` query parameters, which are sent in the `explode` format. + Given that optional lists are assigned a default, empty list, we use a simple `LINQ` expression to + handle the serialization, which is shown below: + + ```csharp + _query["operand"] = request + .Operand.Select(_value => JsonSerializer.Serialize(_value)) + .ToList(); + ``` - Improvement: `map` types are now generated as `Dictionary` types so they can support explicit `null` values. Note that this does _not_ affect every `unknown` type to be an `object?` diff --git a/generators/csharp/sdk/VERSION b/generators/csharp/sdk/VERSION index 42045acae20..1d0ba9ea182 100644 --- a/generators/csharp/sdk/VERSION +++ b/generators/csharp/sdk/VERSION @@ -1 +1 @@ -0.3.4 +0.4.0 diff --git a/seed/csharp-sdk/alias/src/SeedAlias/Core/RawClient.cs b/seed/csharp-sdk/alias/src/SeedAlias/Core/RawClient.cs index ee51f7cb871..f247b92a98f 100644 --- a/seed/csharp-sdk/alias/src/SeedAlias/Core/RawClient.cs +++ b/seed/csharp-sdk/alias/src/SeedAlias/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/api-wide-base-path/src/SeedApiWideBasePath/Core/RawClient.cs b/seed/csharp-sdk/api-wide-base-path/src/SeedApiWideBasePath/Core/RawClient.cs index 41dd0ffaf85..4275a853551 100644 --- a/seed/csharp-sdk/api-wide-base-path/src/SeedApiWideBasePath/Core/RawClient.cs +++ b/seed/csharp-sdk/api-wide-base-path/src/SeedApiWideBasePath/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/audiences/src/SeedAudiences/Core/RawClient.cs b/seed/csharp-sdk/audiences/src/SeedAudiences/Core/RawClient.cs index 80e346af540..9daa608a23c 100644 --- a/seed/csharp-sdk/audiences/src/SeedAudiences/Core/RawClient.cs +++ b/seed/csharp-sdk/audiences/src/SeedAudiences/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs b/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs index ea2cbf462e6..97556b554b5 100644 --- a/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs +++ b/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs @@ -18,10 +18,12 @@ public FooClient(RawClient client) public async Task FindAsync(FindRequest request) { var _query = new Dictionary() { }; + if (request.OptionalString != null) { _query["optionalString"] = request.OptionalString; } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/auth-environment-variables/src/SeedAuthEnvironmentVariables/Core/RawClient.cs b/seed/csharp-sdk/auth-environment-variables/src/SeedAuthEnvironmentVariables/Core/RawClient.cs index 6ca6a6c4a3a..57c5bfc330f 100644 --- a/seed/csharp-sdk/auth-environment-variables/src/SeedAuthEnvironmentVariables/Core/RawClient.cs +++ b/seed/csharp-sdk/auth-environment-variables/src/SeedAuthEnvironmentVariables/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/basic-auth-environment-variables/src/SeedBasicAuthEnvironmentVariables/Core/RawClient.cs b/seed/csharp-sdk/basic-auth-environment-variables/src/SeedBasicAuthEnvironmentVariables/Core/RawClient.cs index b18987e641d..3a11febc763 100644 --- a/seed/csharp-sdk/basic-auth-environment-variables/src/SeedBasicAuthEnvironmentVariables/Core/RawClient.cs +++ b/seed/csharp-sdk/basic-auth-environment-variables/src/SeedBasicAuthEnvironmentVariables/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/basic-auth/src/SeedBasicAuth/Core/RawClient.cs b/seed/csharp-sdk/basic-auth/src/SeedBasicAuth/Core/RawClient.cs index b624d31091e..5bc77863b0d 100644 --- a/seed/csharp-sdk/basic-auth/src/SeedBasicAuth/Core/RawClient.cs +++ b/seed/csharp-sdk/basic-auth/src/SeedBasicAuth/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/bearer-token-environment-variable/src/SeedBearerTokenEnvironmentVariable/Core/RawClient.cs b/seed/csharp-sdk/bearer-token-environment-variable/src/SeedBearerTokenEnvironmentVariable/Core/RawClient.cs index cb62bd63349..25b001ee32b 100644 --- a/seed/csharp-sdk/bearer-token-environment-variable/src/SeedBearerTokenEnvironmentVariable/Core/RawClient.cs +++ b/seed/csharp-sdk/bearer-token-environment-variable/src/SeedBearerTokenEnvironmentVariable/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/bytes/src/SeedBytes/Core/RawClient.cs b/seed/csharp-sdk/bytes/src/SeedBytes/Core/RawClient.cs index 5d5479a51fc..7d652c8c928 100644 --- a/seed/csharp-sdk/bytes/src/SeedBytes/Core/RawClient.cs +++ b/seed/csharp-sdk/bytes/src/SeedBytes/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/circular-references-advanced/src/SeedApi/Core/RawClient.cs b/seed/csharp-sdk/circular-references-advanced/src/SeedApi/Core/RawClient.cs index 437825ca198..c0eedc4f109 100644 --- a/seed/csharp-sdk/circular-references-advanced/src/SeedApi/Core/RawClient.cs +++ b/seed/csharp-sdk/circular-references-advanced/src/SeedApi/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/circular-references/src/SeedApi/Core/RawClient.cs b/seed/csharp-sdk/circular-references/src/SeedApi/Core/RawClient.cs index 437825ca198..c0eedc4f109 100644 --- a/seed/csharp-sdk/circular-references/src/SeedApi/Core/RawClient.cs +++ b/seed/csharp-sdk/circular-references/src/SeedApi/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/code-samples/src/SeedCodeSamples/Core/RawClient.cs b/seed/csharp-sdk/code-samples/src/SeedCodeSamples/Core/RawClient.cs index 12ca26fff72..179d47a1985 100644 --- a/seed/csharp-sdk/code-samples/src/SeedCodeSamples/Core/RawClient.cs +++ b/seed/csharp-sdk/code-samples/src/SeedCodeSamples/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/custom-auth/src/SeedCustomAuth/Core/RawClient.cs b/seed/csharp-sdk/custom-auth/src/SeedCustomAuth/Core/RawClient.cs index 3797dae8236..dc68e05d06c 100644 --- a/seed/csharp-sdk/custom-auth/src/SeedCustomAuth/Core/RawClient.cs +++ b/seed/csharp-sdk/custom-auth/src/SeedCustomAuth/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/error-property/src/SeedErrorProperty/Core/RawClient.cs b/seed/csharp-sdk/error-property/src/SeedErrorProperty/Core/RawClient.cs index cd1b07ea53d..d1088389629 100644 --- a/seed/csharp-sdk/error-property/src/SeedErrorProperty/Core/RawClient.cs +++ b/seed/csharp-sdk/error-property/src/SeedErrorProperty/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/examples/src/SeedExamples/Core/RawClient.cs b/seed/csharp-sdk/examples/src/SeedExamples/Core/RawClient.cs index d0a9f9376c0..ead55a2da2b 100644 --- a/seed/csharp-sdk/examples/src/SeedExamples/Core/RawClient.cs +++ b/seed/csharp-sdk/examples/src/SeedExamples/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs b/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs index a5b24076f6e..f4f50a3c613 100644 --- a/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs +++ b/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs @@ -4,7 +4,7 @@ public record GetMetadataRequest { public bool? Shallow { get; set; } - public string? Tag { get; set; } + public IEnumerable Tag { get; set; } = new List(); public required string XApiVersion { get; set; } } diff --git a/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs b/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs index 9e39115afd6..d2ca02270a7 100644 --- a/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs +++ b/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs @@ -55,14 +55,16 @@ public async Task CreateMovieAsync(Movie request) public async Task GetMetadataAsync(GetMetadataRequest request) { var _query = new Dictionary() { }; + _query["tag"] = request + .Tag.Where(_value => _value != null) + .Select(_value => _value) + .ToList(); + if (request.Shallow != null) { _query["shallow"] = request.Shallow.ToString(); } - if (request.Tag != null) - { - _query["tag"] = request.Tag; - } + var _headers = new Dictionary() { { "X-API-Version", request.XApiVersion }, diff --git a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Core/RawClient.cs b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Core/RawClient.cs index 3d5e0af6ca3..3bb425879eb 100644 --- a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Core/RawClient.cs +++ b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs index 59f61d6668e..ce58a379afc 100644 --- a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs +++ b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs @@ -41,11 +41,9 @@ public async Task GetWithPathAsync(string param) /// public async Task GetWithQueryAsync(GetWithQuery request) { - var _query = new Dictionary() - { - { "query", request.Query }, - { "number", request.Number.ToString() }, - }; + var _query = new Dictionary() { }; + _query["query"] = request.Query; + _query["number"] = request.Number.ToString(); await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -62,11 +60,9 @@ await _client.MakeRequestAsync( /// public async Task GetWithAllowMultipleQueryAsync(GetWithMultipleQuery request) { - var _query = new Dictionary() - { - { "query", request.Query }, - { "numer", request.Numer.ToString() }, - }; + var _query = new Dictionary() { }; + _query["query"] = request.Query.Select(_value => _value).ToList(); + _query["numer"] = request.Numer.Select(_value => _value.ToString()).ToList(); await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -83,7 +79,8 @@ await _client.MakeRequestAsync( /// public async Task GetWithPathAndQueryAsync(string param, GetWithPathAndQuery request) { - var _query = new Dictionary() { { "query", request.Query }, }; + var _query = new Dictionary() { }; + _query["query"] = request.Query; await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/Requests/GetWithMultipleQuery.cs b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/Requests/GetWithMultipleQuery.cs index 2f37fceacff..32e2a499d47 100644 --- a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/Requests/GetWithMultipleQuery.cs +++ b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/Requests/GetWithMultipleQuery.cs @@ -2,7 +2,7 @@ namespace SeedExhaustive.Endpoints.Params; public record GetWithMultipleQuery { - public required string Query { get; set; } + public IEnumerable Query { get; set; } = new List(); - public required int Numer { get; set; } + public IEnumerable Numer { get; set; } = new List(); } diff --git a/seed/csharp-sdk/extends/src/SeedExtends/Core/RawClient.cs b/seed/csharp-sdk/extends/src/SeedExtends/Core/RawClient.cs index e9d8a36a470..f58e4322312 100644 --- a/seed/csharp-sdk/extends/src/SeedExtends/Core/RawClient.cs +++ b/seed/csharp-sdk/extends/src/SeedExtends/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/extra-properties/src/SeedExtraProperties/Core/RawClient.cs b/seed/csharp-sdk/extra-properties/src/SeedExtraProperties/Core/RawClient.cs index 0a32f70013c..5d4294c8a9a 100644 --- a/seed/csharp-sdk/extra-properties/src/SeedExtraProperties/Core/RawClient.cs +++ b/seed/csharp-sdk/extra-properties/src/SeedExtraProperties/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/file-download/src/SeedFileDownload/Core/RawClient.cs b/seed/csharp-sdk/file-download/src/SeedFileDownload/Core/RawClient.cs index 8fcb749cf20..34c61726a23 100644 --- a/seed/csharp-sdk/file-download/src/SeedFileDownload/Core/RawClient.cs +++ b/seed/csharp-sdk/file-download/src/SeedFileDownload/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Core/RawClient.cs b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Core/RawClient.cs index a0c9c51c9b9..474cbd18b6d 100644 --- a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Core/RawClient.cs +++ b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs index 0a950f5a4ed..1da100f537a 100644 --- a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs +++ b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs @@ -8,7 +8,7 @@ public record JustFileWithQueryParamsRequet public int? MaybeInteger { get; set; } - public required string ListOfStrings { get; set; } + public IEnumerable ListOfStrings { get; set; } = new List(); - public string? OptionalListOfStrings { get; set; } + public IEnumerable OptionalListOfStrings { get; set; } = new List(); } diff --git a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs index e5fcd185959..0c5fb2e2233 100644 --- a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs +++ b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs @@ -41,23 +41,24 @@ await _client.MakeRequestAsync( public async Task JustFileWithQueryParamsAsync(JustFileWithQueryParamsRequet request) { - var _query = new Dictionary() - { - { "integer", request.Integer.ToString() }, - { "listOfStrings", request.ListOfStrings }, - }; + var _query = new Dictionary() { }; + _query["integer"] = request.Integer.ToString(); + _query["listOfStrings"] = request.ListOfStrings.Select(_value => _value).ToList(); + _query["optionalListOfStrings"] = request + .OptionalListOfStrings.Where(_value => _value != null) + .Select(_value => _value) + .ToList(); + if (request.MaybeString != null) { _query["maybeString"] = request.MaybeString; } + if (request.MaybeInteger != null) { _query["maybeInteger"] = request.MaybeInteger.ToString(); } - if (request.OptionalListOfStrings != null) - { - _query["optionalListOfStrings"] = request.OptionalListOfStrings; - } + await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/folders/src/SeedApi/Core/RawClient.cs b/seed/csharp-sdk/folders/src/SeedApi/Core/RawClient.cs index 437825ca198..c0eedc4f109 100644 --- a/seed/csharp-sdk/folders/src/SeedApi/Core/RawClient.cs +++ b/seed/csharp-sdk/folders/src/SeedApi/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/idempotency-headers/src/SeedIdempotencyHeaders/Core/RawClient.cs b/seed/csharp-sdk/idempotency-headers/src/SeedIdempotencyHeaders/Core/RawClient.cs index 709fbcddd2c..85f64e581e4 100644 --- a/seed/csharp-sdk/idempotency-headers/src/SeedIdempotencyHeaders/Core/RawClient.cs +++ b/seed/csharp-sdk/idempotency-headers/src/SeedIdempotencyHeaders/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/imdb/extra-dependencies/src/SeedApi/Core/RawClient.cs b/seed/csharp-sdk/imdb/extra-dependencies/src/SeedApi/Core/RawClient.cs index 437825ca198..c0eedc4f109 100644 --- a/seed/csharp-sdk/imdb/extra-dependencies/src/SeedApi/Core/RawClient.cs +++ b/seed/csharp-sdk/imdb/extra-dependencies/src/SeedApi/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/imdb/no-custom-config/src/SeedApi/Core/RawClient.cs b/seed/csharp-sdk/imdb/no-custom-config/src/SeedApi/Core/RawClient.cs index 437825ca198..c0eedc4f109 100644 --- a/seed/csharp-sdk/imdb/no-custom-config/src/SeedApi/Core/RawClient.cs +++ b/seed/csharp-sdk/imdb/no-custom-config/src/SeedApi/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/literal/src/SeedLiteral/Core/RawClient.cs b/seed/csharp-sdk/literal/src/SeedLiteral/Core/RawClient.cs index b10b0919303..15edd5b82af 100644 --- a/seed/csharp-sdk/literal/src/SeedLiteral/Core/RawClient.cs +++ b/seed/csharp-sdk/literal/src/SeedLiteral/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/literal/src/SeedLiteral/Query/QueryClient.cs b/seed/csharp-sdk/literal/src/SeedLiteral/Query/QueryClient.cs index d260ebf8bf8..14f12270306 100644 --- a/seed/csharp-sdk/literal/src/SeedLiteral/Query/QueryClient.cs +++ b/seed/csharp-sdk/literal/src/SeedLiteral/Query/QueryClient.cs @@ -17,12 +17,10 @@ public QueryClient(RawClient client) public async Task SendAsync(SendLiteralsInQueryRequest request) { - var _query = new Dictionary() - { - { "prompt", request.Prompt.ToString() }, - { "query", request.Query }, - { "stream", request.Stream.ToString() }, - }; + var _query = new Dictionary() { }; + _query["prompt"] = request.Prompt.ToString(); + _query["query"] = request.Query; + _query["stream"] = request.Stream.ToString(); var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Core/RawClient.cs b/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Core/RawClient.cs index f99078b5dad..3fa24118baa 100644 --- a/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Core/RawClient.cs +++ b/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Service/ServiceClient.cs b/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Service/ServiceClient.cs index 68afa82b1f6..2b0ca762443 100644 --- a/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Service/ServiceClient.cs +++ b/seed/csharp-sdk/mixed-case/src/SeedMixedCase/Service/ServiceClient.cs @@ -35,11 +35,9 @@ public async Task GetResourceAsync(string resourceId) public async Task> ListResourcesAsync(ListResourcesRequest request) { - var _query = new Dictionary() - { - { "page_limit", request.PageLimit.ToString() }, - { "beforeDate", request.BeforeDate.ToString() }, - }; + var _query = new Dictionary() { }; + _query["page_limit"] = request.PageLimit.ToString(); + _query["beforeDate"] = request.BeforeDate.ToString(); var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/multi-line-docs/src/SeedMultiLineDocs/Core/RawClient.cs b/seed/csharp-sdk/multi-line-docs/src/SeedMultiLineDocs/Core/RawClient.cs index d96906f50c5..0d20b78b94f 100644 --- a/seed/csharp-sdk/multi-line-docs/src/SeedMultiLineDocs/Core/RawClient.cs +++ b/seed/csharp-sdk/multi-line-docs/src/SeedMultiLineDocs/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/multi-url-environment-no-default/src/SeedMultiUrlEnvironmentNoDefault/Core/RawClient.cs b/seed/csharp-sdk/multi-url-environment-no-default/src/SeedMultiUrlEnvironmentNoDefault/Core/RawClient.cs index f65b5b0e62c..cbf976b1c2a 100644 --- a/seed/csharp-sdk/multi-url-environment-no-default/src/SeedMultiUrlEnvironmentNoDefault/Core/RawClient.cs +++ b/seed/csharp-sdk/multi-url-environment-no-default/src/SeedMultiUrlEnvironmentNoDefault/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/multi-url-environment/src/SeedMultiUrlEnvironment/Core/RawClient.cs b/seed/csharp-sdk/multi-url-environment/src/SeedMultiUrlEnvironment/Core/RawClient.cs index cba019d03b9..a52db8fffa7 100644 --- a/seed/csharp-sdk/multi-url-environment/src/SeedMultiUrlEnvironment/Core/RawClient.cs +++ b/seed/csharp-sdk/multi-url-environment/src/SeedMultiUrlEnvironment/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/no-environment/src/SeedNoEnvironment/Core/RawClient.cs b/seed/csharp-sdk/no-environment/src/SeedNoEnvironment/Core/RawClient.cs index 6d8aa8ebce2..2eea20eee02 100644 --- a/seed/csharp-sdk/no-environment/src/SeedNoEnvironment/Core/RawClient.cs +++ b/seed/csharp-sdk/no-environment/src/SeedNoEnvironment/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/oauth-client-credentials-default/src/SeedOauthClientCredentialsDefault/Core/RawClient.cs b/seed/csharp-sdk/oauth-client-credentials-default/src/SeedOauthClientCredentialsDefault/Core/RawClient.cs index fc2e981f229..dcd73df1f13 100644 --- a/seed/csharp-sdk/oauth-client-credentials-default/src/SeedOauthClientCredentialsDefault/Core/RawClient.cs +++ b/seed/csharp-sdk/oauth-client-credentials-default/src/SeedOauthClientCredentialsDefault/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/oauth-client-credentials-environment-variables/src/SeedOauthClientCredentialsEnvironmentVariables/Core/RawClient.cs b/seed/csharp-sdk/oauth-client-credentials-environment-variables/src/SeedOauthClientCredentialsEnvironmentVariables/Core/RawClient.cs index 4116f738375..8b278138404 100644 --- a/seed/csharp-sdk/oauth-client-credentials-environment-variables/src/SeedOauthClientCredentialsEnvironmentVariables/Core/RawClient.cs +++ b/seed/csharp-sdk/oauth-client-credentials-environment-variables/src/SeedOauthClientCredentialsEnvironmentVariables/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/oauth-client-credentials-nested-root/src/SeedOauthClientCredentials/Core/RawClient.cs b/seed/csharp-sdk/oauth-client-credentials-nested-root/src/SeedOauthClientCredentials/Core/RawClient.cs index a0b586498ca..b289b0baf41 100644 --- a/seed/csharp-sdk/oauth-client-credentials-nested-root/src/SeedOauthClientCredentials/Core/RawClient.cs +++ b/seed/csharp-sdk/oauth-client-credentials-nested-root/src/SeedOauthClientCredentials/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/oauth-client-credentials/src/SeedOauthClientCredentials/Core/RawClient.cs b/seed/csharp-sdk/oauth-client-credentials/src/SeedOauthClientCredentials/Core/RawClient.cs index a0b586498ca..b289b0baf41 100644 --- a/seed/csharp-sdk/oauth-client-credentials/src/SeedOauthClientCredentials/Core/RawClient.cs +++ b/seed/csharp-sdk/oauth-client-credentials/src/SeedOauthClientCredentials/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/object/src/SeedObject/Core/RawClient.cs b/seed/csharp-sdk/object/src/SeedObject/Core/RawClient.cs index 275c025a643..f1cbceb56d9 100644 --- a/seed/csharp-sdk/object/src/SeedObject/Core/RawClient.cs +++ b/seed/csharp-sdk/object/src/SeedObject/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/objects-with-imports/src/SeedObjectsWithImports/Core/RawClient.cs b/seed/csharp-sdk/objects-with-imports/src/SeedObjectsWithImports/Core/RawClient.cs index c3eb5ad5e87..ec6044a695b 100644 --- a/seed/csharp-sdk/objects-with-imports/src/SeedObjectsWithImports/Core/RawClient.cs +++ b/seed/csharp-sdk/objects-with-imports/src/SeedObjectsWithImports/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/optional/src/SeedObjectsWithImports/Core/RawClient.cs b/seed/csharp-sdk/optional/src/SeedObjectsWithImports/Core/RawClient.cs index c3eb5ad5e87..ec6044a695b 100644 --- a/seed/csharp-sdk/optional/src/SeedObjectsWithImports/Core/RawClient.cs +++ b/seed/csharp-sdk/optional/src/SeedObjectsWithImports/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/package-yml/src/SeedPackageYml/Core/RawClient.cs b/seed/csharp-sdk/package-yml/src/SeedPackageYml/Core/RawClient.cs index e2587b52e75..be5c0b5a8bd 100644 --- a/seed/csharp-sdk/package-yml/src/SeedPackageYml/Core/RawClient.cs +++ b/seed/csharp-sdk/package-yml/src/SeedPackageYml/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/pagination/src/SeedPagination/Core/RawClient.cs b/seed/csharp-sdk/pagination/src/SeedPagination/Core/RawClient.cs index 545a7dc83cb..4ef015de2b0 100644 --- a/seed/csharp-sdk/pagination/src/SeedPagination/Core/RawClient.cs +++ b/seed/csharp-sdk/pagination/src/SeedPagination/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs b/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs index 269cb893863..d1e6471c058 100644 --- a/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs +++ b/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs @@ -21,22 +21,27 @@ ListUsersCursorPaginationRequest request ) { var _query = new Dictionary() { }; + if (request.Page != null) { _query["page"] = request.Page.ToString(); } + if (request.PerPage != null) { _query["per_page"] = request.PerPage.ToString(); } + if (request.Order != null) { _query["order"] = JsonSerializer.Serialize(request.Order.Value); } + if (request.StartingAfter != null) { _query["starting_after"] = request.StartingAfter; } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -80,22 +85,27 @@ ListUsersOffsetPaginationRequest request ) { var _query = new Dictionary() { }; + if (request.Page != null) { _query["page"] = request.Page.ToString(); } + if (request.PerPage != null) { _query["per_page"] = request.PerPage.ToString(); } + if (request.Order != null) { _query["order"] = JsonSerializer.Serialize(request.Order.Value); } + if (request.StartingAfter != null) { _query["starting_after"] = request.StartingAfter; } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -139,18 +149,22 @@ ListUsersOffsetStepPaginationRequest request ) { var _query = new Dictionary() { }; + if (request.Page != null) { _query["page"] = request.Page.ToString(); } + if (request.Limit != null) { _query["limit"] = request.Limit.ToString(); } + if (request.Order != null) { _query["order"] = JsonSerializer.Serialize(request.Order.Value); } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -173,10 +187,12 @@ ListUsersExtendedRequest request ) { var _query = new Dictionary() { }; + if (request.Cursor != null) { _query["cursor"] = request.Cursor.ToString(); } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -197,10 +213,12 @@ ListUsersExtendedRequest request public async Task ListUsernamesAsync(ListUsernamesRequest request) { var _query = new Dictionary() { }; + if (request.StartingAfter != null) { _query["starting_after"] = request.StartingAfter; } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -223,10 +241,12 @@ ListWithGlobalConfigRequest request ) { var _query = new Dictionary() { }; + if (request.Offset != null) { _query["offset"] = request.Offset.ToString(); } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/plain-text/src/SeedPlainText/Core/RawClient.cs b/seed/csharp-sdk/plain-text/src/SeedPlainText/Core/RawClient.cs index e857412e886..8ec768a13b0 100644 --- a/seed/csharp-sdk/plain-text/src/SeedPlainText/Core/RawClient.cs +++ b/seed/csharp-sdk/plain-text/src/SeedPlainText/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/Core/RawClient.cs b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/Core/RawClient.cs index 80f41ad985e..67052b273de 100644 --- a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/Core/RawClient.cs +++ b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/Requests/GetUsersRequest.cs b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/Requests/GetUsersRequest.cs index 175cb8fc384..731854a96fb 100644 --- a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/Requests/GetUsersRequest.cs +++ b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/Requests/GetUsersRequest.cs @@ -30,7 +30,7 @@ public record GetUsersRequest public User? OptionalUser { get; set; } - public required User ExcludeUser { get; set; } + public IEnumerable ExcludeUser { get; set; } = new List(); - public required string Filter { get; set; } + public IEnumerable Filter { get; set; } = new List(); } diff --git a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs index a1aa6fde576..3054a76990b 100644 --- a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs +++ b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs @@ -17,34 +17,36 @@ public UserClient(RawClient client) public async Task GetUsernameAsync(GetUsersRequest request) { - var _query = new Dictionary() - { - { "limit", request.Limit.ToString() }, - { "id", request.Id.ToString() }, - { "date", request.Date.ToString() }, - { "deadline", request.Deadline.ToString(Constants.DateTimeFormat) }, - { "bytes", request.Bytes.ToString() }, - { "user", request.User.ToString() }, - { "userList", request.UserList.ToString() }, - { "keyValue", request.KeyValue.ToString() }, - { "nestedUser", request.NestedUser.ToString() }, - { "excludeUser", request.ExcludeUser.ToString() }, - { "filter", request.Filter }, - }; + var _query = new Dictionary() { }; + _query["limit"] = request.Limit.ToString(); + _query["id"] = request.Id.ToString(); + _query["date"] = request.Date.ToString(); + _query["deadline"] = request.Deadline.ToString(Constants.DateTimeFormat); + _query["bytes"] = request.Bytes.ToString(); + _query["user"] = request.User.ToString(); + _query["userList"] = request.UserList.ToString(); + _query["keyValue"] = request.KeyValue.ToString(); + _query["nestedUser"] = request.NestedUser.ToString(); + _query["excludeUser"] = request.ExcludeUser.Select(_value => _value.ToString()).ToList(); + _query["filter"] = request.Filter.Select(_value => _value).ToList(); + if (request.OptionalDeadline != null) { _query["optionalDeadline"] = request.OptionalDeadline.Value.ToString( Constants.DateTimeFormat ); } + if (request.OptionalString != null) { _query["optionalString"] = request.OptionalString; } + if (request.OptionalUser != null) { _query["optionalUser"] = request.OptionalUser.ToString(); } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Core/RawClient.cs b/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Core/RawClient.cs index 5eb90c93383..9a54a716cc0 100644 --- a/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Core/RawClient.cs +++ b/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Package/PackageClient.cs b/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Package/PackageClient.cs index df07ddd4cf6..d2fe8a3daf4 100644 --- a/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Package/PackageClient.cs +++ b/seed/csharp-sdk/reserved-keywords/src/SeedNurseryApi/Package/PackageClient.cs @@ -17,7 +17,8 @@ public PackageClient(RawClient client) public async Task TestAsync(TestRequest request) { - var _query = new Dictionary() { { "for", request.For }, }; + var _query = new Dictionary() { }; + _query["for"] = request.For; await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/response-property/src/SeedResponseProperty/Core/RawClient.cs b/seed/csharp-sdk/response-property/src/SeedResponseProperty/Core/RawClient.cs index 69a5cfb63fb..bd49dd31440 100644 --- a/seed/csharp-sdk/response-property/src/SeedResponseProperty/Core/RawClient.cs +++ b/seed/csharp-sdk/response-property/src/SeedResponseProperty/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/server-sent-events/src/SeedServerSentEvents/Core/RawClient.cs b/seed/csharp-sdk/server-sent-events/src/SeedServerSentEvents/Core/RawClient.cs index e6c5f91b880..62dbea408a7 100644 --- a/seed/csharp-sdk/server-sent-events/src/SeedServerSentEvents/Core/RawClient.cs +++ b/seed/csharp-sdk/server-sent-events/src/SeedServerSentEvents/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/single-url-environment-default/src/SeedSingleUrlEnvironmentDefault/Core/RawClient.cs b/seed/csharp-sdk/single-url-environment-default/src/SeedSingleUrlEnvironmentDefault/Core/RawClient.cs index eef7fb18f2a..d1b0dd168d8 100644 --- a/seed/csharp-sdk/single-url-environment-default/src/SeedSingleUrlEnvironmentDefault/Core/RawClient.cs +++ b/seed/csharp-sdk/single-url-environment-default/src/SeedSingleUrlEnvironmentDefault/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/single-url-environment-no-default/src/SeedSingleUrlEnvironmentNoDefault/Core/RawClient.cs b/seed/csharp-sdk/single-url-environment-no-default/src/SeedSingleUrlEnvironmentNoDefault/Core/RawClient.cs index bf74e39aafb..9e3621938e0 100644 --- a/seed/csharp-sdk/single-url-environment-no-default/src/SeedSingleUrlEnvironmentNoDefault/Core/RawClient.cs +++ b/seed/csharp-sdk/single-url-environment-no-default/src/SeedSingleUrlEnvironmentNoDefault/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/streaming-parameter/src/SeedStreaming/Core/RawClient.cs b/seed/csharp-sdk/streaming-parameter/src/SeedStreaming/Core/RawClient.cs index b2a52b7cbef..817fb278635 100644 --- a/seed/csharp-sdk/streaming-parameter/src/SeedStreaming/Core/RawClient.cs +++ b/seed/csharp-sdk/streaming-parameter/src/SeedStreaming/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/streaming/src/SeedStreaming/Core/RawClient.cs b/seed/csharp-sdk/streaming/src/SeedStreaming/Core/RawClient.cs index b2a52b7cbef..817fb278635 100644 --- a/seed/csharp-sdk/streaming/src/SeedStreaming/Core/RawClient.cs +++ b/seed/csharp-sdk/streaming/src/SeedStreaming/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/trace/src/SeedTrace/Core/RawClient.cs b/seed/csharp-sdk/trace/src/SeedTrace/Core/RawClient.cs index 2ffd130a237..c55ca12c725 100644 --- a/seed/csharp-sdk/trace/src/SeedTrace/Core/RawClient.cs +++ b/seed/csharp-sdk/trace/src/SeedTrace/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs index f34c47be5b2..67da450d555 100644 --- a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs +++ b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs @@ -20,16 +20,16 @@ public PlaylistClient(RawClient client) /// public async Task CreatePlaylistAsync(int serviceParam, CreatePlaylistRequest request) { - var _query = new Dictionary() - { - { "datetime", request.Datetime.ToString(Constants.DateTimeFormat) }, - }; + var _query = new Dictionary() { }; + _query["datetime"] = request.Datetime.ToString(Constants.DateTimeFormat); + if (request.OptionalDatetime != null) { _query["optionalDatetime"] = request.OptionalDatetime.Value.ToString( Constants.DateTimeFormat ); } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -56,20 +56,20 @@ public async Task> GetPlaylistsAsync( GetPlaylistsRequest request ) { - var _query = new Dictionary() - { - { "otherField", request.OtherField }, - { "multiLineDocs", request.MultiLineDocs }, - { "multipleField", request.MultipleField }, - }; + var _query = new Dictionary() { }; + _query["otherField"] = request.OtherField; + _query["multiLineDocs"] = request.MultiLineDocs; + _query["optionalMultipleField"] = request + .OptionalMultipleField.Where(_value => _value != null) + .Select(_value => _value) + .ToList(); + _query["multipleField"] = request.MultipleField.Select(_value => _value).ToList(); + if (request.Limit != null) { _query["limit"] = request.Limit.ToString(); } - if (request.OptionalMultipleField != null) - { - _query["optionalMultipleField"] = request.OptionalMultipleField; - } + var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs index 6bee16ccf09..0c36a93e921 100644 --- a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs +++ b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs @@ -15,7 +15,7 @@ public record GetPlaylistsRequest /// public required string MultiLineDocs { get; set; } - public string? OptionalMultipleField { get; set; } + public IEnumerable OptionalMultipleField { get; set; } = new List(); - public required string MultipleField { get; set; } + public IEnumerable MultipleField { get; set; } = new List(); } diff --git a/seed/csharp-sdk/undiscriminated-unions/src/SeedUndiscriminatedUnions/Core/RawClient.cs b/seed/csharp-sdk/undiscriminated-unions/src/SeedUndiscriminatedUnions/Core/RawClient.cs index b8e7dd91094..b40b8986ebc 100644 --- a/seed/csharp-sdk/undiscriminated-unions/src/SeedUndiscriminatedUnions/Core/RawClient.cs +++ b/seed/csharp-sdk/undiscriminated-unions/src/SeedUndiscriminatedUnions/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/unions/src/SeedUnions/Core/RawClient.cs b/seed/csharp-sdk/unions/src/SeedUnions/Core/RawClient.cs index 19341c4d6fd..4f4a97d7c82 100644 --- a/seed/csharp-sdk/unions/src/SeedUnions/Core/RawClient.cs +++ b/seed/csharp-sdk/unions/src/SeedUnions/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/unknown/src/SeedUnknownAsAny/Core/RawClient.cs b/seed/csharp-sdk/unknown/src/SeedUnknownAsAny/Core/RawClient.cs index 91110baf3c6..06b6677aef6 100644 --- a/seed/csharp-sdk/unknown/src/SeedUnknownAsAny/Core/RawClient.cs +++ b/seed/csharp-sdk/unknown/src/SeedUnknownAsAny/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/validation/src/SeedValidation/Core/RawClient.cs b/seed/csharp-sdk/validation/src/SeedValidation/Core/RawClient.cs index d94042a2111..d0a3a8583ce 100644 --- a/seed/csharp-sdk/validation/src/SeedValidation/Core/RawClient.cs +++ b/seed/csharp-sdk/validation/src/SeedValidation/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/validation/src/SeedValidation/SeedValidationClient.cs b/seed/csharp-sdk/validation/src/SeedValidation/SeedValidationClient.cs index 216f0b7a2cf..ffd7db995c2 100644 --- a/seed/csharp-sdk/validation/src/SeedValidation/SeedValidationClient.cs +++ b/seed/csharp-sdk/validation/src/SeedValidation/SeedValidationClient.cs @@ -41,12 +41,10 @@ public async Task CreateAsync(CreateRequest request) public async Task GetAsync(GetRequest request) { - var _query = new Dictionary() - { - { "decimal", request.Decimal.ToString() }, - { "even", request.Even.ToString() }, - { "name", request.Name }, - }; + var _query = new Dictionary() { }; + _query["decimal"] = request.Decimal.ToString(); + _query["even"] = request.Even.ToString(); + _query["name"] = request.Name; var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/variables/src/SeedVariables/Core/RawClient.cs b/seed/csharp-sdk/variables/src/SeedVariables/Core/RawClient.cs index 154bca4c4b9..1c25c93cf01 100644 --- a/seed/csharp-sdk/variables/src/SeedVariables/Core/RawClient.cs +++ b/seed/csharp-sdk/variables/src/SeedVariables/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/version-no-default/src/SeedVersion/Core/RawClient.cs b/seed/csharp-sdk/version-no-default/src/SeedVersion/Core/RawClient.cs index db8d12b0d6e..39c0b93a800 100644 --- a/seed/csharp-sdk/version-no-default/src/SeedVersion/Core/RawClient.cs +++ b/seed/csharp-sdk/version-no-default/src/SeedVersion/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/version/src/SeedVersion/Core/RawClient.cs b/seed/csharp-sdk/version/src/SeedVersion/Core/RawClient.cs index db8d12b0d6e..39c0b93a800 100644 --- a/seed/csharp-sdk/version/src/SeedVersion/Core/RawClient.cs +++ b/seed/csharp-sdk/version/src/SeedVersion/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; diff --git a/seed/csharp-sdk/websocket/src/SeedWebsocket/Core/RawClient.cs b/seed/csharp-sdk/websocket/src/SeedWebsocket/Core/RawClient.cs index 6c060ad2cf5..92e62c0cc7b 100644 --- a/seed/csharp-sdk/websocket/src/SeedWebsocket/Core/RawClient.cs +++ b/seed/csharp-sdk/websocket/src/SeedWebsocket/Core/RawClient.cs @@ -121,7 +121,25 @@ private string BuildUrl(BaseApiRequest request) url += "?"; url = request.Query.Aggregate( url, - (current, queryItem) => current + $"{queryItem.Key}={queryItem.Value}&" + (current, queryItem) => + { + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; + } ); url = url.Substring(0, url.Length - 1); return url; From 7512e0ddb885e2429f4e5118e54676726033ab24 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 18:12:46 -0400 Subject: [PATCH 04/10] Drop unused constant --- .../csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts index 41a58622d0d..b8f8001cd6c 100644 --- a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts +++ b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts @@ -28,7 +28,6 @@ export declare namespace WrappedEndpointRequest { } } -const VALUES_LIST_VAR_NAME = "_values"; const QUERY_PARAMETER_BAG_NAME = "_query"; const HEADER_BAG_NAME = "_headers"; From c656a3ee8e625114b63ee8e2221a47e028bdccd9 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 18:21:09 -0400 Subject: [PATCH 05/10] Remove extra spacing --- .../request/WrappedEndpointRequest.ts | 2 -- .../src/SeedAudiences/Foo/FooClient.cs | 2 -- .../SeedEnum/QueryParam/QueryParamClient.cs | 3 --- .../src/SeedExamples/Service/ServiceClient.cs | 2 -- .../SeedFileUpload/Service/ServiceClient.cs | 3 --- .../src/SeedPagination/Users/UsersClient.cs | 20 ------------------- .../SeedQueryParameters/User/UserClient.cs | 4 ---- .../src/SeedTrace/Playlist/PlaylistClient.cs | 4 ---- 8 files changed, 40 deletions(-) diff --git a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts index b8f8001cd6c..aedf0960aff 100644 --- a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts +++ b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts @@ -74,11 +74,9 @@ export class WrappedEndpointRequest extends EndpointRequest { } for (const query of optionalQueryParameters) { const queryParameterReference = `${this.getParameterName()}.${query.name.name.pascalCase.safeName}`; - writer.writeLine(); writer.controlFlow("if", `${queryParameterReference} != null`); this.writeQueryParameter(writer, query); writer.endControlFlow(); - writer.writeLine(); } }), queryParameterBagReference: QUERY_PARAMETER_BAG_NAME diff --git a/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs b/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs index 97556b554b5..ea2cbf462e6 100644 --- a/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs +++ b/seed/csharp-sdk/audiences/src/SeedAudiences/Foo/FooClient.cs @@ -18,12 +18,10 @@ public FooClient(RawClient client) public async Task FindAsync(FindRequest request) { var _query = new Dictionary() { }; - if (request.OptionalString != null) { _query["optionalString"] = request.OptionalString; } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs index c6e1c337e1b..e75032dcba0 100644 --- a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs +++ b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs @@ -21,17 +21,14 @@ public async Task SendAsync(SendEnumAsQueryParamRequest request) var _query = new Dictionary() { }; _query["operand"] = JsonSerializer.Serialize(request.Operand); _query["operandOrColor"] = request.OperandOrColor.ToString(); - if (request.MaybeOperand != null) { _query["maybeOperand"] = JsonSerializer.Serialize(request.MaybeOperand.Value); } - if (request.MaybeOperandOrColor != null) { _query["maybeOperandOrColor"] = request.MaybeOperandOrColor.ToString(); } - await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs b/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs index d2ca02270a7..df5226d57dc 100644 --- a/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs +++ b/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs @@ -59,12 +59,10 @@ public async Task GetMetadataAsync(GetMetadataRequest request) .Tag.Where(_value => _value != null) .Select(_value => _value) .ToList(); - if (request.Shallow != null) { _query["shallow"] = request.Shallow.ToString(); } - var _headers = new Dictionary() { { "X-API-Version", request.XApiVersion }, diff --git a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs index 0c5fb2e2233..a275566e053 100644 --- a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs +++ b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs @@ -48,17 +48,14 @@ public async Task JustFileWithQueryParamsAsync(JustFileWithQueryParamsRequet req .OptionalListOfStrings.Where(_value => _value != null) .Select(_value => _value) .ToList(); - if (request.MaybeString != null) { _query["maybeString"] = request.MaybeString; } - if (request.MaybeInteger != null) { _query["maybeInteger"] = request.MaybeInteger.ToString(); } - await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs b/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs index d1e6471c058..269cb893863 100644 --- a/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs +++ b/seed/csharp-sdk/pagination/src/SeedPagination/Users/UsersClient.cs @@ -21,27 +21,22 @@ ListUsersCursorPaginationRequest request ) { var _query = new Dictionary() { }; - if (request.Page != null) { _query["page"] = request.Page.ToString(); } - if (request.PerPage != null) { _query["per_page"] = request.PerPage.ToString(); } - if (request.Order != null) { _query["order"] = JsonSerializer.Serialize(request.Order.Value); } - if (request.StartingAfter != null) { _query["starting_after"] = request.StartingAfter; } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -85,27 +80,22 @@ ListUsersOffsetPaginationRequest request ) { var _query = new Dictionary() { }; - if (request.Page != null) { _query["page"] = request.Page.ToString(); } - if (request.PerPage != null) { _query["per_page"] = request.PerPage.ToString(); } - if (request.Order != null) { _query["order"] = JsonSerializer.Serialize(request.Order.Value); } - if (request.StartingAfter != null) { _query["starting_after"] = request.StartingAfter; } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -149,22 +139,18 @@ ListUsersOffsetStepPaginationRequest request ) { var _query = new Dictionary() { }; - if (request.Page != null) { _query["page"] = request.Page.ToString(); } - if (request.Limit != null) { _query["limit"] = request.Limit.ToString(); } - if (request.Order != null) { _query["order"] = JsonSerializer.Serialize(request.Order.Value); } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -187,12 +173,10 @@ ListUsersExtendedRequest request ) { var _query = new Dictionary() { }; - if (request.Cursor != null) { _query["cursor"] = request.Cursor.ToString(); } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -213,12 +197,10 @@ ListUsersExtendedRequest request public async Task ListUsernamesAsync(ListUsernamesRequest request) { var _query = new Dictionary() { }; - if (request.StartingAfter != null) { _query["starting_after"] = request.StartingAfter; } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -241,12 +223,10 @@ ListWithGlobalConfigRequest request ) { var _query = new Dictionary() { }; - if (request.Offset != null) { _query["offset"] = request.Offset.ToString(); } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs index 3054a76990b..c5c9c2511ed 100644 --- a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs +++ b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs @@ -29,24 +29,20 @@ public async Task GetUsernameAsync(GetUsersRequest request) _query["nestedUser"] = request.NestedUser.ToString(); _query["excludeUser"] = request.ExcludeUser.Select(_value => _value.ToString()).ToList(); _query["filter"] = request.Filter.Select(_value => _value).ToList(); - if (request.OptionalDeadline != null) { _query["optionalDeadline"] = request.OptionalDeadline.Value.ToString( Constants.DateTimeFormat ); } - if (request.OptionalString != null) { _query["optionalString"] = request.OptionalString; } - if (request.OptionalUser != null) { _query["optionalUser"] = request.OptionalUser.ToString(); } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { diff --git a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs index 67da450d555..4571ef92bdb 100644 --- a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs +++ b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs @@ -22,14 +22,12 @@ public async Task CreatePlaylistAsync(int serviceParam, CreatePlaylist { var _query = new Dictionary() { }; _query["datetime"] = request.Datetime.ToString(Constants.DateTimeFormat); - if (request.OptionalDatetime != null) { _query["optionalDatetime"] = request.OptionalDatetime.Value.ToString( Constants.DateTimeFormat ); } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { @@ -64,12 +62,10 @@ GetPlaylistsRequest request .Select(_value => _value) .ToList(); _query["multipleField"] = request.MultipleField.Select(_value => _value).ToList(); - if (request.Limit != null) { _query["limit"] = request.Limit.ToString(); } - var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { From bf2c93d41e3be945b11641bc1977f7b38b086cf4 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 19:07:54 -0400 Subject: [PATCH 06/10] Drop redundant .Select(...) calls --- .../csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts index aedf0960aff..470b79c9c34 100644 --- a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts +++ b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts @@ -90,6 +90,10 @@ export class WrappedEndpointRequest extends EndpointRequest { return; } const queryParameterReference = `${this.getParameterName()}.${query.name.name.pascalCase.safeName}`; + if (this.isString(query.valueType)) { + writer.writeLine(`${queryParameterReference};`); + return; + } const maybeOptionalCheck = this.context.isOptional(query.valueType) ? ".Where(_value => _value != null)" : ""; writer.write(`${queryParameterReference}${maybeOptionalCheck}.Select(_value => `); writer.writeNode( From 3f9fdcd0f0660a364718f2933917d5e51b3b47c0 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 19:16:32 -0400 Subject: [PATCH 07/10] allow-multiple query parameters are non-optional --- .../src/wrapped-request/WrappedRequestGenerator.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts b/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts index a0e370e6f8e..45c1c5e5c93 100644 --- a/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts +++ b/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts @@ -46,10 +46,11 @@ export class WrappedRequestGenerator extends FileGenerator { orderedFields.push({ name: this.wrapper.bodyKey, value: reference }); From 7c7311881cb204023b56143c63ce4baef5b1657b Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 19:29:04 -0400 Subject: [PATCH 08/10] Drop unnecessary .Where(...) filter --- .../request/WrappedEndpointRequest.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts index 470b79c9c34..a6054d4c993 100644 --- a/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts +++ b/generators/csharp/sdk/src/endpoint/request/WrappedEndpointRequest.ts @@ -94,10 +94,14 @@ export class WrappedEndpointRequest extends EndpointRequest { writer.writeLine(`${queryParameterReference};`); return; } - const maybeOptionalCheck = this.context.isOptional(query.valueType) ? ".Where(_value => _value != null)" : ""; - writer.write(`${queryParameterReference}${maybeOptionalCheck}.Select(_value => `); + writer.write(`${queryParameterReference}.Select(_value => `); writer.writeNode( - this.stringify({ reference: query.valueType, name: query.name.name, parameterOverride: "_value" }) + this.stringify({ + reference: query.valueType, + name: query.name.name, + parameterOverride: "_value", + allowOptionals: false // When allow-multiple is set, the query parameter never uses optional types. + }) ); writer.writeLine(").ToList();"); } @@ -160,28 +164,30 @@ export class WrappedEndpointRequest extends EndpointRequest { private stringify({ reference, name, - parameterOverride + parameterOverride, + allowOptionals }: { reference: TypeReference; name: Name; parameterOverride?: string; + allowOptionals?: boolean; }): csharp.CodeBlock { const parameter = parameterOverride ?? `${this.getParameterName()}.${name.pascalCase.safeName}`; if (this.isString(reference)) { return csharp.codeblock(`${parameter}`); - } else if (this.isDatetime({ typeReference: reference, allowOptionals: false })) { + } else if (this.isDatetime({ typeReference: reference, allowOptionals: allowOptionals ?? false })) { return csharp.codeblock((writer) => { writer.write(`${parameter}.ToString(`); writer.writeNode(this.context.getConstantsClassReference()); writer.write(".DateTimeFormat)"); }); - } else if (this.isDatetime({ typeReference: reference, allowOptionals: true })) { + } else if (this.isDatetime({ typeReference: reference, allowOptionals: allowOptionals ?? true })) { return csharp.codeblock((writer) => { writer.write(`${parameter}.Value.ToString(`); writer.writeNode(this.context.getConstantsClassReference()); writer.write(".DateTimeFormat)"); }); - } else if (this.isEnum({ typeReference: reference, allowOptionals: false })) { + } else if (this.isEnum({ typeReference: reference, allowOptionals: allowOptionals ?? false })) { return csharp.codeblock((writer) => { writer.writeNode( csharp.classReference({ @@ -191,7 +197,7 @@ export class WrappedEndpointRequest extends EndpointRequest { ); writer.write(`.Serialize(${parameter})`); }); - } else if (this.isEnum({ typeReference: reference, allowOptionals: true })) { + } else if (this.isEnum({ typeReference: reference, allowOptionals: allowOptionals ?? true })) { return csharp.codeblock((writer) => { writer.writeNode( csharp.classReference({ From 3b1119f1c359cdc86c87e7b08b0fd9be36e1b0e9 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 19:33:07 -0400 Subject: [PATCH 09/10] Update snapshots --- .../enum/src/SeedEnum/QueryParam/QueryParamClient.cs | 8 ++------ .../Requests/SendEnumListAsQueryParamRequest.cs | 6 +++--- .../SeedExamples/Service/Requests/GetMetadataRequest.cs | 2 +- .../examples/src/SeedExamples/Service/ServiceClient.cs | 5 +---- .../src/SeedExhaustive/Endpoints/Params/ParamsClient.cs | 2 +- .../Service/Requests/JustFileWithQueryParamsRequet.cs | 2 +- .../src/SeedFileUpload/Service/ServiceClient.cs | 7 ++----- .../src/SeedQueryParameters/User/UserClient.cs | 2 +- .../trace/src/SeedTrace/Playlist/PlaylistClient.cs | 7 ++----- .../SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs | 2 +- 10 files changed, 15 insertions(+), 28 deletions(-) diff --git a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs index e75032dcba0..97f3ae11366 100644 --- a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs +++ b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/QueryParamClient.cs @@ -46,16 +46,12 @@ public async Task SendListAsync(SendEnumListAsQueryParamRequest request) _query["operand"] = request .Operand.Select(_value => JsonSerializer.Serialize(_value)) .ToList(); - _query["maybeOperand"] = request - .MaybeOperand.Where(_value => _value != null) - .Select(_value => JsonSerializer.Serialize(_value.Value)) - .ToList(); + _query["maybeOperand"] = request.MaybeOperand.Select(_value => _value.ToString()).ToList(); _query["operandOrColor"] = request .OperandOrColor.Select(_value => _value.ToString()) .ToList(); _query["maybeOperandOrColor"] = request - .MaybeOperandOrColor.Where(_value => _value != null) - .Select(_value => _value.ToString()) + .MaybeOperandOrColor.Select(_value => _value.ToString()) .ToList(); await _client.MakeRequestAsync( new RawClient.JsonApiRequest diff --git a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs index 8a03f85b65c..8e2ed786c06 100644 --- a/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs +++ b/seed/csharp-sdk/enum/src/SeedEnum/QueryParam/Requests/SendEnumListAsQueryParamRequest.cs @@ -9,11 +9,11 @@ public record SendEnumListAsQueryParamRequest { public IEnumerable Operand { get; set; } = new List(); - public IEnumerable MaybeOperand { get; set; } = new List(); + public IEnumerable MaybeOperand { get; set; } = new List(); public IEnumerable> OperandOrColor { get; set; } = new List>(); - public IEnumerable?> MaybeOperandOrColor { get; set; } = - new List?>(); + public IEnumerable> MaybeOperandOrColor { get; set; } = + new List>(); } diff --git a/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs b/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs index f4f50a3c613..8aebecdad03 100644 --- a/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs +++ b/seed/csharp-sdk/examples/src/SeedExamples/Service/Requests/GetMetadataRequest.cs @@ -4,7 +4,7 @@ public record GetMetadataRequest { public bool? Shallow { get; set; } - public IEnumerable Tag { get; set; } = new List(); + public IEnumerable Tag { get; set; } = new List(); public required string XApiVersion { get; set; } } diff --git a/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs b/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs index df5226d57dc..d8229505053 100644 --- a/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs +++ b/seed/csharp-sdk/examples/src/SeedExamples/Service/ServiceClient.cs @@ -55,10 +55,7 @@ public async Task CreateMovieAsync(Movie request) public async Task GetMetadataAsync(GetMetadataRequest request) { var _query = new Dictionary() { }; - _query["tag"] = request - .Tag.Where(_value => _value != null) - .Select(_value => _value) - .ToList(); + _query["tag"] = request.Tag; if (request.Shallow != null) { _query["shallow"] = request.Shallow.ToString(); diff --git a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs index ce58a379afc..85bffe16634 100644 --- a/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs +++ b/seed/csharp-sdk/exhaustive/explicit-namespaces/src/SeedExhaustive/Endpoints/Params/ParamsClient.cs @@ -61,7 +61,7 @@ await _client.MakeRequestAsync( public async Task GetWithAllowMultipleQueryAsync(GetWithMultipleQuery request) { var _query = new Dictionary() { }; - _query["query"] = request.Query.Select(_value => _value).ToList(); + _query["query"] = request.Query; _query["numer"] = request.Numer.Select(_value => _value.ToString()).ToList(); await _client.MakeRequestAsync( new RawClient.JsonApiRequest diff --git a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs index 1da100f537a..633c399418e 100644 --- a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs +++ b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/Requests/JustFileWithQueryParamsRequet.cs @@ -10,5 +10,5 @@ public record JustFileWithQueryParamsRequet public IEnumerable ListOfStrings { get; set; } = new List(); - public IEnumerable OptionalListOfStrings { get; set; } = new List(); + public IEnumerable OptionalListOfStrings { get; set; } = new List(); } diff --git a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs index a275566e053..d324b854db5 100644 --- a/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs +++ b/seed/csharp-sdk/file-upload/src/SeedFileUpload/Service/ServiceClient.cs @@ -43,11 +43,8 @@ public async Task JustFileWithQueryParamsAsync(JustFileWithQueryParamsRequet req { var _query = new Dictionary() { }; _query["integer"] = request.Integer.ToString(); - _query["listOfStrings"] = request.ListOfStrings.Select(_value => _value).ToList(); - _query["optionalListOfStrings"] = request - .OptionalListOfStrings.Where(_value => _value != null) - .Select(_value => _value) - .ToList(); + _query["listOfStrings"] = request.ListOfStrings; + _query["optionalListOfStrings"] = request.OptionalListOfStrings; if (request.MaybeString != null) { _query["maybeString"] = request.MaybeString; diff --git a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs index c5c9c2511ed..46a94494eaf 100644 --- a/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs +++ b/seed/csharp-sdk/query-parameters/src/SeedQueryParameters/User/UserClient.cs @@ -28,7 +28,7 @@ public async Task GetUsernameAsync(GetUsersRequest request) _query["keyValue"] = request.KeyValue.ToString(); _query["nestedUser"] = request.NestedUser.ToString(); _query["excludeUser"] = request.ExcludeUser.Select(_value => _value.ToString()).ToList(); - _query["filter"] = request.Filter.Select(_value => _value).ToList(); + _query["filter"] = request.Filter; if (request.OptionalDeadline != null) { _query["optionalDeadline"] = request.OptionalDeadline.Value.ToString( diff --git a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs index 4571ef92bdb..f6cb2e0afe2 100644 --- a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs +++ b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/PlaylistClient.cs @@ -57,11 +57,8 @@ GetPlaylistsRequest request var _query = new Dictionary() { }; _query["otherField"] = request.OtherField; _query["multiLineDocs"] = request.MultiLineDocs; - _query["optionalMultipleField"] = request - .OptionalMultipleField.Where(_value => _value != null) - .Select(_value => _value) - .ToList(); - _query["multipleField"] = request.MultipleField.Select(_value => _value).ToList(); + _query["optionalMultipleField"] = request.OptionalMultipleField; + _query["multipleField"] = request.MultipleField; if (request.Limit != null) { _query["limit"] = request.Limit.ToString(); diff --git a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs index 0c36a93e921..98e02608d75 100644 --- a/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs +++ b/seed/csharp-sdk/trace/src/SeedTrace/Playlist/Requests/GetPlaylistsRequest.cs @@ -15,7 +15,7 @@ public record GetPlaylistsRequest /// public required string MultiLineDocs { get; set; } - public IEnumerable OptionalMultipleField { get; set; } = new List(); + public IEnumerable OptionalMultipleField { get; set; } = new List(); public IEnumerable MultipleField { get; set; } = new List(); } From f94db0c182eb0da952472b35b2355bea6ce4e312 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 30 Jul 2024 19:40:23 -0400 Subject: [PATCH 10/10] Restore example endpoint headers --- .../csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts b/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts index 45c1c5e5c93..87e489dbe97 100644 --- a/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts +++ b/generators/csharp/sdk/src/wrapped-request/WrappedRequestGenerator.ts @@ -142,6 +142,10 @@ export class WrappedRequestGenerator extends FileGenerator { orderedFields.push({ name: this.wrapper.bodyKey, value: reference });