Skip to content

Commit 7c8333e

Browse files
committed
update ruby samples
1 parent 4be1145 commit 7c8333e

File tree

8 files changed

+372
-33
lines changed

8 files changed

+372
-33
lines changed

samples/client/petstore/ruby/README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
88

99
- API version: 1.0.0
1010
- Package version: 1.0.0
11-
- Build date: 2016-07-04T22:10:18.328+08:00
11+
- Build date: 2016-07-14T16:12:28.313+08:00
1212
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
1313

1414
## Installation
@@ -57,30 +57,15 @@ require 'petstore'
5757

5858
api_instance = Petstore::FakeApi.new
5959

60-
number = 3.4 # Float | None
60+
body = Petstore::Client.new # Client | client model
6161

62-
double = 1.2 # Float | None
63-
64-
string = "string_example" # String | None
65-
66-
byte = "B" # String | None
67-
68-
opts = {
69-
integer: 56, # Integer | None
70-
int32: 56, # Integer | None
71-
int64: 789, # Integer | None
72-
float: 3.4, # Float | None
73-
binary: "B", # String | None
74-
date: Date.parse("2013-10-20"), # Date | None
75-
date_time: DateTime.parse("2013-10-20T19:20:30+01:00"), # DateTime | None
76-
password: "password_example" # String | None
77-
}
7862

7963
begin
80-
#Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
81-
api_instance.test_endpoint_parameters(number, double, string, byte, opts)
64+
#To test \"client\" model
65+
result = api_instance.test_client_model(body)
66+
p result
8267
rescue Petstore::ApiError => e
83-
puts "Exception when calling FakeApi->test_endpoint_parameters: #{e}"
68+
puts "Exception when calling FakeApi->test_client_model: #{e}"
8469
end
8570

