Skip to content

Commit ced5636

Browse files
authored
feat: add API descriptor with API_SPECTRAL with AsyncAPI/OpenAPI support (#3474)
Add API descriptor as modified copy of the OPENAPI descriptor. Deprecate the contained linter OPENAPI_SPECTRAL. Add `.spectral.yaml` as default config file to `TEMPLATE/` as modified copy of `.openapirc.yml` with rulesets for AsyncAPI and OpenAPI (previously, only OpenAPI). Closes: #3387
1 parent b873257 commit ced5636

File tree

83 files changed

+890
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+890
-66
lines changed

.automation/test/api/api_bad_1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openapi: '3.0.0'

.automation/test/api/api_bad_2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"openapi": "3.0.0"
3+
}

.automation/test/api/api_good_1.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Example
4+
version: "1.0"
5+
contact:
6+
name: Justin Kalland
7+
8+
description: Test for mega-linter
9+
servers:
10+
- url: "http://localhost:3000"
11+
paths: {}
12+
tags:
13+
- name: example

.automation/test/api/api_good_2.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Example",
5+
"version": "1.0",
6+
"contact": {
7+
"name": "Justin Kalland",
8+
"email": "[email protected]"
9+
},
10+
"description": "Test for mega-linter"
11+
},
12+
"servers": [
13+
{
14+
"url": "http://localhost:3000"
15+
}
16+
],
17+
"paths": {},
18+
"tags": [
19+
{
20+
"name": "example"
21+
}
22+
]
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Results of spectral linter (version 5.6.0)
2+
See documentation on https://megalinter.io/descriptors/openapi_spectral/
3+
-----------------------------------------------
4+
5+
[ERROR] .automation/test/api/api_bad_1.yml
6+
OpenAPI 3.x detected
7+
8+
.automation/test/api/api_bad_1.yml
9+
1:1 warning info-contact Info object should contain `contact` object.
10+
1:1 warning info-description OpenAPI object info `description` must be present and non-empty string.
11+
1:1 warning oas3-api-servers OpenAPI `servers` must be present and non-empty array.
12+
1:1 error oas3-schema Object should have required property `info`.
13+
1:1 warning openapi-tags OpenAPI object should have non-empty `tags` array.
14+
15+
✖ 5 problems (1 error, 4 warnings, 0 infos, 0 hints)
16+
17+
[ERROR] .automation/test/api/api_bad_2.json
18+
OpenAPI 3.x detected
19+
20+
.automation/test/api/api_bad_2.json
21+
1:1 warning info-contact Info object should contain `contact` object.
22+
1:1 warning info-description OpenAPI object info `description` must be present and non-empty string.
23+
1:1 warning oas3-api-servers OpenAPI `servers` must be present and non-empty array.
24+
1:1 error oas3-schema Object should have required property `info`.
25+
1:1 warning openapi-tags OpenAPI object should have non-empty `tags` array.
26+
27+
✖ 5 problems (1 error, 4 warnings, 0 infos, 0 hints)
28+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Results of spectral linter (version 5.6.0)
2+
See documentation on https://megalinter.io/descriptors/api_spectral/
3+
-----------------------------------------------
4+
5+
[SUCCESS] .automation/test/api/api_good_1.yml
6+
OpenAPI 3.x detected
7+
No results with a severity of 'error' or higher found!
8+
9+
[SUCCESS] .automation/test/api/api_good_2.json
10+
OpenAPI 3.x detected
11+
No results with a severity of 'error' or higher found!
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TAP version 13
2+
1..4
3+
not ok 1 - api_bad_1.yml
4+
---
5+
message: OpenAPI 3.x detected\n\n/tmp/lint/.automation/test/api/api_bad_1.ymlopenapi\n 1 1 warning info-contact Info object should contain `contact` object.\n 1 1 warning info-description OpenAPI object info `description` must be present and non-empty string.\n 1 1 warning oas3-api-servers OpenAPI `servers` must be present and non-empty array.\n 1 1 error oas3-schema Object should have required property `info`.\n 1 1 warning openapi-tags OpenAPI object should have non-empty `tags` array.\n\n✖ 5 problems (1 error, 4 warnings, 0 infos, 0 hints)\n
6+
...
7+
not ok 2 - api_bad_2.json
8+
---
9+
message: OpenAPI 3.x detected\n\n/tmp/lint/.automation/test/api/api_bad_2.jsonopenapi\n 1 1 warning info-contact Info object should contain `contact` object.\n 1 1 warning info-description OpenAPI object info `description` must be present and non-empty string.\n 1 1 warning oas3-api-servers OpenAPI `servers` must be present and non-empty array.\n 1 1 error oas3-schema Object should have required property `info`.\n 1 1 warning openapi-tags OpenAPI object should have non-empty `tags` array.\n\n✖ 5 problems (1 error, 4 warnings, 0 infos, 0 hints)\n
10+
...
11+
ok 3 - api_good_1.yml
12+
ok 4 - api_good_2.json

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@
521521
"asdict",
522522
"ashokm",
523523
"assignuser",
524+
"asyncapi",
524525
"autocorrect",
525526
"autocrlf",
526527
"autofix",

