yaml - 使用光谱扩展规则
问题描述
我正在关注Spectral 的文档,我正在尝试将我的自定义规则添加为oas3
规则集的扩展,看起来文档中的规则被完全忽略了。
我的 OpenApi 3.0 规范文件:
openapi: 3.0.2
info:
title: Project info
description: |
Project description
contact:
name: Test Testable
email: test@test.test
version: 1.0.0
servers:
- url: http://localhost:8080
tags:
- name: test-tag
paths:
/test:
get:
tags:
- test-tag
summary: Some summary
operationId: operationId
description: Operation description
responses:
200:
description: OKK
我的.spectral.yml
文件:
extends: spectral:oas3
rules:
my-rule-name:
description: Tags must have a description.
given: $.tags[*]
then:
field: description
function: truthy
我的 API 规范包含tags
但那里的标签没有任何描述,所以它应该失败但它没有:
>spectral lint api.yml
OpenAPI 3.x detected
No errors or warnings found!
即使我尝试更改为function: falsy
我希望它在这两种情况之一中失败的情况 - 仍然没有警告和错误。看起来这条规则根本不适用。
解决方案
我找到了。recommended: true
规则定义中需要一个字段。文档提到了它,但不知何故太简短了:
更新.spectral.yml
:
extends: spectral:oas3
rules:
my-rule-name:
description: Tags must have a description.
given: $.tags[*]
recommended: true
then:
field: description
function: truthy
和输出:
13:3 warning my-rule-name Tags must have a description.
✖ 1 problem (0 errors, 1 warning, 0 infos)
推荐阅读
- javascript - 不能将passport.authenticate包装成一个函数
- react-native - TypeError: (0, _native.useTheme) 不是函数。(在 '(0, _native.useTheme)()' 中,'(0, _native.useTheme)' 未定义)
- node.js - TLS 握手失败并出现错误 tls:第一条记录看起来不像 TLS 握手服务器=Orderer remoteaddress=172.24.0.1:41096
- r - 向量化嵌套 for 循环,将不均匀列表映射到其长度的乘积
- mpi - 从 MPICH 切换到 OpenMPI
- node.js - 限制 API 访问
- spring - 从 swaggerhub 生成的 Spring Boot 代码无法在其他属性上抛出 400
- python - Python Discord Bot 不会在成员加入时发送私人消息
- laravel - 数据库中的订阅状态未使用 Stripe 更新
- awk - 从包含唯一条件的行中获取文本到文件中包含重复单词的行的第一次出现