From 354449ebfe6a9886524d9eb8e3b1126f2de49cbc Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 26 Apr 2016 00:06:44 +0800 Subject: [PATCH] add validation to method parameters --- .../io/swagger/codegen/CodegenParameter.java | 1 + .../io/swagger/codegen/CodegenProperty.java | 8 ++ .../io/swagger/codegen/DefaultCodegen.java | 5 +- .../src/main/resources/ruby/api.mustache | 58 ++++++++++-- ...ith-fake-endpoints-models-for-testing.yaml | 90 +++++++++++++++++++ samples/client/petstore/ruby/README.md | 33 ++++--- samples/client/petstore/ruby/lib/petstore.rb | 1 + .../petstore/ruby/lib/petstore/api/pet_api.rb | 48 ++++------ .../ruby/lib/petstore/api/store_api.rb | 33 ++++--- .../ruby/lib/petstore/api/user_api.rb | 51 ++++------- .../client/petstore/ruby/spec/spec_helper.rb | 2 +- 11 files changed, 228 insertions(+), 102 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index a1a0460d0fa..3f38d391e70 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -121,6 +121,7 @@ public class CodegenParameter { output.items = this.items; } output.vendorExtensions = this.vendorExtensions; + output.hasValidation = this.hasValidation; output.isBinary = this.isBinary; output.isByteArray = this.isByteArray; output.isString = this.isString; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index 199d51ce19e..79b7c60a9eb 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -86,6 +86,7 @@ public class CodegenProperty { result = prime * result + ((setter == null) ? 0 : setter.hashCode()); result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode()); result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode()); + result = prime * result + ((hasValidation == null) ? 0 : hasValidation.hashCode()); result = prime * result + ((isString == null) ? 0 : isString.hashCode()); result = prime * result + ((isInteger == null) ? 0 : isInteger.hashCode()); result = prime * result + ((isLong == null) ? 0 : isLong.hashCode()); @@ -203,12 +204,19 @@ public class CodegenProperty { if (this.allowableValues != other.allowableValues && (this.allowableValues == null || !this.allowableValues.equals(other.allowableValues))) { return false; } + if (this.vendorExtensions != other.vendorExtensions && (this.vendorExtensions == null || !this.vendorExtensions.equals(other.vendorExtensions))) { return false; } + + if (this.hasValidation != other.hasValidation && (this.hasValidation == null || !this.hasValidation.equals(other.hasValidation))) { + return false; + } + if (this.isString != other.isString && (this.isString == null || !this.isString.equals(other.isString))) { return false; } + if (this.isInteger != other.isInteger && (this.isInteger == null || !this.isInteger.equals(other.isInteger))) { return false; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 2f2258c0609..69e56e57935 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1838,7 +1838,10 @@ public class DefaultCodegen { p.minimum != null || p.exclusiveMinimum != null || p.maxLength != null || p.minLength != null || p.maxItems != null || p.minItems != null || - p.pattern != null || + p.pattern != null) { + p.hasValidation = true; + } + } else { if (!(param instanceof BodyParameter)) { LOGGER.error("Cannot use Parameter " + param + " as Body Parameter"); diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 594a813de72..20b6d4593e3 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -33,19 +33,59 @@ module {{moduleName}} {{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: {{classname}}#{{operationId}} ..." + @api_client.config.logger.debug "Calling API: {{classname}}.{{operationId}} ..." end - {{#allParams}}{{#required}} + {{#allParams}} + {{#required}} # verify the required parameter '{{paramName}}' is set - fail "Missing the required parameter '{{paramName}}' when calling {{operationId}}" if {{{paramName}}}.nil?{{#isEnum}} + fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}" if {{{paramName}}}.nil? + {{#isEnum}} + # verify enum value unless [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}}) - fail "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" - end{{/isEnum}} - {{/required}}{{^required}}{{#isEnum}} - if opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}']) - fail 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' + fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" end - {{/isEnum}}{{/required}}{{/allParams}} + {{/isEnum}} + {{/required}} + {{^required}} + {{#isEnum}} + if opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}']) + fail ArgumentError, 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' + end + {{/isEnum}} + {{/required}} + {{#hasValidation}} + {{#minLength}} + if {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length > {{{maxLength}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be smaller than or equal to {{{maxLength}}}.' + end + + {{/minLength}} + {{#maxLength}} + if {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length < {{{minLength}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be great than or equal to {{{minLength}}}.' + end + + {{/maxLength}} + {{#maximum}} + if {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} > {{{maximum}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{{maximum}}}.' + end + + {{/maximum}} + {{#minimum}} + if {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} < {{{minimum}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be greater than or equal to {{{minimum}}}.' + end + + {{/minimum}} + {{#pattern}} + if {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ Regexp.new({{{pattern}}}) + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.' + end + + {{/pattern}} + {{/hasValidation}} + {{/allParams}} # resource path local_var_path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index d77eaac6efd..29996c16b72 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -559,6 +559,96 @@ paths: description: Invalid username supplied '404': description: User not found + + /fake: + post: + tags: + - fake + summary: Fake endpoint for testing various parameters + description: Fake endpoint for testing various parameters + operationId: testEndpointParameters + produces: + - application/xml + - application/json + parameters: + - name: integer + type: integer + maximum: 100 + minimum: 10 + in: formData + description: None + - name: int32 + type: integer + format: int32 + maximum: 200 + minimum: 20 + in: formData + description: None + - name: int64 + type: integer + format: int64 + in: formData + description: None + - name: number + maximum: 543.2 + minimum: 32.1 + in: formData + description: None + required: true + - name: float + type: number + format: float + maximum: 987.6 + in: formData + description: None + - name: double + type: number + in: formData + format: double + maximum: 123.4 + minimum: 67.8 + required: true + description: None + - name: string + type: string + pattern: /[a-z]/i + in: formData + description: None + required: true + - name: byte + type: string + format: byte + in: formData + description: None + required: true + - name: binary + type: string + format: binary + in: formData + description: None + - name: date + type: string + format: date + in: formData + description: None + - name: dateTime + type: string + format: date-time + in: formData + description: None + - name: password + type: string + format: password + maxLength: 64 + minLength: 10 + in: formData + description: None + responses: + '400': + description: Invalid username supplied + '404': + description: User not found + securityDefinitions: petstore_auth: type: oauth2 diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md index 9882a3021ec..9d9deefd9ee 100644 --- a/samples/client/petstore/ruby/README.md +++ b/samples/client/petstore/ruby/README.md @@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/ - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-04-25T22:22:56.750+08:00 +- Build date: 2016-04-25T23:58:59.140+08:00 - Build package: class io.swagger.codegen.languages.RubyClientCodegen ## Installation @@ -55,22 +55,32 @@ Please follow the [installation](#installation) procedure and then run the follo # Load the gem require 'petstore' -# Setup authorization -Petstore.configure do |config| - # Configure OAuth2 access token for authorization: petstore_auth - config.access_token = 'YOUR ACCESS TOKEN' -end +api_instance = Petstore::FakeApi.new -api_instance = Petstore::PetApi.new +number = "number_example" # String | None -body = Petstore::Pet.new # Pet | Pet object that needs to be added to the store +double = 1.2 # Float | None +string = "string_example" # String | None + +byte = "B" # String | None + +opts = { + integer: 56, # Integer | None + int32: 56, # Integer | None + int64: 789, # Integer | None + float: 3.4, # Float | None + binary: "B", # String | None + date: Date.parse("2013-10-20"), # Date | None + date_time: DateTime.parse("2013-10-20T19:20:30+01:00"), # DateTime | None + password: "password_example" # String | None +} begin - #Add a new pet to the store - api_instance.add_pet(body) + #Fake endpoint for testing various parameters + api_instance.test_endpoint_parameters(number, double, string, byte, opts) rescue Petstore::ApiError => e - puts "Exception when calling PetApi->add_pet: #{e}" + puts "Exception when calling FakeApi->test_endpoint_parameters: #{e}" end ``` @@ -81,6 +91,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*Petstore::FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters *Petstore::PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store *Petstore::PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet *Petstore::PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status diff --git a/samples/client/petstore/ruby/lib/petstore.rb b/samples/client/petstore/ruby/lib/petstore.rb index 5964a522d9f..f203db3f5ba 100644 --- a/samples/client/petstore/ruby/lib/petstore.rb +++ b/samples/client/petstore/ruby/lib/petstore.rb @@ -37,6 +37,7 @@ require 'petstore/models/tag' require 'petstore/models/user' # APIs +require 'petstore/api/fake_api' require 'petstore/api/pet_api' require 'petstore/api/store_api' require 'petstore/api/user_api' diff --git a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb index 4355642fc58..7e4121d5120 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb @@ -41,12 +41,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def add_pet_with_http_info(body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#add_pet ..." + @api_client.config.logger.debug "Calling API: PetApi.add_pet ..." end - # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling add_pet" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling PetApi.add_pet" if body.nil? # resource path local_var_path = "/pet".sub('{format}','json') @@ -101,12 +99,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def delete_pet_with_http_info(pet_id, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#delete_pet ..." + @api_client.config.logger.debug "Calling API: PetApi.delete_pet ..." end - # verify the required parameter 'pet_id' is set - fail "Missing the required parameter 'pet_id' when calling delete_pet" if pet_id.nil? - + fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.delete_pet" if pet_id.nil? # resource path local_var_path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) @@ -160,12 +156,10 @@ module Petstore # @return [Array<(Array, Fixnum, Hash)>] Array data, response status code and response headers def find_pets_by_status_with_http_info(status, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#find_pets_by_status ..." + @api_client.config.logger.debug "Calling API: PetApi.find_pets_by_status ..." end - # verify the required parameter 'status' is set - fail "Missing the required parameter 'status' when calling find_pets_by_status" if status.nil? - + fail ArgumentError, "Missing the required parameter 'status' when calling PetApi.find_pets_by_status" if status.nil? # resource path local_var_path = "/pet/findByStatus".sub('{format}','json') @@ -220,12 +214,10 @@ module Petstore # @return [Array<(Array, Fixnum, Hash)>] Array data, response status code and response headers def find_pets_by_tags_with_http_info(tags, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#find_pets_by_tags ..." + @api_client.config.logger.debug "Calling API: PetApi.find_pets_by_tags ..." end - # verify the required parameter 'tags' is set - fail "Missing the required parameter 'tags' when calling find_pets_by_tags" if tags.nil? - + fail ArgumentError, "Missing the required parameter 'tags' when calling PetApi.find_pets_by_tags" if tags.nil? # resource path local_var_path = "/pet/findByTags".sub('{format}','json') @@ -280,12 +272,10 @@ module Petstore # @return [Array<(Pet, Fixnum, Hash)>] Pet data, response status code and response headers def get_pet_by_id_with_http_info(pet_id, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#get_pet_by_id ..." + @api_client.config.logger.debug "Calling API: PetApi.get_pet_by_id ..." end - # verify the required parameter 'pet_id' is set - fail "Missing the required parameter 'pet_id' when calling get_pet_by_id" if pet_id.nil? - + fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.get_pet_by_id" if pet_id.nil? # resource path local_var_path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) @@ -339,12 +329,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def update_pet_with_http_info(body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#update_pet ..." + @api_client.config.logger.debug "Calling API: PetApi.update_pet ..." end - # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling update_pet" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling PetApi.update_pet" if body.nil? # resource path local_var_path = "/pet".sub('{format}','json') @@ -401,12 +389,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def update_pet_with_form_with_http_info(pet_id, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#update_pet_with_form ..." + @api_client.config.logger.debug "Calling API: PetApi.update_pet_with_form ..." end - # verify the required parameter 'pet_id' is set - fail "Missing the required parameter 'pet_id' when calling update_pet_with_form" if pet_id.nil? - + fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.update_pet_with_form" if pet_id.nil? # resource path local_var_path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) @@ -465,12 +451,10 @@ module Petstore # @return [Array<(ApiResponse, Fixnum, Hash)>] ApiResponse data, response status code and response headers def upload_file_with_http_info(pet_id, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: PetApi#upload_file ..." + @api_client.config.logger.debug "Calling API: PetApi.upload_file ..." end - # verify the required parameter 'pet_id' is set - fail "Missing the required parameter 'pet_id' when calling upload_file" if pet_id.nil? - + fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.upload_file" if pet_id.nil? # resource path local_var_path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) diff --git a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb index 5a3c8efeb82..04c7f2701d8 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb @@ -41,12 +41,14 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def delete_order_with_http_info(order_id, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: StoreApi#delete_order ..." + @api_client.config.logger.debug "Calling API: StoreApi.delete_order ..." end - # verify the required parameter 'order_id' is set - fail "Missing the required parameter 'order_id' when calling delete_order" if order_id.nil? - + fail ArgumentError, "Missing the required parameter 'order_id' when calling StoreApi.delete_order" if order_id.nil? + if order_id < 1.0 + fail ArgumentError, 'invalid value for "order_id" when calling StoreApi.delete_order, must be greater than or equal to 1.0.' + end + # resource path local_var_path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s) @@ -97,9 +99,8 @@ module Petstore # @return [Array<(Hash, Fixnum, Hash)>] Hash data, response status code and response headers def get_inventory_with_http_info(opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: StoreApi#get_inventory ..." + @api_client.config.logger.debug "Calling API: StoreApi.get_inventory ..." end - # resource path local_var_path = "/store/inventory".sub('{format}','json') @@ -153,12 +154,18 @@ module Petstore # @return [Array<(Order, Fixnum, Hash)>] Order data, response status code and response headers def get_order_by_id_with_http_info(order_id, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: StoreApi#get_order_by_id ..." + @api_client.config.logger.debug "Calling API: StoreApi.get_order_by_id ..." end - # verify the required parameter 'order_id' is set - fail "Missing the required parameter 'order_id' when calling get_order_by_id" if order_id.nil? - + fail ArgumentError, "Missing the required parameter 'order_id' when calling StoreApi.get_order_by_id" if order_id.nil? + if order_id > 5.0 + fail ArgumentError, 'invalid value for "order_id" when calling StoreApi.get_order_by_id, must be smaller than or equal to 5.0.' + end + + if order_id < 1.0 + fail ArgumentError, 'invalid value for "order_id" when calling StoreApi.get_order_by_id, must be greater than or equal to 1.0.' + end + # resource path local_var_path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s) @@ -212,12 +219,10 @@ module Petstore # @return [Array<(Order, Fixnum, Hash)>] Order data, response status code and response headers def place_order_with_http_info(body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: StoreApi#place_order ..." + @api_client.config.logger.debug "Calling API: StoreApi.place_order ..." end - # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling place_order" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling StoreApi.place_order" if body.nil? # resource path local_var_path = "/store/order".sub('{format}','json') diff --git a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb index d5535aac583..469c950934a 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb @@ -41,12 +41,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def create_user_with_http_info(body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#create_user ..." + @api_client.config.logger.debug "Calling API: UserApi.create_user ..." end - # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling create_user" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling UserApi.create_user" if body.nil? # resource path local_var_path = "/user".sub('{format}','json') @@ -99,12 +97,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def create_users_with_array_input_with_http_info(body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#create_users_with_array_input ..." + @api_client.config.logger.debug "Calling API: UserApi.create_users_with_array_input ..." end - # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling create_users_with_array_input" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling UserApi.create_users_with_array_input" if body.nil? # resource path local_var_path = "/user/createWithArray".sub('{format}','json') @@ -157,12 +153,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def create_users_with_list_input_with_http_info(body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#create_users_with_list_input ..." + @api_client.config.logger.debug "Calling API: UserApi.create_users_with_list_input ..." end - # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling create_users_with_list_input" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling UserApi.create_users_with_list_input" if body.nil? # resource path local_var_path = "/user/createWithList".sub('{format}','json') @@ -215,12 +209,10 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def delete_user_with_http_info(username, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#delete_user ..." + @api_client.config.logger.debug "Calling API: UserApi.delete_user ..." end - # verify the required parameter 'username' is set - fail "Missing the required parameter 'username' when calling delete_user" if username.nil? - + fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.delete_user" if username.nil? # resource path local_var_path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) @@ -273,12 +265,10 @@ module Petstore # @return [Array<(User, Fixnum, Hash)>] User data, response status code and response headers def get_user_by_name_with_http_info(username, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#get_user_by_name ..." + @api_client.config.logger.debug "Calling API: UserApi.get_user_by_name ..." end - # verify the required parameter 'username' is set - fail "Missing the required parameter 'username' when calling get_user_by_name" if username.nil? - + fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.get_user_by_name" if username.nil? # resource path local_var_path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) @@ -334,15 +324,12 @@ module Petstore # @return [Array<(String, Fixnum, Hash)>] String data, response status code and response headers def login_user_with_http_info(username, password, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#login_user ..." + @api_client.config.logger.debug "Calling API: UserApi.login_user ..." end - # verify the required parameter 'username' is set - fail "Missing the required parameter 'username' when calling login_user" if username.nil? - + fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.login_user" if username.nil? # verify the required parameter 'password' is set - fail "Missing the required parameter 'password' when calling login_user" if password.nil? - + fail ArgumentError, "Missing the required parameter 'password' when calling UserApi.login_user" if password.nil? # resource path local_var_path = "/user/login".sub('{format}','json') @@ -396,9 +383,8 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def logout_user_with_http_info(opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#logout_user ..." + @api_client.config.logger.debug "Calling API: UserApi.logout_user ..." end - # resource path local_var_path = "/user/logout".sub('{format}','json') @@ -453,15 +439,12 @@ module Petstore # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers def update_user_with_http_info(username, body, opts = {}) if @api_client.config.debugging - @api_client.config.logger.debug "Calling API: UserApi#update_user ..." + @api_client.config.logger.debug "Calling API: UserApi.update_user ..." end - # verify the required parameter 'username' is set - fail "Missing the required parameter 'username' when calling update_user" if username.nil? - + fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.update_user" if username.nil? # verify the required parameter 'body' is set - fail "Missing the required parameter 'body' when calling update_user" if body.nil? - + fail ArgumentError, "Missing the required parameter 'body' when calling UserApi.update_user" if body.nil? # resource path local_var_path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index 68147e76b72..50702c439b7 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -55,7 +55,7 @@ end # create a random order, return its id def prepare_store(store_api) - order_id = random_id + order_id = 5 order = Petstore::Order.new("id" => order_id, "petId" => 123, "quantity" => 789,