Skip to content

Commit 8f60746

Browse files
authored
Add Spectral linting rules for openAPI documents (#2618)
1 parent 33e044d commit 8f60746

File tree

5 files changed

+113
-5
lines changed

5 files changed

+113
-5
lines changed

.spectral.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
extends: ["spectral:oas"]
2+
rules:
3+
# Built-in rules
4+
# Descriptions
5+
oas3-parameter-description: warn
6+
oas2-parameter-description: warn
7+
tag-description: info
8+
# Document info
9+
info-contact: info
10+
info-description: warn
11+
info-license: warn
12+
# Examples
13+
oas3-valid-media-example: false
14+
oas3-valid-schema-example: false
15+
oas2-valid-media-example: false
16+
# Operations
17+
operation-operationId: false
18+
operation-operationId-unique: false
19+
operation-operationId-valid-in-url: false
20+
operation-tag-defined: warn
21+
operation-tags: warn
22+
# Responses
23+
operation-success-response: warn
24+
# Schema
25+
oas3-schema: warn
26+
oas2-schema: warn
27+
# Tags
28+
openapi-tags: warn
29+
openapi-tags-alphabetical: info
30+
# Turn off some built-in rules
31+
operation-description: false
32+
operation-singular-tag: false
33+
# Custom rules
34+
# Descriptions
35+
avoid-problematic-words:
36+
description: Ban certain words from descriptions
37+
message: "Use appropriate replacements for problematic terms"
38+
severity: warn
39+
given: "$..*.description"
40+
then:
41+
function: pattern
42+
functionOptions:
43+
notMatch: /(blacklist|whitelist|execute|kill)/i
44+
# Examples
45+
operation-success-examples:
46+
formats: ["oas3_1"]
47+
description: Response code 200 should have at least one example.
48+
message: "Each response body should have a realistic example. It must not contain any sensitive or confidential data."
49+
severity: info
50+
given: $.paths[*].[*].responses.[200].content.[application/json]
51+
then:
52+
field: examples
53+
function: defined
54+
# Extensions
55+
internal-extension:
56+
description: Operations should not have x-internal extension.
57+
message: "Do not publish x-internal operations"
58+
severity: error
59+
given: $.paths[*].[get,put,post,delete,options,head,patch,trace]
60+
then:
61+
field: x-internal
62+
function: undefined
63+
# Operations
64+
operation-summary:
65+
description: Operations should have summaries.
66+
message: "Each operation should have a summary"
67+
severity: error
68+
recommended: true
69+
given: $.paths[*][*]
70+
then:
71+
field: summary
72+
function: defined
73+
operation-summary-length:
74+
description: Operation summary should be between 5 and 45 characters
75+
given: "$.paths[*].[get,put,post,delete,options,head,patch,trace]"
76+
then:
77+
field: summary
78+
function: length
79+
functionOptions:
80+
max: 45
81+
min: 5
82+
severity: warn
83+
simple-verbs-in-summary:
84+
given:
85+
- "$.paths[*][*].summary"
86+
then:
87+
function: pattern
88+
functionOptions:
89+
notMatch: "Retrieve|Return|List *"
90+
severity: warn
91+
description: Summaries should use common verbs.
92+
message: "Summaries should use common verbs like Get, Update, Delete whenever possible"
93+
# NOTE: This one hiccups on acronyms so perhaps too noisy
94+
# docs-operation-summary-sentence-case:
95+
# description: Operation summary should be sentence cased
96+
# given: "$.paths[*].[get,put,post,delete,options,head,patch,trace]"
97+
# then:
98+
# field: summary
99+
# function: pattern
100+
# functionOptions:
101+
# match: /^[A-Z]+[^A-Z]+$/
102+
# severity: warn
103+

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ setup: ## Install dependencies for contrib target
3939
@make clean-dep
4040
@npm install --prefix compiler
4141
@npm install --prefix typescript-generator
42+
@npm install @stoplight/spectral-cli
4243

4344
clean-dep: ## Clean npm dependencies
4445
@rm -rf compiler/node_modules
@@ -58,6 +59,9 @@ dump-routes: ## Create a new schema with all generics expanded
5859

5960
contrib: | generate license-check spec-format-fix transform-to-openapi ## Pre contribution target
6061

62+
lint-docs: ## Lint the OpenAPI documents
63+
@npx @stoplight/spectral-cli lint output/openapi/elasticsearch-serverless-openapi.json
64+
6165
help: ## Display help
6266
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
6367
#------------- <https://suva.sh/posts/well-documented-makefiles> --------------

output/schema/schema.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/async_search/status/AsyncSearchStatusRequest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { RequestBase } from '@_types/Base'
2121
import { Id } from '@_types/common'
2222

2323
/**
24-
* Retreives the status of a previously submitted async search request given its identifier, without retrieving search results.
24+
* Get async search status
25+
* Retrieves the status of a previously submitted async search request given its identifier, without retrieving search results.
2526
* If the Elasticsearch security features are enabled, use of this API is restricted to the `monitoring_user` role.
2627
* @rest_spec_name async_search.status
2728
* @availability stack since=7.11.0 stability=stable

specification/ml/close_job/MlCloseJobRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Id } from '@_types/common'
2222
import { Duration } from '@_types/Time'
2323

2424
/**
25-
* Closes one or more anomaly detection jobs.
25+
* Close anomaly detection jobs
2626
* A job can be opened and closed multiple times throughout its lifecycle. A closed job cannot receive data or perform analysis operations, but you can still explore and navigate results.
2727
* When you close a job, it runs housekeeping tasks such as pruning the model history, flushing buffers, calculating final results and persisting the model snapshots. Depending upon the size of the job, it could take several minutes to close and the equivalent time to re-open. After it is closed, the job has a minimal overhead on the cluster except for maintaining its meta data. Therefore it is a best practice to close jobs that are no longer required to process data.
2828
* If you close an anomaly detection job whose datafeed is running, the request first tries to stop the datafeed. This behavior is equivalent to calling stop datafeed API with the same timeout and force parameters as the close job request.

0 commit comments

Comments
 (0)