Yaml 利用谱分析扩展规则
我正在遵循并尝试将我的自定义规则添加为Yaml 利用谱分析扩展规则,yaml,static-analysis,jsonpath,openapi,spectral,Yaml,Static Analysis,Jsonpath,Openapi,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://
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
我的.spectrum.yml
文件:
extends: spectral:oas3
rules:
my-rule-name:
description: Tags must have a description.
given: $.tags[*]
then:
field: description
function: truthy
我的API规范包含标记
,但该标记没有任何描述,因此它应该失败,但它没有:
>spectral lint api.yml
OpenAPI 3.x detected
No errors or warnings found!
即使我尝试更改为
function:falsy
,我希望在这两种情况中的一种情况下它会失败-仍然没有警告和错误。看起来这条规则根本就不适用。我找到了。规则定义中需要一个字段推荐:true
。文档中提到了这一点,但有些过于简短:
更新了.spectrum.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)