首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NelmioApiDocBundle阴性path_patterns

NelmioApiDocBundle阴性path_patterns
EN

Stack Overflow用户
提问于 2021-02-26 08:33:09
回答 1查看 183关注 0票数 1

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

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

如果有机会创建类似这样的负面路径模式,那就太酷了。

代码语言:javascript
复制
...
    path_patterns:
        - !^/_error
        - !^/fubar

这样的事有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-27 21:21:24

这些是正则表达式模式,所以,是的,您应该能够匹配任何类型的模式正则表达式允许的。

请查看“查找”零长度断言,特别是负面展望,并尝试如下所示:

代码语言:javascript
复制
path_patterns:
    - ^\/((?!_error)(?!fubar).)*$

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

代码语言:javascript
复制
^ 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66382525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档