Skip to content

Commit d86b733

Browse files
committed
handle multiple auth
1 parent 82c572e commit d86b733

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

.generator/src/generator/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def cli(specs, output):
6767
env.globals["get_accessors"] = openapi.get_accessors
6868
env.globals["get_default"] = openapi.get_default
6969
env.globals["get_container_type"] = openapi.get_container_type
70+
env.globals["get_security_names"] = openapi.get_security_names
7071

7172
api_j2 = env.get_template("Api.j2")
7273
model_j2 = env.get_template("model.j2")

.generator/src/generator/openapi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ def get_container_type(operation, attribute_path, stop=None):
589589
return type_to_java(parameter)
590590

591591

592+
def get_security_names(security):
593+
if security is None:
594+
return []
595+
596+
auth_names = set()
597+
for auth in security:
598+
for key in auth.keys() if isinstance(auth, dict) else [auth]:
599+
auth_names.add(key)
600+
601+
return list(auth_names)
602+
603+
592604
class Operation:
593605
def __init__(self, name, spec, method, path):
594606
self.name = name

.generator/src/generator/templates/Api.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public class {{ name }} {
379379
if ({{ name|variable_name }} != null) { localVarFormParams.put("{{ name }}", {{ name|variable_name }}); }
380380
{%- endfor %}
381381

382-
Invocation.Builder builder = apiClient.createBuilder("{{ version }}.{{ name }}.{{ operationId }}", localVarPath, {% if queryParams %}localVarQueryParams{% else %}new ArrayList<Pair>(){% endif %}, localVarHeaderParams, new HashMap<String, String>(), new String[] { {%- for mediaType in operation|accept_headers %}"{{ mediaType }}"{% if loop.nextitem %}, {% endif %}{% endfor %} }, new String[] { {% for authMethod in authMethods|reverse %}{%- for name in authMethod %}"{{ name }}"{% if loop.nextitem %}, {% endif %}{% endfor %}{% if loop.nextitem %}, {% endif %}{% endfor %} });
382+
Invocation.Builder builder = apiClient.createBuilder("{{ version }}.{{ name }}.{{ operationId }}", localVarPath, {% if queryParams %}localVarQueryParams{% else %}new ArrayList<Pair>(){% endif %}, localVarHeaderParams, new HashMap<String, String>(), new String[] { {%- for mediaType in operation|accept_headers %}"{{ mediaType }}"{% if loop.nextitem %}, {% endif %}{% endfor %} }, new String[] { {% for name in get_security_names(authMethods)|sort %}"{{ name }}"{% if loop.nextitem %}, {% endif %}{% endfor %} });
383383
return apiClient.invokeAPI("{{ method.upper() }}", builder, localVarHeaderParams, new String[] { {%- if operation.requestBody is defined %} {%- for mediaType in operation.requestBody.content.keys() %}"{{ mediaType }}"{% if loop.nextitem %}, {% endif %}{%- endfor %}{%- endif %} }, localVarPostBody,{% if formParams %}localVarFormParams{% else %}new HashMap<String, Object>(){% endif %} , {% if operation.requestBody %}{% if operation.requestBody.nullable %}true{% else %}false{% endif %}{% else %}false{% endif %}, {% if returnType %}new GenericType<{{ returnType }}>() {}{% else %}null{% endif %});
384384
}
385385

0 commit comments

Comments
 (0)