1

现在我尝试使用 NelmioApiDocBundle 在 Symfony 3 中创建 API 文档。到目前为止,一切都按照给定的 symfony 文档中的描述工作。

现在我想从 swagger 文档中删除 _error 和 _profiler 路由。它说你可以只使用 path_patterns。所以我需要在文档中写下我需要的所有路线。但我有很多不同的路径。

有机会创造负面的路径模式会很酷,比如

...
    path_patterns:
        - !^/_error
        - !^/fubar

这样的事情可能吗?

4

1 回答 1

1

这些是正则表达式模式,是的,您应该能够匹配正则表达式允许的任何类型的模式。
查看“lookaround”零长度断言,特别是 Negative lookahead,然后尝试如下操作:

path_patterns:
    - ^\/((?!_error)(?!fubar).)*$

Regex101是测试和理解正则表达式的绝佳工具。它将解释正则表达式每个部分的影响,如下所示:

^ asserts position at start of a line
\/ matches the character / literally (case sensitive)
1st Capturing Group ((?!_error)(?!fubar).)*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
Negative Lookahead (?!_error)
Assert that the Regex below does not match
_error matches the characters _error literally (case sensitive)
Negative Lookahead (?!fubar)
Assert that the Regex below does not match
fubar matches the characters fubar literally (case sensitive)
. matches any character (except for line terminators)
$ asserts position at the end of a line
于 2021-02-27T21:21:24.240 回答