@@ -13,24 +13,14 @@ def initialize(http_method, path, attributes={})
13
13
attributes [ :format ] ||= Swagger . configuration . format
14
14
attributes [ :params ] ||= { }
15
15
16
+ update_params_for_auth ( attributes )
17
+
16
18
# Set default headers
17
19
default_headers = {
18
20
'Content-Type' => "application/#{ attributes [ :format ] . downcase } " ,
19
- :api_key => Swagger . configuration . api_key ,
20
21
'User-Agent' => Swagger . configuration . user_agent
21
22
}
22
23
23
- # api_key from headers hash trumps the default, even if its value is blank
24
- if attributes [ :headers ] . present? && attributes [ :headers ] . has_key? ( :api_key )
25
- default_headers . delete ( :api_key )
26
- end
27
-
28
- # api_key from params hash trumps all others (headers and default_headers)
29
- if attributes [ :params ] . present? && attributes [ :params ] . has_key? ( :api_key )
30
- default_headers . delete ( :api_key )
31
- attributes [ :headers ] . delete ( :api_key ) if attributes [ :headers ] . present?
32
- end
33
-
34
24
# Merge argument headers into defaults
35
25
attributes [ :headers ] = default_headers . merge ( attributes [ :headers ] || { } )
36
26
@@ -46,6 +36,33 @@ def initialize(http_method, path, attributes={})
46
36
end
47
37
end
48
38
39
+ def update_params_for_auth ( attributes )
40
+ ( attributes [ :auth_names ] || [ ] ) . each do |auth_name |
41
+ case auth_name
42
+
43
+ when 'api_key'
44
+ attributes [ :headers ] ||= { }
45
+ attributes [ :headers ] [ 'api_key' ] = get_api_key_with_prefix ( 'api_key' )
46
+
47
+
48
+
49
+ when 'petstore_auth'
50
+
51
+
52
+ # TODO: support oauth
53
+
54
+ end
55
+ end
56
+ end
57
+
58
+ def get_api_key_with_prefix ( param_name )
59
+ if Swagger . configuration . api_key_prefix [ param_name ] . present?
60
+ "#{ Swagger . configuration . api_key_prefix [ param_name ] } #{ Swagger . configuration . api_key [ param_name ] } "
61
+ else
62
+ Swagger . configuration . api_key [ param_name ]
63
+ end
64
+ end
65
+
49
66
# Construct a base URL
50
67
def url ( options = { } )
51
68
u = Addressable ::URI . new (
@@ -58,9 +75,6 @@ def url(options = {})
58
75
# Drop trailing question mark, if present
59
76
u . sub! /\? $/ , ''
60
77
61
- # Obfuscate API key?
62
- u . sub! /api\_ key=\w +/ , 'api_key=YOUR_API_KEY' if options [ :obfuscated ]
63
-
64
78
u
65
79
end
66
80
@@ -129,7 +143,7 @@ def query_string
129
143
next if self . path . include? "{#{ key } }" # skip path params
130
144
next if value . blank? && value . class != FalseClass # skip empties
131
145
if Swagger . configuration . camelize_params
132
- key = key . to_s . camelize ( :lower ) . to_sym unless key . to_sym == :api_key # api_key is not a camelCased param
146
+ key = key . to_s . camelize ( :lower ) . to_sym
133
147
end
134
148
query_values [ key ] = value . to_s
135
149
end
0 commit comments