Skip to content

OpenAPI (Swagger) documentation does not take into account the routes hostname #6986

Description

@Crovitche-1623

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:

# 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
APP_HOST="example.com"

When I specify the host used for an ApiResource, for instance:

#[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.

Additional Context
Ask if necessary

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions