如何从 NelmioApiDocBundle 生成的文档中删除 _format URL 后缀?
How to remove _format URL suffix from documentation generated by NelmioApiDocBundle?
我已经在 Symfony 中为我的新 API-oriented 项目安装了 NelmioApiDocBundle
,但我无法摆脱这个包添加到我所有端点 URL 的 .{_format}
后缀.
这是它的样子:
我的API不支持_format
作为后缀。它确实支持它作为查询参数或请求 headers。因此,如果我尝试从 NelmioApiDocBundle 沙箱向该端点发出请求,它会收到 404 错误响应。
这是我当前关于 nelmio 的 config.yml 部分:
yml
nelmio_api_doc:
name: My API doc
sandbox:
enabled: true
endpoint: null
accept_type: application/json
body_format:
formats: null
default_format: json
request_format:
formats:
json: application/json
xml: null
method: accept_header
default_format: json
authentication:
name: bearer
delivery: query
cache:
enabled: false
file: '%kernel.cache_dir%/api-doc.cache'
我已经在 Whosebug 的其他地方弄明白了。看来我的问题与 NelmioApiDocBundle 无关,而是与 FOSRestBundle 相关。我只需要更改 config.yml
:
中的一个 FOSRest 设置
fos_rest:
routing_loader:
include_format: false
我找到了解决方案here
我已经在 Symfony 中为我的新 API-oriented 项目安装了 NelmioApiDocBundle
,但我无法摆脱这个包添加到我所有端点 URL 的 .{_format}
后缀.
这是它的样子:
我的API不支持_format
作为后缀。它确实支持它作为查询参数或请求 headers。因此,如果我尝试从 NelmioApiDocBundle 沙箱向该端点发出请求,它会收到 404 错误响应。
这是我当前关于 nelmio 的 config.yml 部分:
yml
nelmio_api_doc:
name: My API doc
sandbox:
enabled: true
endpoint: null
accept_type: application/json
body_format:
formats: null
default_format: json
request_format:
formats:
json: application/json
xml: null
method: accept_header
default_format: json
authentication:
name: bearer
delivery: query
cache:
enabled: false
file: '%kernel.cache_dir%/api-doc.cache'
我已经在 Whosebug 的其他地方弄明白了。看来我的问题与 NelmioApiDocBundle 无关,而是与 FOSRestBundle 相关。我只需要更改 config.yml
:
fos_rest:
routing_loader:
include_format: false
我找到了解决方案here