forked from loafle/openapi-generator-original
fix #3215 and enum array issue in parameter check
This commit is contained in:
parent
d15c504fc9
commit
f04df9a163
@ -40,10 +40,12 @@ module {{moduleName}}
|
||||
# verify the required parameter '{{paramName}}' is set
|
||||
fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}" if {{{paramName}}}.nil?
|
||||
{{#isEnum}}
|
||||
{{^isContainer}}
|
||||
# verify enum value
|
||||
unless [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}})
|
||||
fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}"
|
||||
end
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
@ -90,9 +92,17 @@ module {{moduleName}}
|
||||
local_var_path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}
|
||||
|
||||
# query parameters
|
||||
query_params = {}{{#queryParams}}{{#required}}
|
||||
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}{{/required}}{{/queryParams}}{{#queryParams}}{{^required}}
|
||||
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if opts[:'{{{paramName}}}']{{/required}}{{/queryParams}}
|
||||
query_params = {}
|
||||
{{#queryParams}}
|
||||
{{#required}}
|
||||
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
|
||||
{{/required}}
|
||||
{{/queryParams}}
|
||||
{{#queryParams}}
|
||||
{{^required}}
|
||||
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil?
|
||||
{{/required}}
|
||||
{{/queryParams}}
|
||||
|
||||
# header parameters
|
||||
header_params = {}
|
||||
@ -103,18 +113,37 @@ module {{moduleName}}
|
||||
|
||||
# HTTP header 'Content-Type'
|
||||
local_header_content_type = [{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
|
||||
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type){{#headerParams}}{{#required}}
|
||||
header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}{{/required}}{{/headerParams}}{{#headerParams}}{{^required}}
|
||||
header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if opts[:'{{{paramName}}}']{{/required}}{{/headerParams}}
|
||||
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
|
||||
{{#headerParams}}
|
||||
{{#required}}
|
||||
header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
|
||||
{{/required}}
|
||||
{{/headerParams}}
|
||||
{{#headerParams}}
|
||||
{{^required}}
|
||||
header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil?
|
||||
{{/required}}
|
||||
{{/headerParams}}
|
||||
|
||||
# form parameters
|
||||
form_params = {}{{#formParams}}{{#required}}
|
||||
form_params["{{baseName}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}{{/required}}{{/formParams}}{{#formParams}}{{^required}}
|
||||
form_params["{{baseName}}"] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if opts[:'{{paramName}}']{{/required}}{{/formParams}}
|
||||
form_params = {}
|
||||
{{#formParams}}
|
||||
{{#required}}
|
||||
form_params["{{baseName}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
|
||||
{{/required}}
|
||||
{{/formParams}}
|
||||
{{#formParams}}
|
||||
{{^required}}
|
||||
form_params["{{baseName}}"] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{paramName}}'].nil?
|
||||
{{/required}}
|
||||
{{/formParams}}
|
||||
|
||||
# http body (model)
|
||||
{{^bodyParam}}post_body = nil
|
||||
{{/bodyParam}}{{#bodyParam}}post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
|
||||
{{^bodyParam}}
|
||||
post_body = nil
|
||||
{{/bodyParam}}
|
||||
{{#bodyParam}}
|
||||
post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
|
||||
{{/bodyParam}}
|
||||
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
|
||||
data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path,
|
||||
|
@ -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-05-25T01:17:54.676+08:00
|
||||
- Build date: 2016-06-26T19:08:46.043+08:00
|
||||
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
|
||||
|
||||
## Installation
|
||||
@ -92,6 +92,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::FakeApi* | [**test_enum_query_parameters**](docs/FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query 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
|
||||
@ -120,6 +121,8 @@ Class | Method | HTTP request | Description
|
||||
- [Petstore::Animal](docs/Animal.md)
|
||||
- [Petstore::AnimalFarm](docs/AnimalFarm.md)
|
||||
- [Petstore::ApiResponse](docs/ApiResponse.md)
|
||||
- [Petstore::ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
|
||||
- [Petstore::ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
|
||||
- [Petstore::ArrayTest](docs/ArrayTest.md)
|
||||
- [Petstore::Cat](docs/Cat.md)
|
||||
- [Petstore::Category](docs/Category.md)
|
||||
@ -127,10 +130,13 @@ Class | Method | HTTP request | Description
|
||||
- [Petstore::EnumClass](docs/EnumClass.md)
|
||||
- [Petstore::EnumTest](docs/EnumTest.md)
|
||||
- [Petstore::FormatTest](docs/FormatTest.md)
|
||||
- [Petstore::HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
|
||||
- [Petstore::MapTest](docs/MapTest.md)
|
||||
- [Petstore::MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
|
||||
- [Petstore::Model200Response](docs/Model200Response.md)
|
||||
- [Petstore::ModelReturn](docs/ModelReturn.md)
|
||||
- [Petstore::Name](docs/Name.md)
|
||||
- [Petstore::NumberOnly](docs/NumberOnly.md)
|
||||
- [Petstore::Order](docs/Order.md)
|
||||
- [Petstore::Pet](docs/Pet.md)
|
||||
- [Petstore::ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -3,5 +3,7 @@
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**map_property** | **Hash<String, String>** | | [optional]
|
||||
**map_of_map_property** | **Hash<String, Hash<String, String>>** | | [optional]
|
||||
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
# Petstore::ArrayOfArrayOfNumberOnly
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**array_array_number** | **Array<Array<Float>>** | | [optional]
|
||||
|
||||
|
8
samples/client/petstore/ruby/docs/ArrayOfNumberOnly.md
Normal file
8
samples/client/petstore/ruby/docs/ArrayOfNumberOnly.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Petstore::ArrayOfNumberOnly
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**array_number** | **Array<Float>** | | [optional]
|
||||
|
||||
|
@ -3,5 +3,9 @@
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**array_of_string** | **Array<String>** | | [optional]
|
||||
**array_array_of_integer** | **Array<Array<Integer>>** | | [optional]
|
||||
**array_array_of_model** | **Array<Array<ReadOnlyFirst>>** | | [optional]
|
||||
**array_of_enum** | **Array<String>** | | [optional]
|
||||
|
||||
|
||||
|
@ -5,6 +5,7 @@ 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_enum_query_parameters**](FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
|
||||
|
||||
|
||||
# **test_endpoint_parameters**
|
||||
@ -80,3 +81,52 @@ No authorization required
|
||||
|
||||
|
||||
|
||||
# **test_enum_query_parameters**
|
||||
> test_enum_query_parameters(opts)
|
||||
|
||||
To test enum query parameters
|
||||
|
||||
### Example
|
||||
```ruby
|
||||
# load the gem
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
|
||||
opts = {
|
||||
enum_query_string: "-efg", # String | Query parameter enum test (string)
|
||||
enum_query_integer: 3.4, # Float | Query parameter enum test (double)
|
||||
enum_query_double: 1.2 # Float | Query parameter enum test (double)
|
||||
}
|
||||
|
||||
begin
|
||||
#To test enum query parameters
|
||||
api_instance.test_enum_query_parameters(opts)
|
||||
rescue Petstore::ApiError => e
|
||||
puts "Exception when calling FakeApi->test_enum_query_parameters: #{e}"
|
||||
end
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**enum_query_string** | **String**| Query parameter enum test (string) | [optional] [default to -efg]
|
||||
**enum_query_integer** | **Float**| Query parameter enum test (double) | [optional]
|
||||
**enum_query_double** | **Float**| Query parameter enum test (double) | [optional]
|
||||
|
||||
### Return type
|
||||
|
||||
nil (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
|
||||
|
||||
|
9
samples/client/petstore/ruby/docs/HasOnlyReadOnly.md
Normal file
9
samples/client/petstore/ruby/docs/HasOnlyReadOnly.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Petstore::HasOnlyReadOnly
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**bar** | **String** | | [optional]
|
||||
**foo** | **String** | | [optional]
|
||||
|
||||
|
10
samples/client/petstore/ruby/docs/MapTest.md
Normal file
10
samples/client/petstore/ruby/docs/MapTest.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Petstore::MapTest
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**map_map_of_string** | **Hash<String, Hash<String, String>>** | | [optional]
|
||||
**map_map_of_enum** | **Hash<String, Hash<String, String>>** | | [optional]
|
||||
**map_of_enum_string** | **Hash<String, String>** | | [optional]
|
||||
|
||||
|
@ -5,5 +5,6 @@ Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | **String** | | [optional]
|
||||
**date_time** | **DateTime** | | [optional]
|
||||
**map** | [**Hash<String, Animal>**](Animal.md) | | [optional]
|
||||
|
||||
|
||||
|
@ -4,5 +4,6 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **Integer** | | [optional]
|
||||
**_class** | **String** | | [optional]
|
||||
|
||||
|
||||
|
8
samples/client/petstore/ruby/docs/NumberOnly.md
Normal file
8
samples/client/petstore/ruby/docs/NumberOnly.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Petstore::NumberOnly
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**just_number** | **Float** | | [optional]
|
||||
|
||||
|
@ -32,6 +32,8 @@ require 'petstore/models/additional_properties_class'
|
||||
require 'petstore/models/animal'
|
||||
require 'petstore/models/animal_farm'
|
||||
require 'petstore/models/api_response'
|
||||
require 'petstore/models/array_of_array_of_number_only'
|
||||
require 'petstore/models/array_of_number_only'
|
||||
require 'petstore/models/array_test'
|
||||
require 'petstore/models/cat'
|
||||
require 'petstore/models/category'
|
||||
@ -39,10 +41,13 @@ require 'petstore/models/dog'
|
||||
require 'petstore/models/enum_class'
|
||||
require 'petstore/models/enum_test'
|
||||
require 'petstore/models/format_test'
|
||||
require 'petstore/models/has_only_read_only'
|
||||
require 'petstore/models/map_test'
|
||||
require 'petstore/models/mixed_properties_and_additional_properties_class'
|
||||
require 'petstore/models/model_200_response'
|
||||
require 'petstore/models/model_return'
|
||||
require 'petstore/models/name'
|
||||
require 'petstore/models/number_only'
|
||||
require 'petstore/models/order'
|
||||
require 'petstore/models/pet'
|
||||
require 'petstore/models/read_only_first'
|
||||
|
@ -151,18 +151,18 @@ module Petstore
|
||||
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']
|
||||
form_params["integer"] = opts[:'integer'] if !opts[:'integer'].nil?
|
||||
form_params["int32"] = opts[:'int32'] if !opts[:'int32'].nil?
|
||||
form_params["int64"] = opts[:'int64'] if !opts[:'int64'].nil?
|
||||
form_params["float"] = opts[:'float'] if !opts[:'float'].nil?
|
||||
form_params["binary"] = opts[:'binary'] if !opts[:'binary'].nil?
|
||||
form_params["date"] = opts[:'date'] if !opts[:'date'].nil?
|
||||
form_params["dateTime"] = opts[:'date_time'] if !opts[:'date_time'].nil?
|
||||
form_params["password"] = opts[:'password'] if !opts[:'password'].nil?
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -174,5 +174,69 @@ module Petstore
|
||||
end
|
||||
return data, status_code, headers
|
||||
end
|
||||
|
||||
# To test enum query parameters
|
||||
#
|
||||
# @param [Hash] opts the optional parameters
|
||||
# @option opts [String] :enum_query_string Query parameter enum test (string) (default to -efg)
|
||||
# @option opts [Float] :enum_query_integer Query parameter enum test (double)
|
||||
# @option opts [Float] :enum_query_double Query parameter enum test (double)
|
||||
# @return [nil]
|
||||
def test_enum_query_parameters(opts = {})
|
||||
test_enum_query_parameters_with_http_info(opts)
|
||||
return nil
|
||||
end
|
||||
|
||||
# To test enum query parameters
|
||||
#
|
||||
# @param [Hash] opts the optional parameters
|
||||
# @option opts [String] :enum_query_string Query parameter enum test (string)
|
||||
# @option opts [Float] :enum_query_integer Query parameter enum test (double)
|
||||
# @option opts [Float] :enum_query_double Query parameter enum test (double)
|
||||
# @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers
|
||||
def test_enum_query_parameters_with_http_info(opts = {})
|
||||
if @api_client.config.debugging
|
||||
@api_client.config.logger.debug "Calling API: FakeApi.test_enum_query_parameters ..."
|
||||
end
|
||||
if opts[:'enum_query_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_query_string'])
|
||||
fail ArgumentError, 'invalid value for "enum_query_string", must be one of _abc, -efg, (xyz)'
|
||||
end
|
||||
# resource path
|
||||
local_var_path = "/fake".sub('{format}','json')
|
||||
|
||||
# query parameters
|
||||
query_params = {}
|
||||
query_params[:'enum_query_integer'] = opts[:'enum_query_integer'] if !opts[:'enum_query_integer'].nil?
|
||||
|
||||
# header parameters
|
||||
header_params = {}
|
||||
|
||||
# HTTP header 'Accept' (if needed)
|
||||
local_header_accept = ['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 = ['application/json']
|
||||
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
|
||||
|
||||
# form parameters
|
||||
form_params = {}
|
||||
form_params["enum_query_string"] = opts[:'enum_query_string'] if !opts[:'enum_query_string'].nil?
|
||||
form_params["enum_query_double"] = opts[:'enum_query_double'] if !opts[:'enum_query_double'].nil?
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:GET, 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_enum_query_parameters\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
||||
end
|
||||
return data, status_code, headers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -126,14 +126,14 @@ module Petstore
|
||||
# HTTP header 'Content-Type'
|
||||
local_header_content_type = []
|
||||
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
|
||||
header_params[:'api_key'] = opts[:'api_key'] if opts[:'api_key']
|
||||
header_params[:'api_key'] = opts[:'api_key'] if !opts[:'api_key'].nil?
|
||||
|
||||
# form parameters
|
||||
form_params = {}
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['petstore_auth']
|
||||
auth_names = ['petstore_auth']
|
||||
data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -190,7 +190,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['petstore_auth']
|
||||
auth_names = ['petstore_auth']
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -248,7 +248,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['petstore_auth']
|
||||
auth_names = ['petstore_auth']
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -305,7 +305,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['api_key']
|
||||
auth_names = ['api_key']
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -419,12 +419,12 @@ module Petstore
|
||||
|
||||
# form parameters
|
||||
form_params = {}
|
||||
form_params["name"] = opts[:'name'] if opts[:'name']
|
||||
form_params["status"] = opts[:'status'] if opts[:'status']
|
||||
form_params["name"] = opts[:'name'] if !opts[:'name'].nil?
|
||||
form_params["status"] = opts[:'status'] if !opts[:'status'].nil?
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['petstore_auth']
|
||||
auth_names = ['petstore_auth']
|
||||
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -481,12 +481,12 @@ module Petstore
|
||||
|
||||
# form parameters
|
||||
form_params = {}
|
||||
form_params["additionalMetadata"] = opts[:'additional_metadata'] if opts[:'additional_metadata']
|
||||
form_params["file"] = opts[:'file'] if opts[:'file']
|
||||
form_params["additionalMetadata"] = opts[:'additional_metadata'] if !opts[:'additional_metadata'].nil?
|
||||
form_params["file"] = opts[:'file'] if !opts[:'file'].nil?
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['petstore_auth']
|
||||
auth_names = ['petstore_auth']
|
||||
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
|
@ -78,7 +78,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -130,7 +130,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = ['api_key']
|
||||
auth_names = ['api_key']
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -195,7 +195,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
|
@ -242,7 +242,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -298,7 +298,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -361,7 +361,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
@ -414,7 +414,7 @@ module Petstore
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
auth_names = []
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
|
@ -26,15 +26,24 @@ require 'date'
|
||||
module Petstore
|
||||
|
||||
class AdditionalPropertiesClass
|
||||
attr_accessor :map_property
|
||||
|
||||
attr_accessor :map_of_map_property
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'map_property' => :'map_property',
|
||||
:'map_of_map_property' => :'map_of_map_property'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'map_property' => :'Hash<String, String>',
|
||||
:'map_of_map_property' => :'Hash<String, Hash<String, String>>'
|
||||
}
|
||||
end
|
||||
|
||||
@ -46,6 +55,18 @@ module Petstore
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'map_property')
|
||||
if (value = attributes[:'map_property']).is_a?(Array)
|
||||
self.map_property = value
|
||||
end
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'map_of_map_property')
|
||||
if (value = attributes[:'map_of_map_property']).is_a?(Array)
|
||||
self.map_of_map_property = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
@ -58,13 +79,16 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class
|
||||
self.class == o.class &&
|
||||
map_property == o.map_property &&
|
||||
map_of_map_property == o.map_of_map_property
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
@ -76,7 +100,7 @@ module Petstore
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[].hash
|
||||
[map_property, map_of_map_property].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
|
@ -0,0 +1,201 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Petstore
|
||||
|
||||
class ArrayOfArrayOfNumberOnly
|
||||
attr_accessor :array_array_number
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'array_array_number' => :'ArrayArrayNumber'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'array_array_number' => :'Array<Array<Float>>'
|
||||
}
|
||||
end
|
||||
|
||||
# Initializes the object
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
def initialize(attributes = {})
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'ArrayArrayNumber')
|
||||
if (value = attributes[:'ArrayArrayNumber']).is_a?(Array)
|
||||
self.array_array_number = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
# @return Array for valid properies with the reasons
|
||||
def list_invalid_properties
|
||||
invalid_properties = Array.new
|
||||
return invalid_properties
|
||||
end
|
||||
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
array_array_number == o.array_array_number
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
# @param [Object] Object to be compared
|
||||
def eql?(o)
|
||||
self == o
|
||||
end
|
||||
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[array_array_number].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
# @return [Object] Returns the model itself
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^Array<(.*)>/i
|
||||
# check to ensure the input is an array given that the the attribute
|
||||
# is documented as an array but the input is not
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
# Deserializes the data based on type
|
||||
# @param string type Data type
|
||||
# @param string value Value to be deserialized
|
||||
# @return [Object] Deserialized data
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :Date
|
||||
Date.parse(value)
|
||||
when :String
|
||||
value.to_s
|
||||
when :Integer
|
||||
value.to_i
|
||||
when :Float
|
||||
value.to_f
|
||||
when :BOOLEAN
|
||||
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when :Object
|
||||
# generic object (usually a Hash), return directly
|
||||
value
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
temp_model = Petstore.const_get(type).new
|
||||
temp_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the string representation of the object
|
||||
# @return [String] String presentation of the object
|
||||
def to_s
|
||||
to_hash.to_s
|
||||
end
|
||||
|
||||
# to_body is an alias to to_hash (backward compatibility)
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_body
|
||||
to_hash
|
||||
end
|
||||
|
||||
# Returns the object in the form of hash
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Outputs non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
# @param [Object] value Any valid value
|
||||
# @return [Hash] Returns the value in the form of hash
|
||||
def _to_hash(value)
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,201 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Petstore
|
||||
|
||||
class ArrayOfNumberOnly
|
||||
attr_accessor :array_number
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'array_number' => :'ArrayNumber'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'array_number' => :'Array<Float>'
|
||||
}
|
||||
end
|
||||
|
||||
# Initializes the object
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
def initialize(attributes = {})
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'ArrayNumber')
|
||||
if (value = attributes[:'ArrayNumber']).is_a?(Array)
|
||||
self.array_number = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
# @return Array for valid properies with the reasons
|
||||
def list_invalid_properties
|
||||
invalid_properties = Array.new
|
||||
return invalid_properties
|
||||
end
|
||||
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
array_number == o.array_number
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
# @param [Object] Object to be compared
|
||||
def eql?(o)
|
||||
self == o
|
||||
end
|
||||
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[array_number].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
# @return [Object] Returns the model itself
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^Array<(.*)>/i
|
||||
# check to ensure the input is an array given that the the attribute
|
||||
# is documented as an array but the input is not
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
# Deserializes the data based on type
|
||||
# @param string type Data type
|
||||
# @param string value Value to be deserialized
|
||||
# @return [Object] Deserialized data
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :Date
|
||||
Date.parse(value)
|
||||
when :String
|
||||
value.to_s
|
||||
when :Integer
|
||||
value.to_i
|
||||
when :Float
|
||||
value.to_f
|
||||
when :BOOLEAN
|
||||
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when :Object
|
||||
# generic object (usually a Hash), return directly
|
||||
value
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
temp_model = Petstore.const_get(type).new
|
||||
temp_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the string representation of the object
|
||||
# @return [String] String presentation of the object
|
||||
def to_s
|
||||
to_hash.to_s
|
||||
end
|
||||
|
||||
# to_body is an alias to to_hash (backward compatibility)
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_body
|
||||
to_hash
|
||||
end
|
||||
|
||||
# Returns the object in the form of hash
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Outputs non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
# @param [Object] value Any valid value
|
||||
# @return [Hash] Returns the value in the form of hash
|
||||
def _to_hash(value)
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -32,13 +32,37 @@ module Petstore
|
||||
|
||||
attr_accessor :array_array_of_model
|
||||
|
||||
attr_accessor :array_of_enum
|
||||
|
||||
class EnumAttributeValidator
|
||||
attr_reader :datatype
|
||||
attr_reader :allowable_values
|
||||
|
||||
def initialize(datatype, allowable_values)
|
||||
@allowable_values = allowable_values.map do |value|
|
||||
case datatype.to_s
|
||||
when /Integer/i
|
||||
value.to_i
|
||||
when /Float/i
|
||||
value.to_f
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def valid?(value)
|
||||
!value || allowable_values.include?(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'array_of_string' => :'array_of_string',
|
||||
:'array_array_of_integer' => :'array_array_of_integer',
|
||||
:'array_array_of_model' => :'array_array_of_model'
|
||||
:'array_array_of_model' => :'array_array_of_model',
|
||||
:'array_of_enum' => :'array_of_enum'
|
||||
}
|
||||
end
|
||||
|
||||
@ -47,7 +71,8 @@ module Petstore
|
||||
{
|
||||
:'array_of_string' => :'Array<String>',
|
||||
:'array_array_of_integer' => :'Array<Array<Integer>>',
|
||||
:'array_array_of_model' => :'Array<Array<ReadOnlyFirst>>'
|
||||
:'array_array_of_model' => :'Array<Array<ReadOnlyFirst>>',
|
||||
:'array_of_enum' => :'Array<String>'
|
||||
}
|
||||
end
|
||||
|
||||
@ -77,6 +102,12 @@ module Petstore
|
||||
end
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'array_of_enum')
|
||||
if (value = attributes[:'array_of_enum']).is_a?(Array)
|
||||
self.array_of_enum = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
@ -89,9 +120,21 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
array_of_enum_validator = EnumAttributeValidator.new('Array<String>', [])
|
||||
return false unless array_of_enum_validator.valid?(@array_of_enum)
|
||||
return true
|
||||
end
|
||||
|
||||
# Custom attribute writer method checking allowed values (enum).
|
||||
# @param [Object] array_of_enum Object to be assigned
|
||||
def array_of_enum=(array_of_enum)
|
||||
validator = EnumAttributeValidator.new('Array<String>', [])
|
||||
unless validator.valid?(array_of_enum)
|
||||
fail ArgumentError, "invalid value for 'array_of_enum', must be one of #{validator.allowable_values}."
|
||||
end
|
||||
@array_of_enum = array_of_enum
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
@ -99,7 +142,8 @@ module Petstore
|
||||
self.class == o.class &&
|
||||
array_of_string == o.array_of_string &&
|
||||
array_array_of_integer == o.array_array_of_integer &&
|
||||
array_array_of_model == o.array_array_of_model
|
||||
array_array_of_model == o.array_array_of_model &&
|
||||
array_of_enum == o.array_of_enum
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
@ -111,7 +155,7 @@ module Petstore
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[array_of_string, array_array_of_integer, array_array_of_model].hash
|
||||
[array_of_string, array_array_of_integer, array_array_of_model, array_of_enum].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
|
@ -0,0 +1,208 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Petstore
|
||||
|
||||
class HasOnlyReadOnly
|
||||
attr_accessor :bar
|
||||
|
||||
attr_accessor :foo
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'bar' => :'bar',
|
||||
:'foo' => :'foo'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'bar' => :'String',
|
||||
:'foo' => :'String'
|
||||
}
|
||||
end
|
||||
|
||||
# Initializes the object
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
def initialize(attributes = {})
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'bar')
|
||||
self.bar = attributes[:'bar']
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'foo')
|
||||
self.foo = attributes[:'foo']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
# @return Array for valid properies with the reasons
|
||||
def list_invalid_properties
|
||||
invalid_properties = Array.new
|
||||
return invalid_properties
|
||||
end
|
||||
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
bar == o.bar &&
|
||||
foo == o.foo
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
# @param [Object] Object to be compared
|
||||
def eql?(o)
|
||||
self == o
|
||||
end
|
||||
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[bar, foo].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
# @return [Object] Returns the model itself
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^Array<(.*)>/i
|
||||
# check to ensure the input is an array given that the the attribute
|
||||
# is documented as an array but the input is not
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
# Deserializes the data based on type
|
||||
# @param string type Data type
|
||||
# @param string value Value to be deserialized
|
||||
# @return [Object] Deserialized data
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :Date
|
||||
Date.parse(value)
|
||||
when :String
|
||||
value.to_s
|
||||
when :Integer
|
||||
value.to_i
|
||||
when :Float
|
||||
value.to_f
|
||||
when :BOOLEAN
|
||||
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when :Object
|
||||
# generic object (usually a Hash), return directly
|
||||
value
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
temp_model = Petstore.const_get(type).new
|
||||
temp_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the string representation of the object
|
||||
# @return [String] String presentation of the object
|
||||
def to_s
|
||||
to_hash.to_s
|
||||
end
|
||||
|
||||
# to_body is an alias to to_hash (backward compatibility)
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_body
|
||||
to_hash
|
||||
end
|
||||
|
||||
# Returns the object in the form of hash
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Outputs non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
# @param [Object] value Any valid value
|
||||
# @return [Hash] Returns the value in the form of hash
|
||||
def _to_hash(value)
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
268
samples/client/petstore/ruby/lib/petstore/models/map_test.rb
Normal file
268
samples/client/petstore/ruby/lib/petstore/models/map_test.rb
Normal file
@ -0,0 +1,268 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Petstore
|
||||
|
||||
class MapTest
|
||||
attr_accessor :map_map_of_string
|
||||
|
||||
attr_accessor :map_map_of_enum
|
||||
|
||||
attr_accessor :map_of_enum_string
|
||||
|
||||
class EnumAttributeValidator
|
||||
attr_reader :datatype
|
||||
attr_reader :allowable_values
|
||||
|
||||
def initialize(datatype, allowable_values)
|
||||
@allowable_values = allowable_values.map do |value|
|
||||
case datatype.to_s
|
||||
when /Integer/i
|
||||
value.to_i
|
||||
when /Float/i
|
||||
value.to_f
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def valid?(value)
|
||||
!value || allowable_values.include?(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'map_map_of_string' => :'map_map_of_string',
|
||||
:'map_map_of_enum' => :'map_map_of_enum',
|
||||
:'map_of_enum_string' => :'map_of_enum_string'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'map_map_of_string' => :'Hash<String, Hash<String, String>>',
|
||||
:'map_map_of_enum' => :'Hash<String, Hash<String, String>>',
|
||||
:'map_of_enum_string' => :'Hash<String, String>'
|
||||
}
|
||||
end
|
||||
|
||||
# Initializes the object
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
def initialize(attributes = {})
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'map_map_of_string')
|
||||
if (value = attributes[:'map_map_of_string']).is_a?(Array)
|
||||
self.map_map_of_string = value
|
||||
end
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'map_map_of_enum')
|
||||
if (value = attributes[:'map_map_of_enum']).is_a?(Array)
|
||||
self.map_map_of_enum = value
|
||||
end
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'map_of_enum_string')
|
||||
if (value = attributes[:'map_of_enum_string']).is_a?(Array)
|
||||
self.map_of_enum_string = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
# @return Array for valid properies with the reasons
|
||||
def list_invalid_properties
|
||||
invalid_properties = Array.new
|
||||
return invalid_properties
|
||||
end
|
||||
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
map_map_of_enum_validator = EnumAttributeValidator.new('Hash<String, Hash<String, String>>', [])
|
||||
return false unless map_map_of_enum_validator.valid?(@map_map_of_enum)
|
||||
map_of_enum_string_validator = EnumAttributeValidator.new('Hash<String, String>', [])
|
||||
return false unless map_of_enum_string_validator.valid?(@map_of_enum_string)
|
||||
return true
|
||||
end
|
||||
|
||||
# Custom attribute writer method checking allowed values (enum).
|
||||
# @param [Object] map_map_of_enum Object to be assigned
|
||||
def map_map_of_enum=(map_map_of_enum)
|
||||
validator = EnumAttributeValidator.new('Hash<String, Hash<String, String>>', [])
|
||||
unless validator.valid?(map_map_of_enum)
|
||||
fail ArgumentError, "invalid value for 'map_map_of_enum', must be one of #{validator.allowable_values}."
|
||||
end
|
||||
@map_map_of_enum = map_map_of_enum
|
||||
end
|
||||
|
||||
# Custom attribute writer method checking allowed values (enum).
|
||||
# @param [Object] map_of_enum_string Object to be assigned
|
||||
def map_of_enum_string=(map_of_enum_string)
|
||||
validator = EnumAttributeValidator.new('Hash<String, String>', [])
|
||||
unless validator.valid?(map_of_enum_string)
|
||||
fail ArgumentError, "invalid value for 'map_of_enum_string', must be one of #{validator.allowable_values}."
|
||||
end
|
||||
@map_of_enum_string = map_of_enum_string
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
map_map_of_string == o.map_map_of_string &&
|
||||
map_map_of_enum == o.map_map_of_enum &&
|
||||
map_of_enum_string == o.map_of_enum_string
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
# @param [Object] Object to be compared
|
||||
def eql?(o)
|
||||
self == o
|
||||
end
|
||||
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[map_map_of_string, map_map_of_enum, map_of_enum_string].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
# @return [Object] Returns the model itself
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^Array<(.*)>/i
|
||||
# check to ensure the input is an array given that the the attribute
|
||||
# is documented as an array but the input is not
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
# Deserializes the data based on type
|
||||
# @param string type Data type
|
||||
# @param string value Value to be deserialized
|
||||
# @return [Object] Deserialized data
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :Date
|
||||
Date.parse(value)
|
||||
when :String
|
||||
value.to_s
|
||||
when :Integer
|
||||
value.to_i
|
||||
when :Float
|
||||
value.to_f
|
||||
when :BOOLEAN
|
||||
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when :Object
|
||||
# generic object (usually a Hash), return directly
|
||||
value
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
temp_model = Petstore.const_get(type).new
|
||||
temp_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the string representation of the object
|
||||
# @return [String] String presentation of the object
|
||||
def to_s
|
||||
to_hash.to_s
|
||||
end
|
||||
|
||||
# to_body is an alias to to_hash (backward compatibility)
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_body
|
||||
to_hash
|
||||
end
|
||||
|
||||
# Returns the object in the form of hash
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Outputs non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
# @param [Object] value Any valid value
|
||||
# @return [Hash] Returns the value in the form of hash
|
||||
def _to_hash(value)
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -30,11 +30,15 @@ module Petstore
|
||||
|
||||
attr_accessor :date_time
|
||||
|
||||
attr_accessor :map
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'uuid' => :'uuid',
|
||||
:'date_time' => :'dateTime'
|
||||
:'date_time' => :'dateTime',
|
||||
:'map' => :'map'
|
||||
}
|
||||
end
|
||||
|
||||
@ -42,7 +46,8 @@ module Petstore
|
||||
def self.swagger_types
|
||||
{
|
||||
:'uuid' => :'String',
|
||||
:'date_time' => :'DateTime'
|
||||
:'date_time' => :'DateTime',
|
||||
:'map' => :'Hash<String, Animal>'
|
||||
}
|
||||
end
|
||||
|
||||
@ -62,6 +67,12 @@ module Petstore
|
||||
self.date_time = attributes[:'dateTime']
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'map')
|
||||
if (value = attributes[:'map']).is_a?(Array)
|
||||
self.map = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
@ -74,6 +85,7 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
@ -82,7 +94,8 @@ module Petstore
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
uuid == o.uuid &&
|
||||
date_time == o.date_time
|
||||
date_time == o.date_time &&
|
||||
map == o.map
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
@ -94,7 +107,7 @@ module Petstore
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[uuid, date_time].hash
|
||||
[uuid, date_time, map].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
|
@ -28,18 +28,22 @@ module Petstore
|
||||
class Model200Response
|
||||
attr_accessor :name
|
||||
|
||||
attr_accessor :_class
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'name' => :'name'
|
||||
:'name' => :'name',
|
||||
:'_class' => :'class'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'name' => :'Integer'
|
||||
:'name' => :'Integer',
|
||||
:'_class' => :'String'
|
||||
}
|
||||
end
|
||||
|
||||
@ -55,6 +59,10 @@ module Petstore
|
||||
self.name = attributes[:'name']
|
||||
end
|
||||
|
||||
if attributes.has_key?(:'class')
|
||||
self._class = attributes[:'class']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
@ -75,7 +83,8 @@ module Petstore
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
name == o.name
|
||||
name == o.name &&
|
||||
_class == o._class
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
@ -87,7 +96,7 @@ module Petstore
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[name].hash
|
||||
[name, _class].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
|
199
samples/client/petstore/ruby/lib/petstore/models/number_only.rb
Normal file
199
samples/client/petstore/ruby/lib/petstore/models/number_only.rb
Normal file
@ -0,0 +1,199 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Petstore
|
||||
|
||||
class NumberOnly
|
||||
attr_accessor :just_number
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'just_number' => :'JustNumber'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'just_number' => :'Float'
|
||||
}
|
||||
end
|
||||
|
||||
# Initializes the object
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
def initialize(attributes = {})
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'JustNumber')
|
||||
self.just_number = attributes[:'JustNumber']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
# @return Array for valid properies with the reasons
|
||||
def list_invalid_properties
|
||||
invalid_properties = Array.new
|
||||
return invalid_properties
|
||||
end
|
||||
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
just_number == o.just_number
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
# @param [Object] Object to be compared
|
||||
def eql?(o)
|
||||
self == o
|
||||
end
|
||||
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[just_number].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
# @return [Object] Returns the model itself
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^Array<(.*)>/i
|
||||
# check to ensure the input is an array given that the the attribute
|
||||
# is documented as an array but the input is not
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
# Deserializes the data based on type
|
||||
# @param string type Data type
|
||||
# @param string value Value to be deserialized
|
||||
# @return [Object] Deserialized data
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :Date
|
||||
Date.parse(value)
|
||||
when :String
|
||||
value.to_s
|
||||
when :Integer
|
||||
value.to_i
|
||||
when :Float
|
||||
value.to_f
|
||||
when :BOOLEAN
|
||||
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when :Object
|
||||
# generic object (usually a Hash), return directly
|
||||
value
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
temp_model = Petstore.const_get(type).new
|
||||
temp_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the string representation of the object
|
||||
# @return [String] String presentation of the object
|
||||
def to_s
|
||||
to_hash.to_s
|
||||
end
|
||||
|
||||
# to_body is an alias to to_hash (backward compatibility)
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_body
|
||||
to_hash
|
||||
end
|
||||
|
||||
# Returns the object in the form of hash
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Outputs non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
# @param [Object] value Any valid value
|
||||
# @return [Hash] Returns the value in the form of hash
|
||||
def _to_hash(value)
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -30,6 +30,7 @@ module Petstore
|
||||
|
||||
attr_accessor :baz
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
@ -74,6 +75,7 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
|
@ -0,0 +1,53 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'json'
|
||||
require 'date'
|
||||
|
||||
# Unit tests for Petstore::ArrayOfArrayOfNumberOnly
|
||||
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
||||
# Please update as you see appropriate
|
||||
describe 'ArrayOfArrayOfNumberOnly' do
|
||||
before do
|
||||
# run before each test
|
||||
@instance = Petstore::ArrayOfArrayOfNumberOnly.new
|
||||
end
|
||||
|
||||
after do
|
||||
# run after each test
|
||||
end
|
||||
|
||||
describe 'test an instance of ArrayOfArrayOfNumberOnly' do
|
||||
it 'should create an instact of ArrayOfArrayOfNumberOnly' do
|
||||
expect(@instance).to be_instance_of(Petstore::ArrayOfArrayOfNumberOnly)
|
||||
end
|
||||
end
|
||||
describe 'test attribute "array_array_number"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -0,0 +1,53 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'json'
|
||||
require 'date'
|
||||
|
||||
# Unit tests for Petstore::ArrayOfNumberOnly
|
||||
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
||||
# Please update as you see appropriate
|
||||
describe 'ArrayOfNumberOnly' do
|
||||
before do
|
||||
# run before each test
|
||||
@instance = Petstore::ArrayOfNumberOnly.new
|
||||
end
|
||||
|
||||
after do
|
||||
# run after each test
|
||||
end
|
||||
|
||||
describe 'test an instance of ArrayOfNumberOnly' do
|
||||
it 'should create an instact of ArrayOfNumberOnly' do
|
||||
expect(@instance).to be_instance_of(Petstore::ArrayOfNumberOnly)
|
||||
end
|
||||
end
|
||||
describe 'test attribute "array_number"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -0,0 +1,59 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'json'
|
||||
require 'date'
|
||||
|
||||
# Unit tests for Petstore::HasOnlyReadOnly
|
||||
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
||||
# Please update as you see appropriate
|
||||
describe 'HasOnlyReadOnly' do
|
||||
before do
|
||||
# run before each test
|
||||
@instance = Petstore::HasOnlyReadOnly.new
|
||||
end
|
||||
|
||||
after do
|
||||
# run after each test
|
||||
end
|
||||
|
||||
describe 'test an instance of HasOnlyReadOnly' do
|
||||
it 'should create an instact of HasOnlyReadOnly' do
|
||||
expect(@instance).to be_instance_of(Petstore::HasOnlyReadOnly)
|
||||
end
|
||||
end
|
||||
describe 'test attribute "bar"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
describe 'test attribute "foo"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
71
samples/client/petstore/ruby/spec/models/map_test_spec.rb
Normal file
71
samples/client/petstore/ruby/spec/models/map_test_spec.rb
Normal file
@ -0,0 +1,71 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'json'
|
||||
require 'date'
|
||||
|
||||
# Unit tests for Petstore::MapTest
|
||||
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
||||
# Please update as you see appropriate
|
||||
describe 'MapTest' do
|
||||
before do
|
||||
# run before each test
|
||||
@instance = Petstore::MapTest.new
|
||||
end
|
||||
|
||||
after do
|
||||
# run after each test
|
||||
end
|
||||
|
||||
describe 'test an instance of MapTest' do
|
||||
it 'should create an instact of MapTest' do
|
||||
expect(@instance).to be_instance_of(Petstore::MapTest)
|
||||
end
|
||||
end
|
||||
describe 'test attribute "map_map_of_string"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
describe 'test attribute "map_map_of_enum"' do
|
||||
it 'should work' do
|
||||
validator = Petstore::EnumTest::EnumAttributeValidator.new('Hash<String, Hash<String, String>>', [])
|
||||
validator.allowable_values.each do |value|
|
||||
expect { @instance.map_map_of_enum = value }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'test attribute "map_of_enum_string"' do
|
||||
it 'should work' do
|
||||
validator = Petstore::EnumTest::EnumAttributeValidator.new('Hash<String, String>', [])
|
||||
validator.allowable_values.each do |value|
|
||||
expect { @instance.map_of_enum_string = value }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
53
samples/client/petstore/ruby/spec/models/number_only_spec.rb
Normal file
53
samples/client/petstore/ruby/spec/models/number_only_spec.rb
Normal file
@ -0,0 +1,53 @@
|
||||
=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. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'json'
|
||||
require 'date'
|
||||
|
||||
# Unit tests for Petstore::NumberOnly
|
||||
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
||||
# Please update as you see appropriate
|
||||
describe 'NumberOnly' do
|
||||
before do
|
||||
# run before each test
|
||||
@instance = Petstore::NumberOnly.new
|
||||
end
|
||||
|
||||
after do
|
||||
# run after each test
|
||||
end
|
||||
|
||||
describe 'test an instance of NumberOnly' do
|
||||
it 'should create an instact of NumberOnly' do
|
||||
expect(@instance).to be_instance_of(Petstore::NumberOnly)
|
||||
end
|
||||
end
|
||||
describe 'test attribute "just_number"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user