1.1.9 • Published 2 months ago

@baloise/spectral-rules v1.1.9

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

Gitpod

spectral-ruleset

👷🚧🛠️ in development 👷🚧🛠️

Custom Spectral API Linter ruleset for Zalando RESTful API Guidelines.

There are two flavors of the ruleset:

Please refer to the table below for details.

The ruleset spectral:oas is disabled by default. If you like to enable these rules again use

echo "extends: [https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/zalando.yml, spectral:oas]" \
    > .spectral.yml

Use it

Possibility A: Reference via 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

Or just create a .spectral.yml extending it

echo "extends: [https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/baloise.yml]" \
    > .spectral.yml
npx @stoplight/spectral-cli lint example/example-openapi.yml

If you're behind a proxy you can pass it via PROXY environment variable:

PROXY=<PROXY URL> npx @stoplight/spectral lint <...>

Possibility B: Install via 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

Or just create a .spectral.yml extending it

echo "extends: [./node_modules/@baloise/spectral-rules/baloise.yml]" > .spectral.yml
npx @stoplight/spectral-cli lint example/example-openapi.yml

Development

Adding a new Rule

  1. Choose a new, unsupported rule from the table below. For example #151 MUST specify success and error responses.
  2. Make sure tests/fixtures/base-openapi.yml satisfies the rule.
  3. Add a test tests/151-MUST-specify-success-and-error-responses.test.ts that
    1. Takes the base-openapi.yaml as input
    2. Modifies it to break the new rule
    3. Expect that spectral finds the error (this will fail for now)
  4. Extend zalando.yml with the new rule, so that the previously added test succeeds. See https://meta.stoplight.io/docs/spectral/docs/guides/4-custom-rulesets.md on how to define custom rules.
  5. Add a :heavy_check_mark: to the table below.
  6. Create a PR

Alternative baloise rules are marked by appending the rule number with an a. For example zalando rule #115 versus baloise rule #115a. The zalando rule #115 is defined in zalando.yml. The baloise rule #115a is defined in baloise.yml while deactivating the original zalando rule #115a.

Setup

npm install
npm run test
npm run lint
npm run lint-fix # format source files

Currently supported rules from the zalando restful-api-guidelines

:heavy_check_mark: = rule implemented
:grey_exclamation: = rule implementation not possible or to complex

