现在,我尝试用NelmioApiDocBundle在Symfony 3中创建一个API文档。到目前为止,一切都按照给定的symfony文档所描述的那样工作。
现在,我想从swagger文档中删除_error和_profiler路由。它说你可以只使用path_patterns。所以我需要在文档中写下我需要的所有路线。但我有很多不同的方法。
如果有机会创建类似这样的负面路径模式,那就太酷了。
...
path_patterns:
- !^/_error
- !^/fubar这样的事有可能吗?
发布于 2021-02-27 21:21:24
这些是正则表达式模式,所以,是的,您应该能够匹配任何类型的模式正则表达式允许的。
请查看“查找”零长度断言,特别是负面展望,并尝试如下所示:
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 linehttps://stackoverflow.com/questions/66382525
复制相似问题