Skip to content

Commit 0afa8fe

Browse files
committed
fix csharp
1 parent 3f5d168 commit 0afa8fe

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919

2020
public class AlgoliaCSharpGenerator extends CSharpClientCodegen {
2121

22-
// This is used for the CTS generation
23-
private static final AlgoliaCSharpGenerator INSTANCE = new AlgoliaCSharpGenerator();
24-
25-
public AlgoliaCSharpGenerator() {
26-
super();
27-
reservedWords.add("source");
28-
}
29-
30-
/** Convert a text to a valid csharp identifier. */
31-
public static String formatIdentifier(String text) {
32-
return INSTANCE.escapeReservedWord(text);
33-
}
34-
3522
private String CLIENT;
3623

3724
@Override
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.algolia.codegen.cts.lambda;
22

3-
import com.algolia.codegen.AlgoliaCSharpGenerator;
43
import com.samskivert.mustache.Mustache;
54
import com.samskivert.mustache.Template;
65
import java.io.IOException;
@@ -11,7 +10,12 @@ public class CSharpIdentifierLambda implements Mustache.Lambda {
1110
@Override
1211
public void execute(Template.Fragment frag, Writer out) throws IOException {
1312
String text = frag.execute();
14-
var formatted = AlgoliaCSharpGenerator.formatIdentifier(text);
15-
out.write(formatted);
13+
if (text.equals("source")) {
14+
out.write("varSource");
15+
16+
return;
17+
}
18+
19+
out.write(text);
1620
}
1721
}

scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ _apic_format_complete() {
8484
if [[ COMP_CWORD -eq 2 ]]; then
8585
COMPREPLY=($(compgen -W "$(_list_languages)" -- "$cur"))
8686
elif [[ COMP_CWORD -eq 3 ]]; then
87-
COMPREPLY=($(compgen -d -- "$cur"))
87+
COMPREPLY=($(compgen -d -S / -- "$cur"))
8888
fi
8989
}
9090

templates/csharp/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Algolia.Search.Clients;
4040
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
4141
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
4242
/// <returns>Task of {{> return_type_doc}}</returns>
43-
Task{{#returnType}}<{{> return_type}}>{{/returnType}} {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default);
43+
Task{{#returnType}}<{{> return_type}}>{{/returnType}} {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default);
4444

4545
/// <summary>
4646
/// {{{notes}}} (Synchronous version)
@@ -57,7 +57,7 @@ namespace Algolia.Search.Clients;
5757
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
5858
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
5959
/// <returns>{{> return_type_doc}}</returns>
60-
{{^returnType}}void{{/returnType}}{{#returnType}}{{> return_type}}{{/returnType}} {{operationId}}{{#returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default);
60+
{{^returnType}}void{{/returnType}}{{#returnType}}{{> return_type}}{{/returnType}} {{operationId}}{{#returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default);
6161

6262
{{/operation}}
6363
}
@@ -152,7 +152,7 @@ namespace Algolia.Search.Clients;
152152
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
153153
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
154154
/// <returns>Task of {{> return_type_doc}}</returns>
155-
public async Task{{#returnType}}<{{> return_type}}>{{/returnType}} {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default)
155+
public async Task{{#returnType}}<{{> return_type}}>{{/returnType}} {{operationId}}Async{{#returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{/returnType}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default)
156156
{
157157
{{#allParams}}
158158
{{#required}}
@@ -246,7 +246,7 @@ namespace Algolia.Search.Clients;
246246
/// <exception cref="Algolia.Search.Exceptions.AlgoliaApiException">Thrown when the API call was rejected by Algolia</exception>
247247
/// <exception cref="Algolia.Search.Exceptions.AlgoliaUnreachableHostException">Thrown when the client failed to call the endpoint</exception>
248248
/// <returns>{{> return_type_doc}}</returns>
249-
public {{^returnType}}void{{/returnType}}{{#returnType}}{{> return_type}}{{/returnType}} {{operationId}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}({{#allParams}}{{{dataType}}}{{#isEnumRef}}{{^required}}?{{/required}}{{/isEnumRef}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default) =>
249+
public {{^returnType}}void{{/returnType}}{{#returnType}}{{> return_type}}{{/returnType}} {{operationId}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default{{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}RequestOptions options = null, CancellationToken cancellationToken = default) =>
250250
AsyncHelper.RunSync(() => {{operationId}}Async{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}} options, cancellationToken));
251251

252252
{{/supportsAsync}}

templates/csharp/modelGeneric.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,36 +126,36 @@
126126
/// </summary>
127127
{{#readWriteVars}}
128128
{{#required}}
129-
/// <param name="{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}">{{description}}{{^description}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{.}}){{/defaultValue}}.</param>
129+
/// <param name="{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}">{{description}}{{^description}}{{nameInCamelCase}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{.}}){{/defaultValue}}.</param>
130130
{{/required}}
131131
{{/readWriteVars}}
132132
{{#hasOnlyReadOnly}}
133133
[JsonConstructor]
134134
{{/hasOnlyReadOnly}}
135-
public {{classname}}({{#requiredVars}}{{> generic_type}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{^-last}}, {{/-last}}{{/requiredVars}}){{#parent}} : base({{#parentVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{^-last}}, {{/-last}}{{/parentVars}}){{/parent}}
135+
public {{classname}}({{#requiredVars}}{{> generic_type}} {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}{{^-last}}, {{/-last}}{{/requiredVars}}){{#parent}} : base({{#parentVars}}{{nameInCamelCase}}{{^-last}}, {{/-last}}{{/parentVars}}){{/parent}}
136136
{
137137
{{#vars}}
138138
{{^isInherited}}
139139
{{^isReadOnly}}
140140
{{#required}}
141141
{{^conditionalSerialization}}
142142
{{^vendorExtensions.x-csharp-value-type}}
143-
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? throw new ArgumentNullException(nameof({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}));
143+
{{name}} = {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} ?? throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}));
144144
{{/vendorExtensions.x-csharp-value-type}}
145145
{{#vendorExtensions.x-csharp-value-type}}
146-
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
146+
{{name}} = {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}};
147147
{{/vendorExtensions.x-csharp-value-type}}
148148
{{/conditionalSerialization}}
149149
{{#conditionalSerialization}}
150150
{{^vendorExtensions.x-csharp-value-type}}
151-
if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} == null)
151+
if ({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} == null)
152152
{
153-
throw new ArgumentNullException(nameof({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}));
153+
throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}));
154154
}
155-
_{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
155+
_{{name}} = {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}};
156156
{{/vendorExtensions.x-csharp-value-type}}
157157
{{#vendorExtensions.x-csharp-value-type}}
158-
_{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
158+
_{{name}} = {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}};
159159
{{/vendorExtensions.x-csharp-value-type}}
160160
{{/conditionalSerialization}}
161161
{{/required}}

tests/output/csharp/src/ClientExtensionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public async Task ShouldBrowseObjects()
164164
Page = 0,
165165
ProcessingTimeMS = 1,
166166
Query = "",
167-
VarParams = ""
167+
Params = ""
168168
}
169169
)
170170
)
@@ -191,7 +191,7 @@ public async Task ShouldBrowseObjects()
191191
Page = 0,
192192
ProcessingTimeMS = 1,
193193
Query = "",
194-
VarParams = ""
194+
Params = ""
195195
}
196196
)
197197
)
@@ -218,7 +218,7 @@ public async Task ShouldBrowseObjects()
218218
Page = 0,
219219
ProcessingTimeMS = 1,
220220
Query = "",
221-
VarParams = ""
221+
Params = ""
222222
}
223223
)
224224
)

tests/output/csharp/src/RetryStrategyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public async Task CanOverrideHost()
160160
ProcessingTimeMS = 1,
161161
Hits = new List<object>(),
162162
Query = "",
163-
VarParams = ""
163+
Params = ""
164164
},
165165
JsonConfig.Options
166166
)

0 commit comments

Comments
 (0)