Skip to content

Commit 38e34e0

Browse files
committed
Merge pull request #584 from wing328/ruby_fix_accept
Fixed Ruby header: "Accept", "Content-Type"
2 parents 9159892 + 1c0cb7f commit 38e34e0

File tree

4 files changed

+189
-21
lines changed

4 files changed

+189
-21
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ class {{classname}}
4141
query_param_keys.include? key
4242
end
4343

44-
# header parameters, if any
44+
# header parameters
4545
headers = {}
46+
47+
_header_accept = '{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}'
48+
if _header_accept != ''
49+
headerParams['Accept'] = _header_accept
50+
end
51+
_header_content_type = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
52+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
53+
4654
{{#headerParams}}{{#optional}}headers[:'{{{baseName}}}'] = options[:'{{{paramName}}}'] if options[:'{{{paramName}}}']{{/optional}}{{/headerParams}}
4755
{{#headerParams}}{{^optional}}headers[:'{{{baseName}}}'] = {{{paramName}}}{{/optional}}{{/headerParams}}
4856
# http body (model)

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ def self.updatePet (body, opts={})
3232
query_param_keys.include? key
3333
end
3434

35-
# header parameters, if any
35+
# header parameters
3636
headers = {}
37+
38+
_header_accept = 'application/json, application/xml'
39+
if _header_accept != ''
40+
headerParams['Accept'] = _header_accept
41+
end
42+
_header_content_type = ['application/json', 'application/xml', ]
43+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
44+
3745

3846

3947
# http body (model)
@@ -92,8 +100,16 @@ def self.addPet (body, opts={})
92100
query_param_keys.include? key
93101
end
94102

95-
# header parameters, if any
103+
# header parameters
96104
headers = {}
105+
106+
_header_accept = 'application/json, application/xml'
107+
if _header_accept != ''
108+
headerParams['Accept'] = _header_accept
109+
end
110+
_header_content_type = ['application/json', 'application/xml', ]
111+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
112+
97113

98114

99115
# http body (model)
@@ -152,8 +168,16 @@ def self.findPetsByStatus (status, opts={})
152168
query_param_keys.include? key
153169
end
154170

155-
# header parameters, if any
171+
# header parameters
156172
headers = {}
173+
174+
_header_accept = 'application/json, application/xml'
175+
if _header_accept != ''
176+
headerParams['Accept'] = _header_accept
177+
end
178+
_header_content_type = []
179+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
180+
157181

158182

159183
# http body (model)
@@ -194,8 +218,16 @@ def self.findPetsByTags (tags, opts={})
194218
query_param_keys.include? key
195219
end
196220

197-
# header parameters, if any
221+
# header parameters
198222
headers = {}
223+
224+
_header_accept = 'application/json, application/xml'
225+
if _header_accept != ''
226+
headerParams['Accept'] = _header_accept
227+
end
228+
_header_content_type = []
229+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
230+
199231

200232

201233
# http body (model)
@@ -237,8 +269,16 @@ def self.getPetById (pet_id, opts={})
237269
query_param_keys.include? key
238270
end
239271

240-
# header parameters, if any
272+
# header parameters
241273
headers = {}
274+
275+
_header_accept = 'application/json, application/xml'
276+
if _header_accept != ''
277+
headerParams['Accept'] = _header_accept
278+
end
279+
_header_content_type = []
280+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
281+
242282

243283

244284
# http body (model)
@@ -283,8 +323,16 @@ def self.updatePetWithForm (pet_id, name, status, opts={})
283323
query_param_keys.include? key
284324
end
285325

286-
# header parameters, if any
326+
# header parameters
287327
headers = {}
328+
329+
_header_accept = 'application/json, application/xml'
330+
if _header_accept != ''
331+
headerParams['Accept'] = _header_accept
332+
end
333+
_header_content_type = ['application/x-www-form-urlencoded', ]
334+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
335+
288336

289337

290338
# http body (model)
@@ -328,8 +376,16 @@ def self.deletePet (api_key, pet_id, opts={})
328376
query_param_keys.include? key
329377
end
330378

331-
# header parameters, if any
379+
# header parameters
332380
headers = {}
381+
382+
_header_accept = 'application/json, application/xml'
383+
if _header_accept != ''
384+
headerParams['Accept'] = _header_accept
385+
end
386+
_header_content_type = []
387+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
388+
333389

334390
headers[:'api_key'] = api_key
335391
# http body (model)
@@ -373,8 +429,16 @@ def self.uploadFile (pet_id, additional_metadata, file, opts={})
373429
query_param_keys.include? key
374430
end
375431

376-
# header parameters, if any
432+
# header parameters
377433
headers = {}
434+
435+
_header_accept = 'application/json, application/xml'
436+
if _header_accept != ''
437+
headerParams['Accept'] = _header_accept
438+
end
439+
_header_content_type = ['multipart/form-data', ]
440+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
441+
378442

379443

380444
# http body (model)

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ def self.getInventory (opts={})
3030
query_param_keys.include? key
3131
end
3232

33-
# header parameters, if any
33+
# header parameters
3434
headers = {}
35+
36+
_header_accept = 'application/json, application/xml'
37+
if _header_accept != ''
38+
headerParams['Accept'] = _header_accept
39+
end
40+
_header_content_type = []
41+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
42+
3543

3644

3745
# http body (model)
@@ -72,8 +80,16 @@ def self.placeOrder (body, opts={})
7280
query_param_keys.include? key
7381
end
7482

75-
# header parameters, if any
83+
# header parameters
7684
headers = {}
85+
86+
_header_accept = 'application/json, application/xml'
87+
if _header_accept != ''
88+
headerParams['Accept'] = _header_accept
89+
end
90+
_header_content_type = []
91+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
92+
7793

7894

7995
# http body (model)
@@ -134,8 +150,16 @@ def self.getOrderById (order_id, opts={})
134150
query_param_keys.include? key
135151
end
136152

137-
# header parameters, if any
153+
# header parameters
138154
headers = {}
155+
156+
_header_accept = 'application/json, application/xml'
157+
if _header_accept != ''
158+
headerParams['Accept'] = _header_accept
159+
end
160+
_header_content_type = []
161+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
162+
139163

140164

141165
# http body (model)
@@ -176,8 +200,16 @@ def self.deleteOrder (order_id, opts={})
176200
query_param_keys.include? key
177201
end
178202

179-
# header parameters, if any
203+
# header parameters
180204
headers = {}
205+
206+
_header_accept = 'application/json, application/xml'
207+
if _header_accept != ''
208+
headerParams['Accept'] = _header_accept
209+
end
210+
_header_content_type = []
211+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
212+
181213

182214

183215
# http body (model)

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ def self.createUser (body, opts={})
3232
query_param_keys.include? key
3333
end
3434

35-
# header parameters, if any
35+
# header parameters
3636
headers = {}
37+
38+
_header_accept = 'application/json, application/xml'
39+
if _header_accept != ''
40+
headerParams['Accept'] = _header_accept
41+
end
42+
_header_content_type = []
43+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
44+
3745

3846

3947
# http body (model)
@@ -92,8 +100,16 @@ def self.createUsersWithArrayInput (body, opts={})
92100
query_param_keys.include? key
93101
end
94102

95-
# header parameters, if any
103+
# header parameters
96104
headers = {}
105+
106+
_header_accept = 'application/json, application/xml'
107+
if _header_accept != ''
108+
headerParams['Accept'] = _header_accept
109+
end
110+
_header_content_type = []
111+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
112+
97113

98114

99115
# http body (model)
@@ -152,8 +168,16 @@ def self.createUsersWithListInput (body, opts={})
152168
query_param_keys.include? key
153169
end
154170

155-
# header parameters, if any
171+
# header parameters
156172
headers = {}
173+
174+
_header_accept = 'application/json, application/xml'
175+
if _header_accept != ''
176+
headerParams['Accept'] = _header_accept
177+
end
178+
_header_content_type = []
179+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
180+
157181

158182

159183
# http body (model)
@@ -214,8 +238,16 @@ def self.loginUser (username, password, opts={})
214238
query_param_keys.include? key
215239
end
216240

217-
# header parameters, if any
241+
# header parameters
218242
headers = {}
243+
244+
_header_accept = 'application/json, application/xml'
245+
if _header_accept != ''
246+
headerParams['Accept'] = _header_accept
247+
end
248+
_header_content_type = []
249+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
250+
219251

220252

221253
# http body (model)
@@ -253,8 +285,16 @@ def self.logoutUser (opts={})
253285
query_param_keys.include? key
254286
end
255287

256-
# header parameters, if any
288+
# header parameters
257289
headers = {}
290+
291+
_header_accept = 'application/json, application/xml'
292+
if _header_accept != ''
293+
headerParams['Accept'] = _header_accept
294+
end
295+
_header_content_type = []
296+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
297+
258298

259299

260300
# http body (model)
@@ -294,8 +334,16 @@ def self.getUserByName (username, opts={})
294334
query_param_keys.include? key
295335
end
296336

297-
# header parameters, if any
337+
# header parameters
298338
headers = {}
339+
340+
_header_accept = 'application/json, application/xml'
341+
if _header_accept != ''
342+
headerParams['Accept'] = _header_accept
343+
end
344+
_header_content_type = []
345+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
346+
299347

300348

301349
# http body (model)
@@ -338,8 +386,16 @@ def self.updateUser (username, body, opts={})
338386
query_param_keys.include? key
339387
end
340388

341-
# header parameters, if any
389+
# header parameters
342390
headers = {}
391+
392+
_header_accept = 'application/json, application/xml'
393+
if _header_accept != ''
394+
headerParams['Accept'] = _header_accept
395+
end
396+
_header_content_type = []
397+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
398+
343399

344400

345401
# http body (model)
@@ -399,8 +455,16 @@ def self.deleteUser (username, opts={})
399455
query_param_keys.include? key
400456
end
401457

402-
# header parameters, if any
458+
# header parameters
403459
headers = {}
460+
461+
_header_accept = 'application/json, application/xml'
462+
if _header_accept != ''
463+
headerParams['Accept'] = _header_accept
464+
end
465+
_header_content_type = []
466+
headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json'
467+
404468

405469

406470
# http body (model)

0 commit comments

Comments
 (0)