From 4a440f4ee4cdf19f7cf427625359bde363affb2e Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Mon, 2 May 2016 16:37:32 +0100 Subject: [PATCH] Fix excpetion message to include --- .../src/main/resources/python/api.mustache | 8 ++++---- .../src/main/resources/python/model.mustache | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api.mustache b/modules/swagger-codegen/src/main/resources/python/api.mustache index 5a38ee255ee3..7902754e5fb3 100644 --- a/modules/swagger-codegen/src/main/resources/python/api.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api.mustache @@ -101,19 +101,19 @@ class {{classname}}(object): {{#hasValidation}} {{#maxLength}} if '{{paramName}}' in params and len(params['{{paramName}}']) > {{maxLength}}: - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than `{{maxLength}}`") + raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`") {{/maxLength}} {{#minLength}} if '{{paramName}}' in params and len(params['{{paramName}}']) < {{minLength}}: - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than `{{minLength}}`") + raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`") {{/minLength}} {{#maximum}} if '{{paramName}}' in params and params['{{paramName}}'] > {{maximum}}: - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than `{{maximum}}`") + raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than or equal to `{{maximum}}`") {{/maximum}} {{#minimum}} if '{{paramName}}' in params and params['{{paramName}}'] < {{minimum}}: - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than `{{minimum}}`") + raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than or equal to `{{minimum}}`") {{/minimum}} {{#pattern}} #if not re.match('{{pattern}}', '{{paramName}}' in params and params['{{paramName}}']): diff --git a/modules/swagger-codegen/src/main/resources/python/model.mustache b/modules/swagger-codegen/src/main/resources/python/model.mustache index 340c73687f50..78fe2ff2acd5 100644 --- a/modules/swagger-codegen/src/main/resources/python/model.mustache +++ b/modules/swagger-codegen/src/main/resources/python/model.mustache @@ -21,7 +21,8 @@ Copyright 2016 SmartBear Software {{#models}} {{#model}} from pprint import pformat -from six import iteritems +from six import +import re class {{classname}}(object): @@ -83,24 +84,27 @@ class {{classname}}(object): {{^isEnum}} {{#hasValidation}} + if not {{name}}: + raise ValueError("Invalid value for `{{name}}`, must not be `None`") {{#maxLength}} if len({{name}}) > {{maxLength}}: raise ValueError("Invalid value for `{{name}}`, length must be less than `{{maxLength}}`") {{/maxLength}} {{#minLength}} if len({{name}}) < {{minLength}}: - raise ValueError("Invalid value for `{{name}}`, length must be greater than `{{minLength}}`") + raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") {{/minLength}} {{#maximum}} if {{name}} > {{maximum}}: - raise ValueError("Invalid value for `{{name}}`, must be a value less than `{{maximum}}`") + raise ValueError("Invalid value for `{{name}}`, must be a value less than or equal to `{{maximum}}`") {{/maximum}} {{#minimum}} if {{name}} < {{minimum}}: - raise ValueError("Invalid value for `{{name}}`, must be a value greater than `{{minimum}}`") + raise ValueError("Invalid value for `{{name}}`, must be a value greater than or equal to `{{minimum}}`") {{/minimum}} {{#pattern}} - #Check pattern + #if not re.match('/[a-z]/i', {{name}}): + # raise ValueError("Invalid value for `{{name}}`, must be a follow pattern or equal to `{{pattern}}`") {{/pattern}} {{/hasValidation}} {{/isEnum}}