Skip to content

Commit 1cc72b2

Browse files
committed
Improve httpApiKeyAuth description in OpenAPI
Relates to #872
1 parent d8fdf44 commit 1cc72b2

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

smithy-aws-apigateway-openapi/src/test/resources/software/amazon/smithy/aws/apigateway/openapi/operation-http-api-key-security.openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"securitySchemes": {
2626
"api_key": {
2727
"type": "apiKey",
28-
"description": "X-Api-Key authentication",
28+
"description": "API key authentication via the 'x-api-key' header",
2929
"name": "x-api-key",
3030
"in": "header"
3131
}

smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverter.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,32 @@ public Class<HttpApiKeyAuthTrait> getAuthSchemeType() {
4040

4141
@Override
4242
public SecurityScheme createSecurityScheme(Context<? extends Trait> context, HttpApiKeyAuthTrait trait) {
43+
StringBuilder description = new StringBuilder()
44+
.append("API key authentication via the '")
45+
.append(trait.getName())
46+
.append("' ");
47+
48+
if (trait.getIn().equals(HttpApiKeyAuthTrait.Location.QUERY)) {
49+
description.append(" query string parameter");
50+
} else {
51+
description.append(trait.getIn());
52+
}
53+
4354
if (trait.getScheme().isPresent()) {
4455
return SecurityScheme.builder()
4556
.type("http")
4657
.scheme(trait.getScheme().get())
4758
.name(trait.getName())
4859
.in(trait.getIn().toString())
49-
.description("ApiKey authentication semantics via 'Authorization' header")
60+
.description(description.toString())
5061
.build();
5162
}
5263

5364
return SecurityScheme.builder()
5465
.type("apiKey")
5566
.name(trait.getName())
5667
.in(trait.getIn().toString())
57-
.description("X-Api-Key authentication")
68+
.description(description.toString())
5869
.build();
5970
}
6071

smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/security/http-api-key-bearer-security.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"smithy.api#httpApiKeyAuth": {
1515
"name": "Authorization",
1616
"in": "header",
17-
"scheme": "ApiKey"
17+
"scheme": "whatever-scheme-we-want"
1818
}
1919
}
2020
},

smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/security/http-api-key-bearer-security.openapi.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"securitySchemes": {
2121
"smithy.api.httpApiKeyAuth": {
2222
"type": "http",
23-
"description": "ApiKey authentication semantics via 'Authorization' header",
23+
"description": "API key authentication via the 'Authorization' header",
2424
"name": "Authorization",
2525
"in": "header",
26-
"scheme": "ApiKey"
26+
"scheme": "whatever-scheme-we-want"
2727
}
2828
}
2929
},

smithy-openapi/src/test/resources/software/amazon/smithy/openapi/fromsmithy/security/http-api-key-security.openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"securitySchemes": {
2121
"smithy.api.httpApiKeyAuth": {
2222
"type": "apiKey",
23-
"description": "X-Api-Key authentication",
23+
"description": "API key authentication via the 'x-api-key' header",
2424
"name": "x-api-key",
2525
"in": "header"
2626
}

0 commit comments

Comments
 (0)