Skip to content

Commit fb2ab79

Browse files
committed
update ruby doc
1 parent 3d12c88 commit fb2ab79

File tree

4 files changed

+274
-79
lines changed

4 files changed

+274
-79
lines changed

modules/swagger-codegen/src/main/resources/ruby/api.mustache

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ class {{classname}}
99
URI.encode(string.to_s)
1010
end
1111

12-
{{#operation}}
12+
{{#operation}}
13+
{{newline}}
14+
# {{summary}}
15+
# {{notes}}{{newLine}}
16+
{{#allParams}}{{^optional}}{{newLine}} # @param {{paramName}} {{description}}
17+
{{/optional}}{{/allParams}}{{#allParams}}{{#optional}}{{newLine}} # @option opts [{{dataType}}] :{{baseName}} {{description}}
18+
{{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}}
1319
def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}},{{/allParams}} opts={})
1420
query_param_keys = [{{#queryParams}}:{{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}}]
1521

1622
{{#requiredParamCount}}
17-
1823
# verify existence of params
1924
{{#requiredParams}}
2025
raise "{{{paramName}}} is required" if {{{paramName}}}.nil?
@@ -40,7 +45,6 @@ class {{classname}}
4045
headers = {}
4146
{{#headerParams}}{{#optional}}headers[:'{{{baseName}}}'] = options[:'{{{paramName}}}'] if options[:'{{{paramName}}}']{{/optional}}{{/headerParams}}
4247
{{#headerParams}}{{^optional}}headers[:'{{{baseName}}}'] = {{{paramName}}}{{/optional}}{{/headerParams}}
43-
4448
# http body (model)
4549
post_body = nil
4650
{{#bodyParam}}
@@ -55,7 +59,6 @@ class {{classname}}
5559
end
5660
end
5761
post_body = array
58-
5962
else
6063
if body.respond_to?("to_body".to_sym)
6164
post_body = body.to_body
@@ -65,12 +68,10 @@ class {{classname}}
6568
end
6669
end
6770
{{/bodyParam}}
68-
6971
# form parameters
7072
form_parameter_hash = {}
7173
{{#formParams}}{{#optional}}form_parameter_hash["{{baseName}}"] = options[:'{{paramName}}'] if options[:'{{paramName}}']{{/optional}}
7274
{{^optional}}form_parameter_hash["{{baseName}}"] = {{paramName}}{{/optional}}{{/formParams}}
73-
7475
{{#returnType}}
7576
response = Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
7677
{{#returnContainer}}
@@ -81,7 +82,6 @@ class {{classname}}
8182
{{/returnType}}
8283
{{newline}}
8384
end
84-
8585
{{/operation}}
8686
end
8787
{{/operations}}

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

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ def self.escapeString(string)
88
URI.encode(string.to_s)
99
end
1010

11-
11+
12+
# Update an existing pet
13+
#
14+
# @param body Pet object that needs to be added to the store
15+
# @return void
1216
def self.updatePet (body, opts={})
1317
query_param_keys = []
1418

@@ -32,7 +36,6 @@ def self.updatePet (body, opts={})
3236
headers = {}
3337

3438

35-
3639
# http body (model)
3740
post_body = nil
3841

@@ -47,7 +50,6 @@ def self.updatePet (body, opts={})
4750
end
4851
end
4952
post_body = array
50-
5153
else
5254
if body.respond_to?("to_body".to_sym)
5355
post_body = body.to_body
@@ -57,19 +59,20 @@ def self.updatePet (body, opts={})
5759
end
5860
end
5961

60-
6162
# form parameters
6263
form_parameter_hash = {}
6364

64-
6565

6666

6767
Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
6868

6969

7070
end
7171

72-
72+
# Add a new pet to the store
73+
#
74+
# @param body Pet object that needs to be added to the store
75+
# @return void
7376
def self.addPet (body, opts={})
7477
query_param_keys = []
7578

@@ -93,7 +96,6 @@ def self.addPet (body, opts={})
9396
headers = {}
9497

9598

96-
9799
# http body (model)
98100
post_body = nil
99101

@@ -108,7 +110,6 @@ def self.addPet (body, opts={})
108110
end
109111
end
110112
post_body = array
111-
112113
else
113114
if body.respond_to?("to_body".to_sym)
114115
post_body = body.to_body
@@ -118,19 +119,20 @@ def self.addPet (body, opts={})
118119
end
119120
end
120121

121-
122122
# form parameters
123123
form_parameter_hash = {}
124124

125-
126125

127126

128127
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
129128

130129

131130
end
132131

133-
132+
# Finds Pets by status
133+
# Multiple status values can be provided with comma seperated strings
134+
# @param status Status values that need to be considered for filter
135+
# @return array[Pet]
134136
def self.findPetsByStatus (status, opts={})
135137
query_param_keys = [:status]
136138

@@ -154,15 +156,12 @@ def self.findPetsByStatus (status, opts={})
154156
headers = {}
155157

156158

157-
158159
# http body (model)
159160
post_body = nil
160161

161-
162162
# form parameters
163163
form_parameter_hash = {}
164164

165-
166165

167166
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
168167

@@ -172,7 +171,10 @@ def self.findPetsByStatus (status, opts={})
172171

173172
end
174173

175-
174+
# Finds Pets by tags
175+
# Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
176+
# @param tags Tags to filter by
177+
# @return array[Pet]
176178
def self.findPetsByTags (tags, opts={})
177179
query_param_keys = [:tags]
178180

@@ -196,15 +198,12 @@ def self.findPetsByTags (tags, opts={})
196198
headers = {}
197199

198200

199-
200201
# http body (model)
201202
post_body = nil
202203

203-
204204
# form parameters
205205
form_parameter_hash = {}
206206

207-
208207

209208
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
210209

@@ -214,7 +213,10 @@ def self.findPetsByTags (tags, opts={})
214213

215214
end
216215

217-
216+
# Find pet by ID
217+
# Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
218+
# @param pet_id ID of pet that needs to be fetched
219+
# @return Pet
218220
def self.getPetById (pet_id, opts={})
219221
query_param_keys = []
220222

@@ -239,15 +241,12 @@ def self.getPetById (pet_id, opts={})
239241
headers = {}
240242

241243

242-
243244
# http body (model)
244245
post_body = nil
245246

246-
247247
# form parameters
248248
form_parameter_hash = {}
249249

250-
251250

252251
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
253252
Pet.new(response)
@@ -256,7 +255,12 @@ def self.getPetById (pet_id, opts={})
256255

257256
end
258257

259-
258+
# Updates a pet in the store with form data
259+
#
260+
# @param pet_id ID of pet that needs to be updated
261+
# @param name Updated name of the pet
262+
# @param status Updated status of the pet
263+
# @return void
260264
def self.updatePetWithForm (pet_id,name,status, opts={})
261265
query_param_keys = []
262266

@@ -283,25 +287,26 @@ def self.updatePetWithForm (pet_id,name,status, opts={})
283287
headers = {}
284288

285289

286-
287290
# http body (model)
288291
post_body = nil
289292

290-
291293
# form parameters
292294
form_parameter_hash = {}
293295

294296
form_parameter_hash["name"] = name
295297
form_parameter_hash["status"] = status
296-
297298

298299

299300
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
300301

301302

302303
end
303304

304-
305+
# Deletes a pet
306+
#
307+
# @param api_key
308+
# @param pet_id Pet id to delete
309+
# @return void
305310
def self.deletePet (api_key,pet_id, opts={})
306311
query_param_keys = []
307312

@@ -327,23 +332,25 @@ def self.deletePet (api_key,pet_id, opts={})
327332
headers = {}
328333

329334
headers[:'api_key'] = api_key
330-
331335
# http body (model)
332336
post_body = nil
333337

334-
335338
# form parameters
336339
form_parameter_hash = {}
337340

338-
339341

340342

341343
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
342344

343345

344346
end
345347

346-
348+
# uploads an image
349+
#
350+
# @param pet_id ID of pet to update
351+
# @param additional_metadata Additional data to pass to server
352+
# @param file file to upload
353+
# @return void
347354
def self.uploadFile (pet_id,additional_metadata,file, opts={})
348355
query_param_keys = []
349356

@@ -370,22 +377,18 @@ def self.uploadFile (pet_id,additional_metadata,file, opts={})
370377
headers = {}
371378

372379

373-
374380
# http body (model)
375381
post_body = nil
376382

377-
378383
# form parameters
379384
form_parameter_hash = {}
380385

381386
form_parameter_hash["additionalMetadata"] = additional_metadata
382387
form_parameter_hash["file"] = file
383-
384388

385389

386390
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
387391

388392

389393
end
390-
391394
end

0 commit comments

Comments
 (0)