首页 > 解决方案 > 为什么 swagger 看不到 public/bundles/hbswaggerui 中的文件?

问题描述

我使用 OpenServer(Apache 2.4 + PHP 7.2)。

Symfony 4 工作正常,路由工作正常。在 /public 文件夹中,我放置了 .htaccess 文件。

RewriteEngine On
Options +FollowSymlinks
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php [L]

有用。

我在这里安装了招摇: https ://github.com/harmbandstra/swagger-ui-bundle

我还在 hb_swagger_ui.yaml 中使用了assetUrlPath 参数

hb_swagger_ui:
  directory: "%kernel.root_dir%/../docs/"
  assetUrlPath: '/public/bundles/hbswaggerui/'
  files:
    - "swagger.json"

url mysite/docs/?url=/docs/file/swagger.json 显示白页

控制台显示:

Refused to apply style from 'http://mysite/docs/swagger-ui.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
?url=/docs/file/swagger.json:36 GET http://mysite/docs/swagger-ui-bundle.js net::ERR_ABORTED 404 (Not Found)
?url=/docs/file/swagger.json:37 GET http://mysite/docs/swagger-ui-standalone-preset.js net::ERR_ABORTED 404 (Not Found)
?url=/docs/file/swagger.json:41 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (?url=/docs/file/swagger.json:41)

如果我创建文件夹 /public/doc/ 并将文件从 /public/bundles/hbswaggerui/ 移到那里 - 它可以工作。

但它应该在文件夹 /public/bundles/hbswaggerui 中工作。

为什么不呢?

我应该做一些额外的 Apache 设置来将 /public/docs 重写为 /public/bundles/hbswaggerui 吗?

手册中没有关于它的信息...

标签: symfonyswagger

解决方案


你不应该设置assetUrlPath,从你的配置中删除它。


推荐阅读