Skip to content

Commit 8741435

Browse files
bopmwing328
authored andcommitted
Add support of Bearer Basic Authorization to Ruby client (#2856)
* Support for Bearer in Ruby Client * Update README.mustache * Update README.mustache * Update api_doc.mustache * Update api_doc.mustache * Update api_doc.mustache * samples * Uncommited changes * Formatting * More Formatting * Fomatting * More formatting * More formatting * Even more formatting * Even more formatting * More formatting * Even more formatting * More formatting * More formatting
1 parent c353f79 commit 8741435

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

modules/openapi-generator/src/main/resources/ruby-client/README.mustache

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ Please follow the [installation](#installation) procedure and then run the follo
6565
require '{{{gemName}}}'
6666
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}
6767
# Setup authorization
68-
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}
68+
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}}
6969
# Configure HTTP basic authorization: {{{name}}}
70-
config.username = 'YOUR USERNAME'
71-
config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
70+
config.username = 'YOUR_USERNAME'
71+
config.password = 'YOUR_PASSWORD'{{/isBasicBearer}}{{#isBasicBearer}}
72+
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
73+
config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
7274
# Configure API key authorization: {{{name}}}
7375
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
7476
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
@@ -128,7 +130,10 @@ Class | Method | HTTP request | Description
128130
- **API key parameter name**: {{keyParamName}}
129131
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
130132
{{/isApiKey}}
131-
{{#isBasic}}- **Type**: HTTP basic authentication
133+
{{#isBasic}}
134+
{{^isBasicBearer}}- **Type**: HTTP basic authentication
135+
{{/isBasicBearer}}{{#isBasicBearer}}- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
136+
{{/isBasicBearer}}
132137
{{/isBasic}}
133138
{{#isOAuth}}
134139

modules/openapi-generator/src/main/resources/ruby-client/api_doc.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ Method | HTTP request | Description
2727
require '{{{gemName}}}'
2828
{{#hasAuthMethods}}
2929
# setup authorization
30-
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}
30+
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}}
3131
# Configure HTTP basic authorization: {{{name}}}
3232
config.username = 'YOUR USERNAME'
33-
config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
33+
config.password = 'YOUR PASSWORD'{{/isBasicBearer}}{{#isBasicBearer}}
34+
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
35+
config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
3436
# Configure API key authorization: {{{name}}}
3537
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
3638
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)

modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,27 @@ module {{moduleName}}
199199
},
200200
{{/isApiKey}}
201201
{{#isBasic}}
202+
{{^isBasicBearer}}
202203
'{{name}}' =>
203204
{
204205
type: 'basic',
205206
in: 'header',
206207
key: 'Authorization',
207208
value: basic_auth_token
208209
},
210+
{{/isBasicBearer}}
211+
{{#isBasicBearer}}
212+
'{{name}}' =>
213+
{
214+
type: 'bearer',
215+
in: 'header',
216+
{{#bearerFormat}}
217+
format: '{{{.}}}',
218+
{{/bearerFormat}}
219+
key: 'Authorization',
220+
value: "Bearer #{access_token}"
221+
},
222+
{{/isBasicBearer}}
209223
{{/isBasic}}
210224
{{#isOAuth}}
211225
'{{name}}' =>

samples/openapi3/client/petstore/ruby/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Class | Method | HTTP request | Description
180180

181181
### bearer_test
182182

183-
- **Type**: HTTP basic authentication
183+
- **Type**: Bearer authentication (JWT)
184184

185185
### http_basic_test
186186

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,8 @@ Fake endpoint to test group parameters (optional)
547547
require 'petstore'
548548
# setup authorization
549549
Petstore.configure do |config|
550-
# Configure HTTP basic authorization: bearer_test
551-
config.username = 'YOUR USERNAME'
552-
config.password = 'YOUR PASSWORD'
550+
# Configure Bearer authorization (JWT): bearer_test
551+
config.access_token = 'YOUR_BEARER_TOKEN'
553552
end
554553

555554
api_instance = Petstore::FakeApi.new

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ def auth_settings
212212
},
213213
'bearer_test' =>
214214
{
215-
type: 'basic',
215+
type: 'bearer',
216216
in: 'header',
217+
format: 'JWT',
217218
key: 'Authorization',
218-
value: basic_auth_token
219+
value: "Bearer #{access_token}"
219220
},
220221
'http_basic_test' =>
221222
{

0 commit comments

Comments
 (0)