I'm trying to document my Symfony 3.4 application API using nelmio/api-doc-bundle but fail to create a security scheme.
Generating the documentation itself works as expected with the following configuration:
nelmio_api_doc:
documentation:
info:
description: FooBar API
title: FooBar
version: 1.0.0
routes:
path_patterns:
- ^/api/
And the following annotations:
/**
* @SWG\Get(
* security={
* {"ApiKeyAuth":{}}
* },
* @SWG\Response(
* response=200,
* description="Returns all [Foo]",
* @SWG\Schema(
* type="array",
* @Model(type=App\Entity\Foo::class)
* )
* ),
* @SWG\Response(
* response=404,
* description="Returns an error when no [Foo] were found"
* )
* )
*/
public function cgetAction(): Response
{
// ...
}
So I get a proper JSON file like this:
{
"swagger" : "2.0",
"info" : {
"title" : "FooBar",
"description" : "FooBar API",
"version" : "1.0.0"
},
"paths" : {
"\/api\/foo" : {
"get" : {
"responses" : {
"200" : {
"description" : "Returns all [Foo]",
"schema" : {
"items" : {
"$ref" : "#\/definitions\/Foo"
},
"type" : "array"
}
},
"404" : {
"description" : "Returns an error when no [Foo] were found"
}
},
"security" : [
{
"ApiKeyAuth" : [ ]
}
]
}
}
},
"definitions" : {
"Foo" : {
"properties" : {
"id" : {
"type" : "integer"
}
},
"type" : "object"
}
}
}
Now the problem is that I need to define ApiKeyAuth
anywhere. Based on the examples I found ...
https://github.com/zircote/swagger-php/blob/master/Examples/petstore.swagger.io/security.php
https://swagger.io/docs/specification/2-0/authentication/api-keys/
... that might look like the following:
/**
* @SWG\SecurityScheme(
* name="X-API-KEY",
* type="apiKey",
* in="header",
* securityDefinition="ApiKeyAuth"
* )
*/
But regardless of where I put this in the controller it is not recognized.
So where is the right place for it?
Can I configure the api-doc-bundle to recognize a file with global definitions?
Do I need to create the definition in the config and not as annotation?
Does it work at all?