api-platform: Swagger UI docs 404

API Platform version(s) affected: 2.6

Description
Some Swagger UI docs resources like javascript and css are not loaded from the correct path which you configured in “config/routes/api_platform.yaml” resulting in a 404.

How to reproduce

  1. Setup an ingress blocking everything that does not start with /api/users
  2. configure the api_platform prefix to /api/users
  3. Some resources for displaying the Swagger UI don’t pass the ingress as they are coming from host/bundles

Example: expected: https://localhost:8000/api/users/public/bundles/apiplatform/swagger-ui/swagger-ui.css actual: https://localhost:8000/bundles/apiplatform/swagger-ui/swagger-ui.css The ingress is blocking https://localhost:8000/bundles/

There should be a way to change the path from where these resources are served.

Possible Solution
I don’t know maybe serve the files for the UI from the same URL that is setup in config/routes/api_platform.yaml

This is how the swagger ui docs looks like Additional Context

most important settings of my app:

Dockerfile

FROM php:7.4-fpm

RUN apt-get update && apt-get install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
    && docker-php-ext-install intl opcache pdo pdo_mysql \
    && pecl install apcu \
    && docker-php-ext-enable apcu \
    && docker-php-ext-configure zip \
    && docker-php-ext-install zip

WORKDIR /app
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
#RUN symfony server:ca:install

ADD composer.json composer.lock ./
RUN composer install
ADD . .
RUN ./bin/console cache:clear

CMD ["symfony", "server:start", "--no-tls"]

k8s/ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
    #nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
  rules:
    - host: ticketing.dev
      http:
        paths:
          - path: /api/users
            backend:
              serviceName: user-srv
              servicePort: 8000

config/routes/api_platform.yaml

api_platform:
    resource: .
    type: api_platform
    prefix: /api/users

Screenshot from 2021-02-06 16-56-19

Screenshot from 2021-02-06 17-53-46

Screenshot from 2021-02-06 17-54-53

About this issue

Most upvoted comments

Go to your docker and run -> bin/console asset:install 😃

You can try in the framework.yaml to add the base url for asset. It worked for me

api/config/packages/framework.yaml

    assets:
        base_path: '/api'

This is depending how you configure nginx. In mine, I only search for /api location, so I found this way to relocate the asset path.