NelmioApiDocBundle icon indicating copy to clipboard operation
NelmioApiDocBundle copied to clipboard

Allow custom key usage in "documentation" (for example x-logo)

Open BafS opened this issue 5 years ago • 3 comments

It's currently not possible to use a custom key (x-...), it can be useful for some frontends, for example Redoc uses x-logo.

Example:

nelmio_api_doc:
    documentation:
        x-logo: # <- not possible
            url: 'https://redocly.github.io/redoc/petstore-logo.png'
            altText: Petstore logo
        info:
            title: My API
"Undefined index: x_logo"

exception | "ErrorException"
file | "/.../api/vendor/nelmio/api-doc-bundle/OpenApiPhp/Util.php"
line | 377

BafS avatar Aug 28 '20 16:08 BafS

Indeed, zircote/swagger-php annotations support custom keys through the x field (see https://github.com/zircote/swagger-php/blob/a824f77936558c27d2ca43d00528f505fb12f9e3/src/Annotations/AbstractAnnotation.php#L22-L29).

As pointed by the error you provided, we should update https://github.com/nelmio/NelmioApiDocBundle/blob/a4c4ffcf3bbcc40d10510f026c4b5a757db8c947/OpenApiPhp/Util.php#L372-L379 to recognize fields beginning with x-.

GuilhemN avatar Sep 04 '20 10:09 GuilhemN

Note: it's possible to do

nelmio_api_doc:
    documentation:
        x:
            logo:
                url: 'https://....png'
                altText: Petstore logo
...

I don't know what you prefer, in any case it would be good to document it :)

BafS avatar Sep 07 '20 15:09 BafS

I'm not fund of using documentation.x, this does not respect the swagger specification and thus prevent people from using existing documentations.

GuilhemN avatar Sep 09 '20 07:09 GuilhemN

Fixed in https://github.com/nelmio/NelmioApiDocBundle/pull/2230

DjordyKoert avatar Mar 06 '24 18:03 DjordyKoert