Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public open class {{classname}} : ApiClientBase {
{{#authMethods}}
{{#-first}}

{{!TODO: Implement}}
//addAuthentication({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}})
addAuthentication({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}})
{{/-first}}
{{/authMethods}}
{{#queryParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,42 @@ public abstract class ApiClientBase {
}
{{#hasAuthMethods}}

protected fun HttpRequestBuilder.addAuthentication(apiKeyAuths: List<String>, basicAuths: List<String>, bearerAuths: List<String>, oAuths: List<String>) {
for (name in apiKeyAuths) {
val auth = apiKeyAuth[name] ?: throw IllegalStateException("ApiKeyAuth \"$name\" was configured, but not found")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These had the pretty good reason to error on invalid schemas, so I'd like to keep them

if (auth.isConfigured) {
protected fun HttpRequestBuilder.addAuthentication(vararg auths: String) {
for (name in auths) {
val auth = apiKeyAuth[name]
if (auth?.isConfigured == true) {
auth.configure(this)
return
}
}
for (name in basicAuths) {
val auth = basicAuth[name] ?: throw IllegalStateException("HttpBasicAuth \"$name\" was configured, but not found")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

if (auth.isConfigured) {
for (name in auths) {
val auth = basicAuth[name]
if (auth?.isConfigured == true) {
auth.configure(this)
return
}
}
for (name in bearerAuths) {
val auth = bearerAuth[name] ?: throw IllegalStateException("HttpBearerAuth \"$name\" was configured, but not found")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

if (auth.isConfigured) {
for (name in auths) {
val auth = bearerAuth[name]
if (auth?.isConfigured == true) {
auth.configure(this)
return
}
}
for (name in oAuths) {
val auth = oAuth[name] ?: throw IllegalStateException("OAuth \"$name\" was configured, but not found")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

if (auth.isConfigured) {
for (name in auths) {
val auth = oAuth[name]
if (auth?.isConfigured == true) {
auth.configure(this)
return
}
}
throw IllegalStateException(
"""
No valid authentication configured, please configure one of the following:
API Key Authentication: ${apiKeyAuths.joinToString()}
HTTP Bearer Authentication: ${apiKeyAuths.joinToString()}
HTTP Basic Authentication: ${apiKeyAuths.joinToString()}
OAuth: ${apiKeyAuths.joinToString()}
API Key Authentication: ${apiKeyAuth.keys.joinToString()}
HTTP Bearer Authentication: ${bearerAuth.keys.joinToString()}
HTTP Basic Authentication: ${basicAuth.keys.joinToString()}
OAuth: ${oAuth.keys.joinToString()}
""".trimIndent()
)
}
Expand Down