我正在遵循Spectral's documentation,并尝试将我的自定义规则作为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
,我预计在这两种情况中的任何一种都会失败-仍然没有警告和错误。看起来这条规则根本就不适用。
发布于 2019-10-02 20:48:23
我找到了。规则定义中需要一个字段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)
https://stackoverflow.com/questions/58167918
复制相似问题