Skip to content

Commit

Permalink
Improve httpApiKeyAuth description in OpenAPI
Browse files Browse the repository at this point in the history
Relates to #872
  • Loading branch information
mtdowling committed Oct 11, 2021
1 parent d8fdf44 commit 1cc72b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"securitySchemes": {
"api_key": {
"type": "apiKey",
"description": "X-Api-Key authentication",
"description": "API key authentication via the 'x-api-key' header",
"name": "x-api-key",
"in": "header"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,32 @@ public Class<HttpApiKeyAuthTrait> getAuthSchemeType() {

@Override
public SecurityScheme createSecurityScheme(Context<? extends Trait> context, HttpApiKeyAuthTrait trait) {
StringBuilder description = new StringBuilder()
.append("API key authentication via the '")
.append(trait.getName())
.append("' ");

if (trait.getIn().equals(HttpApiKeyAuthTrait.Location.QUERY)) {
description.append(" query string parameter");
} else {
description.append(trait.getIn());
}

if (trait.getScheme().isPresent()) {
return SecurityScheme.builder()
.type("http")
.scheme(trait.getScheme().get())
.name(trait.getName())
.in(trait.getIn().toString())
.description("ApiKey authentication semantics via 'Authorization' header")
.description(description.toString())
.build();
}

return SecurityScheme.builder()
.type("apiKey")
.name(trait.getName())
.in(trait.getIn().toString())
.description("X-Api-Key authentication")
.description(description.toString())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"smithy.api#httpApiKeyAuth": {
"name": "Authorization",
"in": "header",
"scheme": "ApiKey"
"scheme": "whatever-scheme-we-want"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"securitySchemes": {
"smithy.api.httpApiKeyAuth": {
"type": "http",
"description": "ApiKey authentication semantics via 'Authorization' header",
"description": "API key authentication via the 'Authorization' header",
"name": "Authorization",
"in": "header",
"scheme": "ApiKey"
"scheme": "whatever-scheme-we-want"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"securitySchemes": {
"smithy.api.httpApiKeyAuth": {
"type": "apiKey",
"description": "X-Api-Key authentication",
"description": "API key authentication via the 'x-api-key' header",
"name": "x-api-key",
"in": "header"
}
Expand Down

0 comments on commit 1cc72b2

Please sign in to comment.