Skip to content

Commit ee6c043

Browse files
authored
fix(clients): remove all client side validation expect null check (#3936)
1 parent 33565ee commit ee6c043

File tree

13 files changed

+9
-466
lines changed

13 files changed

+9
-466
lines changed

clients/algoliasearch-client-swift/Sources/Core/Helpers/Validation.swift

Lines changed: 0 additions & 150 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void processOpts() {
4646
additionalProperties.put("netCoreProjectFile", true);
4747
additionalProperties.put("targetFramework", "netstandard2.1;netstandard2.0");
4848
additionalProperties.put("isSearchClient", CLIENT.equals("search"));
49-
additionalProperties.put("validatable", false);
5049
additionalProperties.put("apiPackageName", getClientName(CLIENT));
5150
additionalProperties.put("equatable", false);
5251
additionalProperties.put("disallowAdditionalPropertiesIfNotPresent", true);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public void processOpts() {
183183
additionalProperties.put(SWIFT_PACKAGE_PATH, "Sources" + File.separator + getClientName(CLIENT));
184184
additionalProperties.put(OBJC_COMPATIBLE, false);
185185
additionalProperties.put(USE_BACKTICK_ESCAPES, true);
186-
additionalProperties.put(VALIDATABLE, false);
187186
additionalProperties.put("hashableModels", true);
188187

189188
additionalProperties.put("lambda.type-to-name", (Mustache.Lambda) (fragment, writer) -> writer.write(typeToName(fragment.execute())));

scripts/pre-gen/removeExistingCodegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function removeExistingCodegen({ language, client, output }: Genera
6666
baseApiFolder = 'algoliasearch';
6767
break;
6868
case 'ruby':
69-
clientModel = clientName.toLowerCase();
69+
clientModel = client;
7070
clientApi = `${toSnakeCase(clientName)}_client.rb`;
7171
break;
7272
case 'scala':

templates/csharp/modelOneOf.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{{^vendorExtensions.x-has-child-generic}}
1212
[JsonConverter(typeof({{classname}}JsonConverter))]
1313
{{/vendorExtensions.x-has-child-generic}}
14-
{{> visibility}} partial class {{classname}}{{#vendorExtensions.x-has-child-generic}}<T>{{/vendorExtensions.x-has-child-generic}} : {{#lambda.joinWithComma}}AbstractSchema {{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
14+
{{> visibility}} partial class {{classname}}{{#vendorExtensions.x-has-child-generic}}<T>{{/vendorExtensions.x-has-child-generic}} : {{#lambda.joinWithComma}}AbstractSchema {{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{/lambda.joinWithComma}}
1515
{
1616
{{#isNullable}}
1717
/// <summary>

templates/go/api.mustache

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -378,40 +378,6 @@ func (c *APIClient) {{nickname}}WithHTTPInfo({{#hasParams}}r {{#structPrefix}}{{
378378
if r.{{paramName}} == nil {
379379
return nil, nil, reportError("Parameter `{{paramName}}` is required when calling `{{operationId}}`.")
380380
}{{/isEnumRef}}{{/isMap}}{{/isContainer}}{{/isPrimitiveType}}
381-
{{#minItems}}
382-
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) < {{minItems}} {
383-
return nil, nil, reportError("{{paramName}} must have at least {{minItems}} elements")
384-
}
385-
{{/minItems}}
386-
{{#maxItems}}
387-
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) > {{maxItems}} {
388-
return nil, nil, reportError("{{paramName}} must have less than {{maxItems}} elements")
389-
}
390-
{{/maxItems}}
391-
{{#minLength}}
392-
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) < {{minLength}} {
393-
return nil, nil, reportError("{{paramName}} must have at least {{minLength}} elements")
394-
}
395-
{{/minLength}}
396-
{{#maxLength}}
397-
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) > {{maxLength}} {
398-
return nil, nil, reportError("{{paramName}} must have less than {{maxLength}} elements")
399-
}
400-
{{/maxLength}}
401-
{{#minimum}}
402-
{{^isString}}
403-
if {{^isPathParam}}*{{/isPathParam}}r.{{paramName}} < {{minimum}} {
404-
{{/isString}}
405-
return nil, nil, reportError("{{paramName}} must be greater than {{minimum}}")
406-
}
407-
{{/minimum}}
408-
{{#maximum}}
409-
{{^isString}}
410-
if {{^isPathParam}}*{{/isPathParam}}r.{{paramName}} > {{maximum}} {
411-
{{/isString}}
412-
return nil, nil, reportError("{{paramName}} must be less than {{maximum}}")
413-
}
414-
{{/maximum}}
415381
{{/required}}
416382
{{/allParams}}
417383

templates/php/api.mustache

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -214,44 +214,6 @@ use Algolia\AlgoliaSearch\Exceptions\NotFoundException;
214214
);
215215
}
216216
{{/required}}
217-
{{#hasValidation}}
218-
{{#maxLength}}
219-
if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) > {{maxLength}}) {
220-
throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.');
221-
}
222-
{{/maxLength}}
223-
{{#minLength}}
224-
if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) < {{minLength}}) {
225-
throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.');
226-
}
227-
{{/minLength}}
228-
{{#maximum}}
229-
if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) {
230-
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.');
231-
}
232-
{{/maximum}}
233-
{{#minimum}}
234-
if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) {
235-
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.');
236-
}
237-
{{/minimum}}
238-
{{#pattern}}
239-
if ({{^required}}${{paramName}} !== null && {{/required}}!preg_match("{{{pattern}}}", ${{paramName}})) {
240-
throw new \InvalidArgumentException("invalid value for \"{{paramName}}\" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
241-
}
242-
{{/pattern}}
243-
{{#maxItems}}
244-
if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) > {{maxItems}}) {
245-
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.');
246-
}
247-
{{/maxItems}}
248-
{{#minItems}}
249-
if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) < {{minItems}}) {
250-
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.');
251-
}
252-
{{/minItems}}
253-
254-
{{/hasValidation}}
255217
{{/allParams}}
256218

257219
$resourcePath = '{{{path}}}';

templates/php/model_generic.mustache

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -178,50 +178,6 @@ class {{classname}} extends AbstractModel implements ModelInterface, \ArrayAcces
178178

179179
{{/isContainer}}
180180
{{/isEnum}}
181-
{{#hasValidation}}
182-
{{#maxLength}}
183-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(mb_strlen($this->container['{{name}}']) > {{maxLength}})) {
184-
$invalidProperties[] = "invalid value for '{{name}}', the character length must be smaller than or equal to {{{maxLength}}}.";
185-
}
186-
187-
{{/maxLength}}
188-
{{#minLength}}
189-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(mb_strlen($this->container['{{name}}']) < {{minLength}})) {
190-
$invalidProperties[] = "invalid value for '{{name}}', the character length must be bigger than or equal to {{{minLength}}}.";
191-
}
192-
193-
{{/minLength}}
194-
{{#maximum}}
195-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}($this->container['{{name}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}})) {
196-
$invalidProperties[] = "invalid value for '{{name}}', must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.";
197-
}
198-
199-
{{/maximum}}
200-
{{#minimum}}
201-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}($this->container['{{name}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}})) {
202-
$invalidProperties[] = "invalid value for '{{name}}', must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.";
203-
}
204-
205-
{{/minimum}}
206-
{{#pattern}}
207-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}!preg_match("{{{pattern}}}", $this->container['{{name}}'])) {
208-
$invalidProperties[] = "invalid value for '{{name}}', must be conform to the pattern {{{pattern}}}.";
209-
}
210-
211-
{{/pattern}}
212-
{{#maxItems}}
213-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(count($this->container['{{name}}']) > {{maxItems}})) {
214-
$invalidProperties[] = "invalid value for '{{name}}', number of items must be less than or equal to {{{maxItems}}}.";
215-
}
216-
217-
{{/maxItems}}
218-
{{#minItems}}
219-
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(count($this->container['{{name}}']) < {{minItems}})) {
220-
$invalidProperties[] = "invalid value for '{{name}}', number of items must be greater than or equal to {{{minItems}}}.";
221-
}
222-
223-
{{/minItems}}
224-
{{/hasValidation}}
225181
{{/vars}}
226182
return $invalidProperties;
227183
}
@@ -288,41 +244,6 @@ class {{classname}} extends AbstractModel implements ModelInterface, \ArrayAcces
288244
}
289245
{{/isContainer}}
290246
{{/isEnum}}
291-
{{#hasValidation}}
292-
{{#maxLength}}
293-
if ({{^required}}!is_null(${{name}}) && {{/required}}(mb_strlen(${{name}}) > {{maxLength}})) {
294-
throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.');
295-
}{{/maxLength}}
296-
{{#minLength}}
297-
if ({{^required}}!is_null(${{name}}) && {{/required}}(mb_strlen(${{name}}) < {{minLength}})) {
298-
throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.');
299-
}
300-
{{/minLength}}
301-
{{#maximum}}
302-
if ({{^required}}!is_null(${{name}}) && {{/required}}(${{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}})) {
303-
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.');
304-
}
305-
{{/maximum}}
306-
{{#minimum}}
307-
if ({{^required}}!is_null(${{name}}) && {{/required}}(${{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}})) {
308-
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.');
309-
}
310-
{{/minimum}}
311-
{{#pattern}}
312-
if ({{^required}}!is_null(${{name}}) && {{/required}}(!preg_match("{{{pattern}}}", ${{name}}))) {
313-
throw new \InvalidArgumentException("invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
314-
}
315-
{{/pattern}}
316-
{{#maxItems}}
317-
if ({{^required}}!is_null(${{name}}) && {{/required}}(count(${{name}}) > {{maxItems}})) {
318-
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.');
319-
}{{/maxItems}}
320-
{{#minItems}}
321-
if ({{^required}}!is_null(${{name}}) && {{/required}}(count(${{name}}) < {{minItems}})) {
322-
throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.');
323-
}
324-
{{/minItems}}
325-
{{/hasValidation}}
326247
$this->container['{{name}}'] = ${{name}};
327248

328249
return $this;

0 commit comments

Comments
 (0)