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 e74b95cf2c1..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 @@ -20,6 +20,7 @@ public class CodegenParameter { public Map allowableValues; public CodegenProperty items; public Map vendorExtensions; + public Boolean hasValidation; /** * Determines whether this parameter is mandatory. If the parameter is in "path", @@ -120,6 +121,7 @@ public CodegenParameter copy() { 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 int hashCode() 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 boolean equals(Object obj) { 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 7e6c43374ac..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 @@ -1833,6 +1833,15 @@ public CodegenParameter fromParameter(Parameter param, Set imports) { p.minItems = qp.getMinItems(); p.uniqueItems = qp.isUniqueItems(); p.multipleOf = qp.getMultipleOf(); + + if (p.maximum != null || p.exclusiveMaximum != null || + p.minimum != null || p.exclusiveMinimum != null || + p.maxLength != null || p.minLength != null || + p.maxItems != null || p.minItems != 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}} + fail ArgumentError, "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}} + {{#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 - {{/isEnum}}{{/required}}{{/allParams}} + + {{/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 + +number = "number_example" # String | None + +double = 1.2 # Float | None -api_instance = Petstore::PetApi.new +string = "string_example" # String | None -body = Petstore::Pet.new # Pet | Pet object that needs to be added to the store +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/docs/FakeApi.md b/samples/client/petstore/ruby/docs/FakeApi.md new file mode 100644 index 00000000000..a7c0b42a475 --- /dev/null +++ b/samples/client/petstore/ruby/docs/FakeApi.md @@ -0,0 +1,82 @@ +# Petstore::FakeApi + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters + + +# **test_endpoint_parameters** +> test_endpoint_parameters(number, double, string, byte, opts) + +Fake endpoint for testing various parameters + +Fake endpoint for testing various parameters + +### Example +```ruby +# load the gem +require 'petstore' + +api_instance = Petstore::FakeApi.new + +number = "number_example" # String | None + +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 + #Fake endpoint for testing various parameters + api_instance.test_endpoint_parameters(number, double, string, byte, opts) +rescue Petstore::ApiError => e + puts "Exception when calling FakeApi->test_endpoint_parameters: #{e}" +end +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **number** | **String**| None | + **double** | **Float**| None | + **string** | **String**| None | + **byte** | **String**| None | + **integer** | **Integer**| None | [optional] + **int32** | **Integer**| None | [optional] + **int64** | **Integer**| None | [optional] + **float** | **Float**| None | [optional] + **binary** | **String**| None | [optional] + **date** | **Date**| None | [optional] + **date_time** | **DateTime**| None | [optional] + **password** | **String**| None | [optional] + +### Return type + +nil (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, application/json + + + 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/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/fake_api.rb b/samples/client/petstore/ruby/lib/petstore/api/fake_api.rb new file mode 100644 index 00000000000..a0cf2913f43 --- /dev/null +++ b/samples/client/petstore/ruby/lib/petstore/api/fake_api.rb @@ -0,0 +1,171 @@ +=begin +Swagger Petstore + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. + +OpenAPI spec version: 1.0.0 +Contact: apiteam@swagger.io +Generated by: https://github.com/swagger-api/swagger-codegen.git + +License: Apache 2.0 +http://www.apache.org/licenses/LICENSE-2.0.html + +Terms of Service: http://swagger.io/terms/ + +=end + +require "uri" + +module Petstore + class FakeApi + attr_accessor :api_client + + def initialize(api_client = ApiClient.default) + @api_client = api_client + end + + # Fake endpoint for testing various parameters + # Fake endpoint for testing various parameters + # @param number None + # @param double None + # @param string None + # @param byte None + # @param [Hash] opts the optional parameters + # @option opts [Integer] :integer None + # @option opts [Integer] :int32 None + # @option opts [Integer] :int64 None + # @option opts [Float] :float None + # @option opts [String] :binary None + # @option opts [Date] :date None + # @option opts [DateTime] :date_time None + # @option opts [String] :password None + # @return [nil] + def test_endpoint_parameters(number, double, string, byte, opts = {}) + test_endpoint_parameters_with_http_info(number, double, string, byte, opts) + return nil + end + + # Fake endpoint for testing various parameters + # Fake endpoint for testing various parameters + # @param number None + # @param double None + # @param string None + # @param byte None + # @param [Hash] opts the optional parameters + # @option opts [Integer] :integer None + # @option opts [Integer] :int32 None + # @option opts [Integer] :int64 None + # @option opts [Float] :float None + # @option opts [String] :binary None + # @option opts [Date] :date None + # @option opts [DateTime] :date_time None + # @option opts [String] :password None + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def test_endpoint_parameters_with_http_info(number, double, string, byte, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug "Calling API: FakeApi.test_endpoint_parameters ..." + end + # verify the required parameter 'number' is set + fail ArgumentError, "Missing the required parameter 'number' when calling FakeApi.test_endpoint_parameters" if number.nil? + if number > 543.2 + fail ArgumentError, 'invalid value for "number" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 543.2.' + end + + if number < 32.1 + fail ArgumentError, 'invalid value for "number" when calling FakeApi.test_endpoint_parameters, must be greater than or equal to 32.1.' + end + + # verify the required parameter 'double' is set + fail ArgumentError, "Missing the required parameter 'double' when calling FakeApi.test_endpoint_parameters" if double.nil? + if double > 123.4 + fail ArgumentError, 'invalid value for "double" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 123.4.' + end + + if double < 67.8 + fail ArgumentError, 'invalid value for "double" when calling FakeApi.test_endpoint_parameters, must be greater than or equal to 67.8.' + end + + # verify the required parameter 'string' is set + fail ArgumentError, "Missing the required parameter 'string' when calling FakeApi.test_endpoint_parameters" if string.nil? + if string !~ Regexp.new(/[a-z]/i) + fail ArgumentError, 'invalid value for "string" when calling FakeApi.test_endpoint_parameters, must conform to the pattern /[a-z]/i.' + end + + # verify the required parameter 'byte' is set + fail ArgumentError, "Missing the required parameter 'byte' when calling FakeApi.test_endpoint_parameters" if byte.nil? + if opts[:'integer'] > 100.0 + fail ArgumentError, 'invalid value for "opts[:"integer"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 100.0.' + end + + if opts[:'integer'] < 10.0 + fail ArgumentError, 'invalid value for "opts[:"integer"]" when calling FakeApi.test_endpoint_parameters, must be greater than or equal to 10.0.' + end + + if opts[:'int32'] > 200.0 + fail ArgumentError, 'invalid value for "opts[:"int32"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 200.0.' + end + + if opts[:'int32'] < 20.0 + fail ArgumentError, 'invalid value for "opts[:"int32"]" when calling FakeApi.test_endpoint_parameters, must be greater than or equal to 20.0.' + end + + if opts[:'float'] > 987.6 + fail ArgumentError, 'invalid value for "opts[:"float"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 987.6.' + end + + if opts[:'password'].to_s.length > 64 + fail ArgumentError, 'invalid value for "opts[:"password"]" when calling FakeApi.test_endpoint_parameters, the character length must be smaller than or equal to 64.' + end + + if opts[:'password'].to_s.length < 10 + fail ArgumentError, 'invalid value for "opts[:"password"]" when calling FakeApi.test_endpoint_parameters, the character length must be great than or equal to 10.' + end + + # resource path + local_var_path = "/fake".sub('{format}','json') + + # query parameters + query_params = {} + + # header parameters + header_params = {} + + # HTTP header 'Accept' (if needed) + local_header_accept = ['application/xml', 'application/json'] + local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result + + # HTTP header 'Content-Type' + local_header_content_type = [] + header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type) + + # form parameters + form_params = {} + form_params["number"] = number + form_params["double"] = double + form_params["string"] = string + form_params["byte"] = byte + form_params["integer"] = opts[:'integer'] if opts[:'integer'] + form_params["int32"] = opts[:'int32'] if opts[:'int32'] + form_params["int64"] = opts[:'int64'] if opts[:'int64'] + form_params["float"] = opts[:'float'] if opts[:'float'] + form_params["binary"] = opts[:'binary'] if opts[:'binary'] + form_params["date"] = opts[:'date'] if opts[:'date'] + form_params["dateTime"] = opts[:'date_time'] if opts[:'date_time'] + form_params["password"] = opts[:'password'] if opts[:'password'] + + # http body (model) + post_body = nil + auth_names = [] + data, status_code, headers = @api_client.call_api(:POST, local_var_path, + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: FakeApi#test_endpoint_parameters\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + end +end 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 @@ def add_pet(body, opts = {}) # @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 @@ def delete_pet(pet_id, opts = {}) # @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 @@ def find_pets_by_status(status, opts = {}) # @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 @@ def find_pets_by_tags(tags, opts = {}) # @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 @@ def get_pet_by_id(pet_id, opts = {}) # @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 @@ def update_pet(body, opts = {}) # @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 @@ def update_pet_with_form(pet_id, opts = {}) # @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 @@ def upload_file(pet_id, opts = {}) # @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 @@ def delete_order(order_id, opts = {}) # @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 @@ def get_inventory(opts = {}) # @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 @@ def get_order_by_id(order_id, opts = {}) # @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 @@ def place_order(body, opts = {}) # @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 @@ def create_user(body, opts = {}) # @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 @@ def create_users_with_array_input(body, opts = {}) # @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 @@ def create_users_with_list_input(body, opts = {}) # @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 @@ def delete_user(username, opts = {}) # @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 @@ def get_user_by_name(username, opts = {}) # @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 @@ def login_user(username, password, opts = {}) # @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 @@ def logout_user(opts = {}) # @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 @@ def update_user(username, body, opts = {}) # @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/api/fake_api_spec.rb b/samples/client/petstore/ruby/spec/api/fake_api_spec.rb new file mode 100644 index 00000000000..84929b8115c --- /dev/null +++ b/samples/client/petstore/ruby/spec/api/fake_api_spec.rb @@ -0,0 +1,66 @@ +=begin +Swagger Petstore + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. + +OpenAPI spec version: 1.0.0 +Contact: apiteam@swagger.io +Generated by: https://github.com/swagger-api/swagger-codegen.git + +License: Apache 2.0 +http://www.apache.org/licenses/LICENSE-2.0.html + +Terms of Service: http://swagger.io/terms/ + +=end + +require 'spec_helper' +require 'json' + +# Unit tests for Petstore::FakeApi +# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen) +# Please update as you see appropriate +describe 'FakeApi' do + before do + # run before each test + @instance = Petstore::FakeApi.new + end + + after do + # run after each test + end + + describe 'test an instance of FakeApi' do + it 'should create an instact of FakeApi' do + @instance.should be_a(Petstore::FakeApi) + end + end + + # unit tests for test_endpoint_parameters + # Fake endpoint for testing various parameters + # Fake endpoint for testing various parameters + # @param number None + # @param double None + # @param string None + # @param byte None + # @param [Hash] opts the optional parameters + # @option opts [Integer] :integer None + # @option opts [Integer] :int32 None + # @option opts [Integer] :int64 None + # @option opts [Float] :float None + # @option opts [String] :binary None + # @option opts [Date] :date None + # @option opts [DateTime] :date_time None + # @option opts [String] :password None + # @return [nil] + describe 'test_endpoint_parameters test' do + it "should work" do + # assertion here + # should be_a() + # should be_nil + # should == + # should_not == + end + end + +end 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 @@ def prepare_pet(pet_api) # 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,