Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BafS opened this issue Aug 28, 2020 · 4 comments
Closed

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

BafS opened this issue Aug 28, 2020 · 4 comments

Comments

@BafS
Copy link
Contributor

BafS commented Aug 28, 2020

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
@GuilhemN
Copy link
Collaborator

GuilhemN commented Sep 4, 2020

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

foreach ($properties as $propertyName => $value) {
if ('$ref' === $propertyName) {
$propertyName = 'ref';
}
if (!\in_array($propertyName, $done, true)) {
self::mergeProperty($annotation, $propertyName, $value, $defaults[$propertyName], $overwrite);
}
}
to recognize fields beginning with x-.

@BafS
Copy link
Contributor Author

BafS commented Sep 7, 2020

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 :)

@GuilhemN
Copy link
Collaborator

GuilhemN commented Sep 9, 2020

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

@DjordyKoert
Copy link
Collaborator

Fixed in #2230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants