光谱规则集
* 参与发展*
自定义 光谱 API Linter 规则 Zalando RESTFul API 准则。 。 。 .
规则有两种口味:
zalando: 坚持 Zalando RESTFul API 准则baloise: 使一些规则适应 乌龟
详见下表.
规则 spectral:oas 默认已禁用。 如果您想要再次启用这些规则
echo "extends: [https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/zalando.yml, spectral:oas]" \
> .spectral.yml
用这个
可能性A:通过 Github URL 引用
# zalando flavor:
npx @stoplight/spectral-cli lint \
--ruleset https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/zalando.yml \
example/example-openapi.yml
# baloise flavor:
npx @stoplight/spectral-cli lint \
--ruleset https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/baloise.yml \
example/example-openapi.yml
或者创造出一个 .spectral.yml 扩展它
echo "extends: [https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/baloise.yml]" \
> .spectral.yml
npx @stoplight/spectral-cli lint example/example-openapi.yml
如果你在代理后 你可以通过 PROXY 环境变量 :
PROXY=<PROXY URL> npx @stoplight/spectral lint <...>
B: 通过 npm 安装
npm i @baloise/spectral-rules
# zalando flavor:
npx @stoplight/spectral-cli lint \
--ruleset ./node_modules/@baloise/spectral-rules/zalando.yml \
example/example-openapi.yml
# baloise flavor:
npx @stoplight/spectral-cli lint \
--ruleset ./node_modules/@baloise/spectral-rules/baloise.yml \
example/example-openapi.yml
或者创造出一个 .spectral.yml 扩展它
echo "extends: [./node_modules/@baloise/spectral-rules/baloise.yml]" > .spectral.yml
npx @stoplight/spectral-cli lint example/example-openapi.yml
发展
添加新规则
- 从下表中选择一个新的、不支持的规则 。 举个例子 #151 MUST 指定成功和错误反应。 。 。 .
- 确保
tests/fixtures/base-openapi.yml满足规则. - 添加测试
tests/151-MUST-specify-success-and-error-responses.test.ts那个- 拿着
base-openapi.yaml作为投入 - 修改它以打破新规则
- 期待光谱找到错误( 暂时失效)
- 拿着
- 扩展
zalando.yml与新规则相配合,从而使之前添加的测试成功. 见 https://meta.stoplight.io/docs/光谱/docs/guides/4-海关规则集.md 关于如何定义自定义规则. - 添加: havy check mark: 到下表.
- 创建 PR
替代的贝卢斯规则的标志是附加规则编号,加上 a例如,扎兰多规则 #115 对白鲸规则 #115a扎兰多规则 #115 定义于 zalando.yml. 白鲸规则 #115a 定义于 baloise.yml 解除原扎兰多规则 #115a。 。 。 .
设置
npm install
npm run test
npm run lint
npm run lint-fix # format source files
目前得到支持的规则 扎兰多休息-api-指针
: havy check mark:=规则已执行
: grey 感叹:=规则执行不可能或复杂