8671
```
@@ -91,6 +76,7 @@ All URIs are relative to *http://petstore.swagger.io/v2*
9176

9277
Class | Method | HTTP request | Description
9378
------------ | ------------- | ------------- | -------------
79+
*Petstore::FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
9480
*Petstore::FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
9581
*Petstore::FakeApi* | [**test_enum_query_parameters**](docs/FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
9682
*Petstore::PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
@@ -126,6 +112,7 @@ Class | Method | HTTP request | Description
126112
- [Petstore::ArrayTest](docs/ArrayTest.md)
127113
- [Petstore::Cat](docs/Cat.md)
128114
- [Petstore::Category](docs/Category.md)
115+
- [Petstore::Client](docs/Client.md)
129116
- [Petstore::Dog](docs/Dog.md)
130117
- [Petstore::EnumClass](docs/EnumClass.md)
131118
- [Petstore::EnumTest](docs/EnumTest.md)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Petstore::Client
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**client** | **String** | | [optional]
7+
8+

samples/client/petstore/ruby/docs/FakeApi.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,56 @@ All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7+
[**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
78
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
89
[**test_enum_query_parameters**](FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
910

1011

12+
# **test_client_model**
13+
> Client test_client_model(body)
14+
15+
To test \"client\" model
16+
17+
### Example
18+
```ruby
19+
# load the gem
20+
require 'petstore'
21+
22+
api_instance = Petstore::FakeApi.new
23+
24+
body = Petstore::Client.new # Client | client model
25+
26+
27+
begin
28+
#To test \"client\" model
29+
result = api_instance.test_client_model(body)
30+
p result
31+
rescue Petstore::ApiError => e
32+
puts "Exception when calling FakeApi->test_client_model: #{e}"
33+
end
34+
```
35+
36+
### Parameters
37+
38+
Name | Type | Description | Notes
39+
------------- | ------------- | ------------- | -------------
40+
**body** | [**Client**](Client.md)| client model |
41+
42+
### Return type
43+
44+
[**Client**](Client.md)
45+
46+
### Authorization
47+
48+
No authorization required
49+
50+
### HTTP request headers
51+
52+
- **Content-Type**: application/json
53+
- **Accept**: application/json
54+
55+
56+
1157
# **test_endpoint_parameters**
1258
> test_endpoint_parameters(number, double, string, byte, opts)
1359

samples/client/petstore/ruby/lib/petstore.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
require 'petstore/models/array_test'
3838
require 'petstore/models/cat'
3939
require 'petstore/models/category'
40+
require 'petstore/models/client'
4041
require 'petstore/models/dog'
4142
require 'petstore/models/enum_class'
4243
require 'petstore/models/enum_test'

samples/client/petstore/ruby/lib/petstore/api/fake_api.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,63 @@ def initialize(api_client = ApiClient.default)
3131
@api_client = api_client
3232
end
3333

34+
# To test \"client\" model
35+
#
36+
# @param body client model
37+
# @param [Hash] opts the optional parameters
38+
# @return [Client]
39+
def test_client_model(body, opts = {})
40+
data, _status_code, _headers = test_client_model_with_http_info(body, opts)
41+
return data
42+
end
43+
44+
# To test \"client\" model
45+
#
46+
# @param body client model
47+
# @param [Hash] opts the optional parameters
48+
# @return [Array<(Client, Fixnum, Hash)>] Client data, response status code and response headers
49+
def test_client_model_with_http_info(body, opts = {})
50+
if @api_client.config.debugging
51+
@api_client.config.logger.debug "Calling API: FakeApi.test_client_model ..."
52+
end
53+
# verify the required parameter 'body' is set
54+
fail ArgumentError, "Missing the required parameter 'body' when calling FakeApi.test_client_model" if body.nil?
55+
# resource path
56+
local_var_path = "/fake".sub('{format}','json')
57+
58+
# query parameters
59+
query_params = {}
60+
61+
# header parameters
62+
header_params = {}
63+
64+
# HTTP header 'Accept' (if needed)
65+
local_header_accept = ['application/json']
66+
local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result
67+
68+
# HTTP header 'Content-Type'
69+
local_header_content_type = ['application/json']
70+
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
71+
72+
# form parameters
73+
form_params = {}
74+
75+
# http body (model)
76+
post_body = @api_client.object_to_http_body(body)
77+
auth_names = []
78+
data, status_code, headers = @api_client.call_api(:PATCH, local_var_path,
79+
:header_params => header_params,
80+
:query_params => query_params,
81+
:form_params => form_params,
82+
:body => post_body,
83+
:auth_names => auth_names,
84+
:return_type => 'Client')
85+
if @api_client.config.debugging
86+
@api_client.config.logger.debug "API called: FakeApi#test_client_model\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
87+
end
88+
return data, status_code, headers
89+
end
90+
3491
# Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
3592
# Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
3693
# @param number None
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
=begin
2+
#Swagger Petstore
3+
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
6+
OpenAPI spec version: 1.0.0
7+
8+
Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
10+
Licensed under the Apache License, Version 2.0 (the "License");
11+
you may not use this file except in compliance with the License.
12+
You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
22+
=end
23+
24+
require 'date'
25+
26+
module Petstore
27+
28+
class Client
29+
attr_accessor :client
30+
31+
32+
# Attribute mapping from ruby-style variable name to JSON key.
33+
def self.attribute_map
34+
{
35+
:'client' => :'client'
36+
}
37+
end
38+
39+
# Attribute type mapping.
40+
def self.swagger_types
41+
{
42+
:'client' => :'String'
43+
}
44+
end
45+
46+
# Initializes the object
47+
# @param [Hash] attributes Model attributes in the form of hash
48+
def initialize(attributes = {})
49+
return unless attributes.is_a?(Hash)
50+
51+
# convert string to symbol for hash key
52+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
53+
54+
if attributes.has_key?(:'client')
55+
self.client = attributes[:'client']
56+
end
57+
58+
end
59+
60+
# Show invalid properties with the reasons. Usually used together with valid?
61+
# @return Array for valid properies with the reasons
62+
def list_invalid_properties
63+
invalid_properties = Array.new
64+
return invalid_properties
65+
end
66+
67+
# Check to see if the all the properties in the model are valid
68+
# @return true if the model is valid
69+
def valid?
70+
return true
71+
end
72+
73+
# Checks equality by comparing each attribute.
74+
# @param [Object] Object to be compared
75+
def ==(o)
76+
return true if self.equal?(o)
77+
self.class == o.class &&
78+
client == o.client
79+
end
80+
81+
# @see the `==` method
82+
# @param [Object] Object to be compared
83+
def eql?(o)
84+
self == o
85+
end
86+
87+
# Calculates hash code according to all attributes.
88+
# @return [Fixnum] Hash code
89+
def hash
90+
[client].hash
91+
end
92+
93+
# Builds the object from hash
94+
# @param [Hash] attributes Model attributes in the form of hash
95+
# @return [Object] Returns the model itself
96+
def build_from_hash(attributes)
97+
return nil unless attributes.is_a?(Hash)
98+
self.class.swagger_types.each_pair do |key, type|
99+
if type =~ /^Array<(.*)>/i
100+
# check to ensure the input is an array given that the the attribute
101+
# is documented as an array but the input is not
102+
if attributes[self.class.attribute_map[key]].is_a?(Array)
103+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
104+
end
105+
elsif !attributes[self.class.attribute_map[key]].nil?
106+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
107+
end # or else data not found in attributes(hash), not an issue as the data can be optional
108+
end
109+
110+
self
111+
end
112+
113+
# Deserializes the data based on type
114+
# @param string type Data type
115+
# @param string value Value to be deserialized
116+
# @return [Object] Deserialized data
117+
def _deserialize(type, value)
118+
case type.to_sym
119+
when :DateTime
120+
DateTime.parse(value)
121+
when :Date
122+
Date.parse(value)
123+
when :String
124+
value.to_s
125+
when :Integer
126+
value.to_i
127+
when :Float
128+
value.to_f
129+
when :BOOLEAN
130+
if value.to_s =~ /^(true|t|yes|y|1)$/i
131+
true
132+
else
133+
false
134+
end
135+
when :Object
136+
# generic object (usually a Hash), return directly
137+
value
138+
when /\AArray<(?<inner_type>.+)>\z/
139+
inner_type = Regexp.last_match[:inner_type]
140+
value.map { |v| _deserialize(inner_type, v) }
141+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
142+
k_type = Regexp.last_match[:k_type]
143+
v_type = Regexp.last_match[:v_type]
144+
{}.tap do |hash|
145+
value.each do |k, v|
146+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
147+
end
148+
end
149+
else # model
150+
temp_model = Petstore.const_get(type).new
151+
temp_model.build_from_hash(value)
152+
end
153+
end
154+
155+
# Returns the string representation of the object
156+
# @return [String] String presentation of the object
157+
def to_s
158+
to_hash.to_s
159+
end
160+
161+
# to_body is an alias to to_hash (backward compatibility)
162+
# @return [Hash] Returns the object in the form of hash
163+
def to_body
164+
to_hash
165+
end
166+
167+
# Returns the object in the form of hash
168+
# @return [Hash] Returns the object in the form of hash
169+
def to_hash
170+
hash = {}
171+
self.class.attribute_map.each_pair do |attr, param|
172+
value = self.send(attr)
173+
next if value.nil?
174+
hash[param] = _to_hash(value)
175+
end
176+
hash
177+
end
178+
179+
# Outputs non-array value in the form of hash
180+
# For object, use to_hash. Otherwise, just return the value
181+
# @param [Object] value Any valid value
182+
# @return [Hash] Returns the value in the form of hash
183+
def _to_hash(value)
184+
if value.is_a?(Array)
185+
value.compact.map{ |v| _to_hash(v) }
186+
elsif value.is_a?(Hash)
187+
{}.tap do |hash|
188+
value.each { |k, v| hash[k] = _to_hash(v) }
189+
end
190+
elsif value.respond_to? :to_hash
191+
value.to_hash
192+
else
193+
value
194+
end
195+
end
196+
197+
end
198+
199+
end

0 commit comments

Comments
 (0)