idtitlezalando.ymlbaloise.ymlprio (A, B, C)
#100MUST follow API first principle:grey_exclamation::grey_exclamation:B
#101MUST provide API specification using OpenAPI:grey_exclamation::grey_exclamation:A
#102SHOULD provide API user manual--C
#103MUST write APIs using U.S. English:grey_exclamation::grey_exclamation:A
#104MUST secure endpoints with OAuth 2.0--B
#105MUST define and assign permissions (scopes)--B
#106MUST not break backward compatibility--B
#107SHOULD prefer compatible extensions:grey_exclamation::grey_exclamation:-
#108MUST prepare clients accept compatible API extensions:grey_exclamation::grey_exclamation:C
#109SHOULD design APIs conservatively:grey_exclamation::grey_exclamation:-
#110MUST always return JSON objects as top-level data structures:heavy_check_mark::heavy_check_mark:A
#111MUST treat Open API specification as open for extension by default:grey_exclamation::grey_exclamation:-
#112SHOULD used open-ended list of values (x-extensible-enum) for enumerations:heavy_check_mark::heavy_check_mark:--
#113SHOULD avoid versioning:grey_exclamation::grey_exclamation:B
#114MUST use media type versioning:grey_exclamation::grey_exclamation:-
#115MUST not use URI versioning:heavy_check_mark:-A
#115aCAN use correct URI versioning: ^((?!.*\/v\d+(\/.*)?\/v\d+)\/.*)$-:heavy_check_mark:A
#116MUST use semantic versioning:heavy_check_mark::heavy_check_mark:B
#118MUST property names must be ASCII snakecase (and never camelCase): `^[a-z][a-z_0-9]*$`:heavy_check_mark:-A
#118aMUST property names must be ASCII camelCase: ^[a-z]+((\d)([A-Z0-9][a-z0-9]+))*([A-Z])?$-:heavy_check_mark:A
#120SHOULD pluralize array names--B
#122MUST not use null for boolean properties:grey_exclamation::grey_exclamation:-
#123MUST use same semantics for null and absent properties:grey_exclamation::grey_exclamation:-
#124SHOULD not use null for empty arrays:grey_exclamation::grey_exclamation:-
#125SHOULD represent enumerations as strings--?
#126SHOULD define dates properties compliant with RFC 3339--?
#127SHOULD define time durations and intervals properties conform to ISO 8601:grey_exclamation::grey_exclamation:-
#128SHOULD use standards for country, language and currency codes--?
#129MUST use lowercase separate words with hyphens for path segments:heavy_check_mark::heavy_check_mark:A
#130MUST use snake_case (never camelCase) for query parameters:heavy_check_mark:-B
#130aMUST use camelCase (never snake_case) for query parameters-:heavy_check_mark:B
#132SHOULD prefer hyphenated-pascal-case for HTTP header fields:heavy_check_mark::heavy_check_mark:B
#133MAY use standardized headers---
#134MUST pluralize resource names--A
#135SHOULD not use /api as base path:heavy_check_mark::heavy_check_mark:A
#136MUST use normalized paths without empty path segments and trailing slashes:heavy_check_mark::heavy_check_mark:B
#137MUST stick to conventional query parameters:grey_exclamation::grey_exclamation:-
#138MUST avoid actions — think about resources:grey_exclamation::grey_exclamation:A
#139SHOULD model complete business processes:grey_exclamation::grey_exclamation:-
#140SHOULD define useful resources:grey_exclamation::grey_exclamation:-
#141MUST keep URLs verb-free:grey_exclamation::grey_exclamation:A
#142MUST use domain-specific resource names:grey_exclamation::grey_exclamation:-
#143MUST identify resources and sub-resources via path segments---
#144SHOULD only use UUIDs if necessary:grey_exclamation::grey_exclamation:-
#145MAY consider using (non-)nested URLs:grey_exclamation::grey_exclamation:-
#146SHOULD limit number of resource types:heavy_check_mark::heavy_check_mark:B
#147SHOULD limit number of sub-resource levels:heavy_check_mark::heavy_check_mark:B
#148MUST use HTTP methods correctly:grey_exclamation::grey_exclamation:A
#149MUST fulfill common method properties:grey_exclamation::grey_exclamation:-
#150MUST use standard HTTP status codes:heavy_check_mark:-
#150aMUST use additional standard HTTP status codes-:heavy_check_mark:-
#151MUST specify success and error responses:heavy_check_mark::heavy_check_mark:B
#152MUST use code 207 for batch or bulk requests:grey_exclamation::grey_exclamation:C
#153MUST use code 429 with headers for rate limits:grey_exclamation::grey_exclamation:C
#154MUST define collection format of header and query parameters:grey_exclamation::grey_exclamation:-
#155SHOULD reduce bandwidth needs and improve responsiveness:grey_exclamation::grey_exclamation:-
#156SHOULD use gzip compression:grey_exclamation::grey_exclamation:-
#157SHOULD support partial responses via filtering:grey_exclamation::grey_exclamation:-
#158SHOULD allow optional embedding of sub-resources:grey_exclamation::grey_exclamation:-
#159MUST support pagination---
#160SHOULD prefer cursor-based pagination, avoid offset-based pagination---
#161SHOULD use pagination links where applicable---
#162MUST use REST maturity level 2---
#163MAY use REST maturity level 3 - HATEOAS---
#164MUST use common hypertext controls---
#165SHOULD use simple hypertext controls for pagination and self-references---
#166MUST not use link headers with JSON entities---
#167MUST use JSON to encode structured data---
#168MAY use non JSON media types for binary data or alternative content representations:grey_exclamation::grey_exclamation:-
#169MUST use standard date and time formats:grey_exclamation::grey_exclamation:A
#170SHOULD use standards for country, language and currency codes--B
#171MUST define format for number and integer types:heavy_check_mark:--
#172SHOULD prefer standard media type name application/json:heavy_check_mark::heavy_check_mark:B
#173MUST use the common money object:grey_exclamation::grey_exclamation:-
#174MUST use common field names and semantics:grey_exclamation::grey_exclamation:-
#176MUST support problem JSON:heavy_check_mark::heavy_check_mark:-
#177MUST not expose stack traces:grey_exclamation::grey_exclamation:-
#178MUST use Content-* headers correctly:grey_exclamation::grey_exclamation:-
#179MAY use Content-Location header:grey_exclamation::grey_exclamation:-
#180SHOULD use Location header instead of Content-Location header---
#181MAY consider to support Prefer header to handle processing preferences:grey_exclamation::grey_exclamation:-
#182MAY consider to support ETag together with If-Match/If-None-Match header:grey_exclamation::grey_exclamation:-
#183SHOULD use only the specified proprietary Zalando headers---
#184MUST propagate proprietary headers---
#185MUST obtain approval of clients before API shut down:grey_exclamation::grey_exclamation:-
#186MUST collect external partner consent on deprecation time span:grey_exclamation::grey_exclamation:-
#187MUST reflect deprecation in API specifications:grey_exclamation::grey_exclamation:-
#188MUST monitor usage of deprecated API scheduled for sunset:grey_exclamation::grey_exclamation:-
#189SHOULD add Deprecation and Sunset header to responses:grey_exclamation::grey_exclamation:-
#190SHOULD add monitoring for Deprecation and Sunset header:grey_exclamation::grey_exclamation:-
#191MUST not start using deprecated APIs:grey_exclamation::grey_exclamation:B
#192MUST publish Open API specification:grey_exclamation::grey_exclamation:A
#193SHOULD monitor API usage:grey_exclamation::grey_exclamation:-
#194MUST treat events as part of the service interface---
#195MUST make event schema available for review---
#196MUST ensure event schema conforms to Open API schema object---
#197MUST ensure that events are registered as event types---
#198MUST ensure that events conform to a well-known event category---
#199MUST ensure that events define useful business resources---
#200MUST ensure that events do not provide sensitive data---
#201MUST use the general event category to signal steps and arrival points in business processes---
#202MUST use data change events to signal mutations---
#203SHOULD provide means for explicit event ordering---
#204SHOULD use the hash partition strategy for data change events---
#205SHOULD ensure that data change events match the APIs resources---
#207MUST indicate ownership of event types---
#208MUST define event payloads compliant with overall API guidelines---
#209MUST maintain backwards compatibility for events---
#210SHOULD avoid additionalProperties in event type definitions---
#211MUST use unique event identifiers---
#212SHOULD design for idempotent out-of-order processing---
#213MUST follow naming convention for event type names---
#214MUST prepare event consumers for duplicate events---
#215MUST provide API identifiers:heavy_check_mark::heavy_check_mark:--
#216SHOULD define maps using additionalProperties---
#217MUST use full, absolute URI---
#218MUST contain API meta information:heavy_check_mark::heavy_check_mark:--
#219MUST provide API audience:heavy_check_mark:---
#219aMUST provide baloise API audience-:heavy_check_mark:--
#220MUST use most specific HTTP status codes:grey_exclamation::grey_exclamation:-
#223MUST-SHOULD use functional naming schema:grey_exclamation::grey_exclamation:-
#224MUST follow naming convention for hostnames:grey_exclamation::grey_exclamation:-
#225MUST follow naming convention for permissions (scopes):grey_exclamation::grey_exclamation:-
#226MUST document implicit filtering:grey_exclamation::grey_exclamation:-
#227MUST document cachable GET, HEAD, and POST endpoints:grey_exclamation::grey_exclamation:-
#228MUST use URL-friendly resource identifiers: [a-zA-Z0-9:._-/]*:grey_exclamation::grey_exclamation:A
#229SHOULD consider to design POST and PATCH idempotent:grey_exclamation::grey_exclamation:-
#230MAY consider to support Idempotency-Key header:grey_exclamation::grey_exclamation:-
#231Should use secondary key for idempotent POST design:grey_exclamation::grey_exclamation:-
#233aMUST request must use b3 tracing headers-:heavy_check_mark:-
#234MUST only use durable and immutable remote references:grey_exclamation::grey_exclamation:-
#235SHOULD name date/time properties with _at suffix---
#236SHOULD design simple query languages using query parameters:grey_exclamation::grey_exclamation:-
#237SHOULD design complex query languages using JSON:grey_exclamation::grey_exclamation:-
#238SHOULD use standardized property formats:grey_exclamation::grey_exclamation:-
#239SHOULD encode embedded binary data in base64url:grey_exclamation::grey_exclamation:-
#240SHOULD declare enum values using UPPER_SNAKE_CASE format:heavy_check_mark::heavy_check_mark:--
#241MAY expose compound keys as resource identifiers:grey_exclamation::grey_exclamation:-
1.1.9

2 months ago

1.1.8

2 months ago

1.1.7

3 months ago

1.1.5

4 months ago

1.1.3

1 year ago

1.1.1

1 year ago

1.1.2

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

0.7.1

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.1.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago