api-platform / api-platform/core
OpenAPI (Swagger) documentation does not take into account the routes hostname
- Dominant language
- PHP
- Stars
- 2.6k
- Forks
- 980
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 48
Description
**API Platform version(s) affected**: ^3.1
**Description**
I have endpoints that needs to be accessible from different hosts for a multi-tenant app.
On the main domain (`example.com/api`), there are common data endpoints.
For tenant subdomain (`tenant_identifier.example.com/api`), there are the tenant data endpoints.
I tried to restrict the common data endpoints with the `host` parameter and it works as expected but the endpoints does not disappear from the tenant API documentation (`tenant_identifier.example.com/api/docs`). Therefore, the `host` does not seems to be taken into account for the OpenAPI specification.
**How to reproduce**
I have the following service configuration to inject the hostname dynamically:
```yml
# config/services.yaml
parameters:
# Used for route host matching as %env(...)% syntax is not supported
# @see https://stackoverflow.com/questions/47165113/environment-variables-in-route-annotations
hostname: '%env(resolve:APP_HOST)%'
```
```.env
# .env
APP_HOST="example.com"
```
When I specify the host used for an ApiResource, for instance:
```php
#[ApiResource(
// ...
host: '%hostname%',
// ...
)]
class FooBar
```
The endpoints are still available from the tenant API documentation (`tenant_identifier.example.com`).
**Possible Solution**
The server url should be taken into account as it's shown in the [OpenAPI specification](https://swagger.io/docs/specification/api-host-and-base-path/).
**Additional Context**
Ask if necessary
Contributor guide
Assessment
This issue has not been assessed yet.