← 返回刚才阅读的位置

知识卡片

操作参考卡 · 10296.b.1.b.2.a.3 · 生成模型:未记录

路径规则先验证选键

理解等级:中级

JSONPath Plus 的 $.paths[*]~ 取出 OpenAPI 路径名,末尾 ~ 用于选键。先在示例 JSON 上用本地查询工具确认实际取到的键,再交给 Spectral 的 pattern。要求版本前缀时可用 functionOptions.match 配置 ^/v\d+/.*$。用一个有版本的路径和一个缺版本的路径检查规则。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • API Lint 与设计一致性 3.7 Creating a Spectral rule for path versioning · 查看原书依据

      To create your new Spectral rule, the given property should be a JSONPath expression that selects all the URI paths in the API definition, but this isn’t possible with basic JSONPath expressions. To overcome this, Spectral supports an extended set of JSONPath expressions called JSONPath Plus. The JSONPath Plus expression you need to retrieve all the paths in your document is $.paths[*]~. You can find out more about JSONPath Plus expressions at https://github.com/JSONPath-Plus/JSONPath.

    参考来源

    - 位置:《Automating API Delivery APIOps with OpenAPI》《第 03 章 API Lint 与设计一致性》(3.7 Creating a Spectral rule for path versioning;来源项目 book-source,extracted/Automating API Delivery APIOps with OpenAPI/_epub-src/OEBPS/Text/chapter-3.xhtml#p80) - 结论依据:原文说明基础 JSONPath 不足以按示例提取键名,给出 JSONPath Plus 专用表达式。 - 原始内容:To create your new Spectral rule, the given property should be a JSONPath expression that selects all the URI paths in the API definition, but this isn’t possible with basic JSONPath expressions. To overcome this, Spectral supports an extended set of JSONPath expressions called JSONPath Plus. The JSONPath Plus expression you need to retrieve all the paths in your document is $.paths[*]~. You can find out more about JSONPath Plus expressions at https://github.com/JSONPath-Plus/JSONPath.