A custom ruleset for Spectral following the RHOAS API Guidelines.
npm is required to use Spectral.
To use this Spectral ruleset add the following to your .spectral.yaml
:
extends: "@rhoas/spectral-ruleset"
Alternatively you need to create new ruleset
echo 'extends: "@rhoas/spectral-ruleset"' > .spectral.yaml
You can run ruleset as follows
npm install -g @rhoas/spectral-ruleset
rhoasapi lint openapi.yaml
The RHOAS ruleset extends the Spectral built-in "oas" ruleset (except operation-tags
, openapi-tags
). You can see the full list of rules from that ruleset here
OpenAPI schemas should be a minimum of v3.
openapi: 3.0
Recommended: Yes
Severity: warning
The servers
OpenAPI object must be defined and must specify at minimum the following URLs:
servers:
- url: https://api.openshift.com
- url: https://api.stage.openshift.com
- url: http://localhost:8000
- url: /
Recommended: Yes
Severity: warning
The info.license.name
field must be "Apache 2.0".
info:
license:
name: 'Apache 2.0'
Recommended: Yes Severity: warning
The info.license.url
field must have the correct link for Apache 2.0.
info:
license:
url: 'https://www.apache.org/licenses/LICENSE-2.0'
Recommended: Yes
Severity: warning
All paths must match the specified regular expression: \/api\/([a-z_]*){1,}(\/v[0-9]*(alpha|beta)?)(\/{?[a-z_]*}?){0,}$
.
- The first segment must be
/api
- The second segement denotes the service name (e.g.
/api/kafkas_mgmt
) and may only besnake_case
. - The third segment must specify the API version. This can be a major version such as
v1
or a channel-version such asv1beta
,v1alpha
. - All following segments must follow
snake_case
and can only contain alphabetical characters along and underscores but can be repeated (e.g./api/kafkas_mgmt/v1/kafkas/{id}/useful_metrics
)
Recommended: Yes Severity: warning
The content type for all responses must be application/json
.
Recommended: Yes
Severity: warning
All error response bodies must reference #/components/Schemas/Error
Recommended: Yes
Severity: error
All API response bodies must be an object
with three required properties:
type: object
required: [id, kind, href]
properties:
id:
type: string
kind:
type: string
href:
type: string
Recommended: Yes
Severity: error
All JSON schema objects defined in components.schemas
must follow PascalCase
.
Recommended: Yes
Severity: warning
All JSON schema properties defined must follow snake_case
.
Recommended: Yes
Severity: error
components.schema
MUST have a valid Error
object.
Error:
type: object
required: [id, kind, href, code, reason]
properties:
id:
type: string
kind:
type: string
href:
type: string
code:
type: string
reason:
type: string
Recommended: Yes
Severity: warning
components.schema
MUST have a valid ObjectReference
object.
ObjectReference:
type: object
required: [id, kind, href]
properties:
id:
type: string
kind:
type: string
href:
type: string
Recommended: Yes
Severity: warning
components.schema
MUST have a valid List
object.
List:
required:
- kind
- page
- size
- total
- items
type: object
properties:
items:
type: array
kind:
type: string
page:
type: integer
size:
type: integer
total:
type: integer
Recommended: Yes
Severity: warning
operationId
should be present.This ID will become the method name in the SDK.
Recommended: Yes
Severity: warn
NOTE: This project uses Yarn workspaces for easier development.
Install dependencies:
yarn install
Build:
yarn build
Running examples
Validate OpenAPI files using the uncompiled ruleset:
yarn build
npm link .
rhoasapi lint ./examples/openapi-valid.yaml