リクエストのヘッダーにAPI KEYを必要とするAWS APIゲートウェイをセットアップしようとしています。私はjsonの定義を生成するためにswaggerをセットアップし、AWSはそれを完全にうまくインポートします。私はAPIキーセキュリティ定義を追加しようとすると、しかし、Amazonはこのエラーで私の闊歩するAPIドキュメントを拒否:AWS APIゲートウェイでAPIキーをサポートするためのSpring Boot Swaggerアノテーション
Your API was not imported due to errors in the Swagger file. API Key security definition 'api_key' has unexpected name or location. Ignoring.
私は...私はそれが間違ってやっていると仮定ので、私は一緒にいくつかのバリエーションを試してみましたこれらの行。春のブートコンフィグ与え
はthusly springfoxを使用して作成:
@Bean
public Docket swaggerSpringMvcPlugin() {
List<ApiKey> securitySchemes = new ArrayList<>();
ApiKey apiKey = new ApiKey("apiKey", "api_key", "header");
list.add(apiKey);
//the above is probably where i'm missing something
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.apiInfo(apiInfo())
.securitySchemes(securitySchemes)
.select()
.paths(PathSelectors.regex("/api/swaggertest"))
.build();
}
などのように定義された上記のAPI:
@RestController
public class SwaggerTestController {
@ApiOperation(notes = "my notes", value = "test", nickname = "testNickname",
tags = {"tests"}, authorizations = {@Authorization(value="api_key")})
@ApiResponses({
@ApiResponse(code = 200, message = "Nice!", response = Swag.class)
})
@RequestMapping(value = "/api/swaggertest", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<Swag> getSwag() throws Exception {
return ResponseEntity.ok().body(new Swag());
}
}
私は、API-ドキュメントが生成私のアプリを実行すると(私はいくつかを削除します小さなそれを維持するためのセクション):
{
swagger: "2.0",
host: "localhost:4014",
basePath: "/",
tags: [
{
name: "swagger-test-controller",
description: "Swagger Test Controller"
}
],
paths: {
/api/swaggertest: {
get: {
tags: [
"tests"
],
summary: "test",
description: "my notes",
operationId: "testNickname",
consumes: [
"application/json"
],
produces: [
"application/json"
],
responses: {
200: {
description: "Nice!",
schema: {
$ref: "#/definitions/Swag"
}
}
},
security: [
{
api_key: [ ]
}
]
}
}
},
securityDefinitions: {
api_key: {
type: "apiKey",
name: "api_key",
in: "header"
}
},
definitions: {
Swag: {
type: "object",
properties: {
foo: {
type: "string"
}
}} }
誰かがこれにAPIキーのサポートを追加する方法を教えてくれる場合は、私はそれを感謝します。
これはまさに正解です。ありがとうございます。 apiKey = apiKey = new ApiKey( "any_name"、 "x-api-key"、 "header"); '' 'はこの結果を生成しません - アップロード前に手動でjsonを変更する'' 'any_name:{ type:" apiKey "、 name:" any_name "、 in:"ヘッダー " }' ''私はspringfoxの人にチェックインします。 – bsautner