Skip to content

Commit

Permalink
fix(clients): remove all client side validation expect null check (#3936
Browse files Browse the repository at this point in the history
)
  • Loading branch information
millotp authored Oct 9, 2024
1 parent 33565ee commit ee6c043
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 466 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void processOpts() {
additionalProperties.put("netCoreProjectFile", true);
additionalProperties.put("targetFramework", "netstandard2.1;netstandard2.0");
additionalProperties.put("isSearchClient", CLIENT.equals("search"));
additionalProperties.put("validatable", false);
additionalProperties.put("apiPackageName", getClientName(CLIENT));
additionalProperties.put("equatable", false);
additionalProperties.put("disallowAdditionalPropertiesIfNotPresent", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public void processOpts() {
additionalProperties.put(SWIFT_PACKAGE_PATH, "Sources" + File.separator + getClientName(CLIENT));
additionalProperties.put(OBJC_COMPATIBLE, false);
additionalProperties.put(USE_BACKTICK_ESCAPES, true);
additionalProperties.put(VALIDATABLE, false);
additionalProperties.put("hashableModels", true);

additionalProperties.put("lambda.type-to-name", (Mustache.Lambda) (fragment, writer) -> writer.write(typeToName(fragment.execute())));
Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-gen/removeExistingCodegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function removeExistingCodegen({ language, client, output }: Genera
baseApiFolder = 'algoliasearch';
break;
case 'ruby':
clientModel = clientName.toLowerCase();
clientModel = client;
clientApi = `${toSnakeCase(clientName)}_client.rb`;
break;
case 'scala':
Expand Down
2 changes: 1 addition & 1 deletion templates/csharp/modelOneOf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{^vendorExtensions.x-has-child-generic}}
[JsonConverter(typeof({{classname}}JsonConverter))]
{{/vendorExtensions.x-has-child-generic}}
{{> 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}}
{{> 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}}
{
{{#isNullable}}
/// <summary>
Expand Down
34 changes: 0 additions & 34 deletions templates/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -378,40 +378,6 @@ func (c *APIClient) {{nickname}}WithHTTPInfo({{#hasParams}}r {{#structPrefix}}{{
if r.{{paramName}} == nil {
return nil, nil, reportError("Parameter `{{paramName}}` is required when calling `{{operationId}}`.")
}{{/isEnumRef}}{{/isMap}}{{/isContainer}}{{/isPrimitiveType}}
{{#minItems}}
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) < {{minItems}} {
return nil, nil, reportError("{{paramName}} must have at least {{minItems}} elements")
}
{{/minItems}}
{{#maxItems}}
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) > {{maxItems}} {
return nil, nil, reportError("{{paramName}} must have less than {{maxItems}} elements")
}
{{/maxItems}}
{{#minLength}}
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) < {{minLength}} {
return nil, nil, reportError("{{paramName}} must have at least {{minLength}} elements")
}
{{/minLength}}
{{#maxLength}}
if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) > {{maxLength}} {
return nil, nil, reportError("{{paramName}} must have less than {{maxLength}} elements")
}
{{/maxLength}}
{{#minimum}}
{{^isString}}
if {{^isPathParam}}*{{/isPathParam}}r.{{paramName}} < {{minimum}} {
{{/isString}}
return nil, nil, reportError("{{paramName}} must be greater than {{minimum}}")
}
{{/minimum}}
{{#maximum}}
{{^isString}}
if {{^isPathParam}}*{{/isPathParam}}r.{{paramName}} > {{maximum}} {
{{/isString}}
return nil, nil, reportError("{{paramName}} must be less than {{maximum}}")
}
{{/maximum}}
{{/required}}
{{/allParams}}

Expand Down
38 changes: 0 additions & 38 deletions templates/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -214,44 +214,6 @@ use Algolia\AlgoliaSearch\Exceptions\NotFoundException;
);
}
{{/required}}
{{#hasValidation}}
{{#maxLength}}
if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) > {{maxLength}}) {
throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.');
}
{{/maxLength}}
{{#minLength}}
if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) < {{minLength}}) {
throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.');
}
{{/minLength}}
{{#maximum}}
if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) {
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.');
}
{{/maximum}}
{{#minimum}}
if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) {
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.');
}
{{/minimum}}
{{#pattern}}
if ({{^required}}${{paramName}} !== null && {{/required}}!preg_match("{{{pattern}}}", ${{paramName}})) {
throw new \InvalidArgumentException("invalid value for \"{{paramName}}\" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
}
{{/pattern}}
{{#maxItems}}
if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) > {{maxItems}}) {
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.');
}
{{/maxItems}}
{{#minItems}}
if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) < {{minItems}}) {
throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.');
}
{{/minItems}}

{{/hasValidation}}
{{/allParams}}

$resourcePath = '{{{path}}}';
Expand Down
79 changes: 0 additions & 79 deletions templates/php/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -178,50 +178,6 @@ class {{classname}} extends AbstractModel implements ModelInterface, \ArrayAcces

{{/isContainer}}
{{/isEnum}}
{{#hasValidation}}
{{#maxLength}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(mb_strlen($this->container['{{name}}']) > {{maxLength}})) {
$invalidProperties[] = "invalid value for '{{name}}', the character length must be smaller than or equal to {{{maxLength}}}.";
}

{{/maxLength}}
{{#minLength}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(mb_strlen($this->container['{{name}}']) < {{minLength}})) {
$invalidProperties[] = "invalid value for '{{name}}', the character length must be bigger than or equal to {{{minLength}}}.";
}

{{/minLength}}
{{#maximum}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}($this->container['{{name}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}})) {
$invalidProperties[] = "invalid value for '{{name}}', must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.";
}

{{/maximum}}
{{#minimum}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}($this->container['{{name}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}})) {
$invalidProperties[] = "invalid value for '{{name}}', must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.";
}

{{/minimum}}
{{#pattern}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}!preg_match("{{{pattern}}}", $this->container['{{name}}'])) {
$invalidProperties[] = "invalid value for '{{name}}', must be conform to the pattern {{{pattern}}}.";
}

{{/pattern}}
{{#maxItems}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(count($this->container['{{name}}']) > {{maxItems}})) {
$invalidProperties[] = "invalid value for '{{name}}', number of items must be less than or equal to {{{maxItems}}}.";
}

{{/maxItems}}
{{#minItems}}
if ({{^required}}isset($this->container['{{name}}']) && {{/required}}(count($this->container['{{name}}']) < {{minItems}})) {
$invalidProperties[] = "invalid value for '{{name}}', number of items must be greater than or equal to {{{minItems}}}.";
}

{{/minItems}}
{{/hasValidation}}
{{/vars}}
return $invalidProperties;
}
Expand Down Expand Up @@ -288,41 +244,6 @@ class {{classname}} extends AbstractModel implements ModelInterface, \ArrayAcces
}
{{/isContainer}}
{{/isEnum}}
{{#hasValidation}}
{{#maxLength}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(mb_strlen(${{name}}) > {{maxLength}})) {
throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.');
}{{/maxLength}}
{{#minLength}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(mb_strlen(${{name}}) < {{minLength}})) {
throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.');
}
{{/minLength}}
{{#maximum}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(${{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}})) {
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.');
}
{{/maximum}}
{{#minimum}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(${{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}})) {
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.');
}
{{/minimum}}
{{#pattern}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(!preg_match("{{{pattern}}}", ${{name}}))) {
throw new \InvalidArgumentException("invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
}
{{/pattern}}
{{#maxItems}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(count(${{name}}) > {{maxItems}})) {
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.');
}{{/maxItems}}
{{#minItems}}
if ({{^required}}!is_null(${{name}}) && {{/required}}(count(${{name}}) < {{minItems}})) {
throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.');
}
{{/minItems}}
{{/hasValidation}}
$this->container['{{name}}'] = ${{name}};

return $this;
Expand Down
Loading

0 comments on commit ee6c043

Please sign in to comment.