|
206 | 206 |
|
207 | 207 | {{/requiredParams}} |
208 | 208 | {{#allParams}} |
| 209 | + {{^isNullable}} |
| 210 | + if (!missing(`{{paramName}}`) && is.null(`{{paramName}}`)) { |
| 211 | + {{#useDefaultExceptionHandling}} |
| 212 | + stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, `{{paramName}}` is not nullable") |
| 213 | + {{/useDefaultExceptionHandling}} |
| 214 | + {{#useRlangExceptionHandling}} |
| 215 | + rlang::abort(message = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, `{{paramName}}` is not nullable", |
| 216 | + .subclass = "ApiException", |
| 217 | + ApiException = ApiException$new(status = 0, |
| 218 | + reason = "Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, `{{paramName}}` is not nullable")) |
| 219 | + {{/useRlangExceptionHandling}} |
| 220 | + } |
| 221 | + {{/isNullable}} |
209 | 222 | {{#maxLength}} |
210 | | - if (nchar(`{{paramName}}`) > {{maxLength}}) { |
| 223 | + if (!is.null(`{{paramName}}`) && nchar(`{{paramName}}`) > {{maxLength}}) { |
211 | 224 | {{#useDefaultExceptionHandling}} |
212 | 225 | stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than or equal to {{maxLength}}.") |
213 | 226 | {{/useDefaultExceptionHandling}} |
|
220 | 233 | } |
221 | 234 | {{/maxLength}} |
222 | 235 | {{#minLength}} |
223 | | - if (nchar(`{{paramName}}`) < {{minLength}}) { |
| 236 | + if (!is.null(`{{paramName}}`) && nchar(`{{paramName}}`) < {{minLength}}) { |
224 | 237 | {{#useDefaultExceptionHandling}} |
225 | 238 | stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than or equal to {{minLength}}.") |
226 | 239 | {{/useDefaultExceptionHandling}} |
|
233 | 246 | } |
234 | 247 | {{/minLength}} |
235 | 248 | {{#maximum}} |
236 | | - if (`{{paramName}}` >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { |
| 249 | + if (!is.null(`{{paramName}}`) && `{{paramName}}` > {{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { |
237 | 250 | {{#useDefaultExceptionHandling}} |
238 | 251 | stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.") |
239 | 252 | {{/useDefaultExceptionHandling}} |
|
246 | 259 | } |
247 | 260 | {{/maximum}} |
248 | 261 | {{#minimum}} |
249 | | - if (`{{paramName}}` <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { |
| 262 | + if (!is.null(`{{paramName}}`) && `{{paramName}}` < {{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { |
250 | 263 | {{#useDefaultExceptionHandling}} |
251 | 264 | stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.") |
252 | 265 | {{/useDefaultExceptionHandling}} |
|
259 | 272 | } |
260 | 273 | {{/minimum}} |
261 | 274 | {{#pattern}} |
262 | | - if (!str_detect(`{{paramName}}`, "{{{pattern}}}")) { |
| 275 | + if (!is.null(`{{paramName}}`) && !stringr::str_detect(`{{paramName}}`, "{{{pattern}}}")) { |
263 | 276 | {{#useDefaultExceptionHandling}} |
264 | 277 | stop("Invalid value for `{{paramName}}` when calling {{classname}}${{operationId}}, must conform to the pattern {{{pattern}}}.") |
265 | 278 | {{/useDefaultExceptionHandling}} |
|
272 | 285 | } |
273 | 286 | {{/pattern}} |
274 | 287 | {{#maxItems}} |
275 | | - if (length(`{{paramName}}`) > {{maxItems}}) { |
| 288 | + if (!is.null(`{{paramName}}`) && length(`{{paramName}}`) > {{maxItems}}) { |
276 | 289 | {{#useDefaultExceptionHandling}} |
277 | 290 | stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be less than or equal to {{maxItems}}.") |
278 | 291 | {{/useDefaultExceptionHandling}} |
|
285 | 298 | } |
286 | 299 | {{/maxItems}} |
287 | 300 | {{#minItems}} |
288 | | - if (length(`{{paramName}}`) < {{minItems}}) { |
| 301 | + if (!is.null(`{{paramName}}`) && length(`{{paramName}}`) < {{minItems}}) { |
289 | 302 | {{#useDefaultExceptionHandling}} |
290 | 303 | stop("Invalid length for `{{paramName}}` when calling {{classname}}${{operationId}}, number of items must be greater than or equal to {{minItems}}.") |
291 | 304 | {{/useDefaultExceptionHandling}} |
|
307 | 320 | {{#isArray}} |
308 | 321 | {{#uniqueItems}} |
309 | 322 | # check if items are unique |
310 | | - if (!identical(`{{{paramName}}}`, unique(`{{{paramName}}}`))) { |
| 323 | + if (!is.null(`{{paramName}}`) && !identical(`{{{paramName}}}`, unique(`{{{paramName}}}`))) { |
311 | 324 | {{#useDefaultExceptionHandling}} |
312 | 325 | stop("Invalid value for {{{paramName}}} when calling {{classname}}${{operationId}}. Items must be unique.") |
313 | 326 | {{/useDefaultExceptionHandling}} |
|
0 commit comments