.github/workflows/deploy-BETA-linters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
[
7777
"action_actionlint",
7878
"ansible_ansible_lint",
79+
"api_spectral",
7980
"arm_arm_ttk",
8081
"bash_exec",
8182
"bash_shellcheck",

.github/workflows/deploy-DEV-linters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
[
4848
"action_actionlint",
4949
"ansible_ansible_lint",
50+
"api_spectral",
5051
"arm_arm_ttk",
5152
"bash_exec",
5253
"bash_shellcheck",

.github/workflows/deploy-RELEASE-linters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
[
5252
"action_actionlint",
5353
"ansible_ansible_lint",
54+
"api_spectral",
5455
"arm_arm_ttk",
5556
"bash_exec",
5657
"bash_shellcheck",

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
1313
- Media
1414

1515
- New linters
16+
- `API_SPECTRAL` was added as replacement for `OPENAPI_SPECTRAL` (deprecated), supporting AsyncAPI and OpenAPI by default. Uses Spectral's standard config file name `.spectral.yaml` instead of `.openapirc.yml` with a default config with rulesets for AsyncAPI and OpenAPI enabled. Fixes [#3387](https://github.com/oxsecurity/megalinter/issues/3387)
1617

1718
- Reporters
1819

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ WORKDIR /node-deps
206206
RUN npm --no-cache install --ignore-scripts --omit=dev \
207207
@salesforce/cli \
208208
typescript \
209+
@stoplight/spectral-cli \
209210
@coffeelint/cli \
210211
jscpd \
211212
stylelint \
@@ -241,7 +242,6 @@ RUN npm --no-cache install --ignore-scripts --omit=dev \
241242
markdownlint-cli \
242243
markdown-link-check \
243244
markdown-table-formatter \
244-
@stoplight/spectral-cli \
245245
secretlint \
246246
@secretlint/secretlint-rule-preset-recommend \
247247
@secretlint/secretlint-formatter-sarif \

TEMPLATES/.spectral.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
3+
#######################################
4+
#######################################
5+
## AsyncAPI and OpenAPI Linter rules ##
6+
#######################################
7+
#######################################
8+
9+
extends:
10+
- spectral:asyncapi
11+
- spectral:oas

docs/descriptors/api.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: API linters in MegaLinter
3+
description: spectral is available to analyze API files in MegaLinter
4+
---
5+
<!-- markdownlint-disable MD003 MD020 MD033 MD041 -->
6+
<!-- @generated by .automation/build.py, please don't update manually -->
7+
<!-- Instead, update descriptor file at https://github.com/oxsecurity/megalinter/tree/main/megalinter/descriptors/api.yml -->
8+
# API
9+
10+
## Linters
11+
12+
| Linter | Additional |
13+
|-----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
14+
| [**spectral**](api_spectral.md)<br/>[_API_SPECTRAL_](api_spectral.md) | [![GitHub stars](https://img.shields.io/github/stars/stoplightio/spectral?cacheSeconds=3600)](https://github.com/stoplightio/spectral) |
15+
16+
## Linted files
17+
18+
- File extensions:
19+
- `.yml`
20+
- `.yaml`
21+
- `.json`
22+
23+
- Detected file content:
24+
- `"asyncapi":`
25+
- `"openapi":`
26+
- `"swagger":`
27+
- `asyncapi:`
28+
- `openapi:`
29+
- `swagger:`
30+
31+
## Configuration in MegaLinter
32+
33+
| Variable | Description | Default value |
34+
|--------------------------|-------------------------------------------------|---------------|
35+
| API_PRE_COMMANDS | List of bash commands to run before the linters | None |
36+
| API_POST_COMMANDS | List of bash commands to run after the linters | None |
37+
| API_FILTER_REGEX_INCLUDE | Custom regex including filter | |
38+
| API_FILTER_REGEX_EXCLUDE | Custom regex excluding filter | |
39+

0 commit comments

Comments
 (0)