API Documentation and Validation Rules - by TRGoodwill - API Central - Medium
API Documentation and Validation Rules - by TRGoodwill - API Central - Medium
Rules
Improving the Quality and Consistency of APIs with OpenAPI
Documentation Rules and API Validation / API Linting Rules
TRGoodwill · Follow
Published in API Central · 5 min read · May 5
26
The name of the API resource & document should NOT be namespaced
with hyphenated leading name-parts; API paths, teams and groups
should provide domain & sub-domain namespacing. e.g.
/membership/v1/applications NOT membership-applications
The OpenAPI “info” object “version” field MUST be present, and MUST
contain the full semantic version number of the API — e.g. “version:
2.3.1”. Only major version numbers embedded into URLs.
contact:
name: myAPI Support
email: [email protected]
API request and response examples SHOULD be included in the
specification document to assist client developers.
API Validation
Governance of API design standards and security policy compliance must be
automated wherever possible. OpenAPI document linting is supported by
some IDEs, and CI/CD pipelines incorporating OpenAPI document linting
can provide feedback on API quality and enforce mandatory API standards
and patterns.
path-params: Path parameters are correct and valid. For every parameter
referenced in the path string (i.e: /users/{userId}), the parameter must be
defined in either path.parameters, or operation.parameters objects.
Every path.parameters and operation.parameters parameter must be
used in the path string.
Extension rulesets can be easily configured via the Stoplight free tier (web or
locally installed) and must be maintained and made available for integration
into IDE tools and CI/CD pipelines by the API platform or competency team.
Open in app
Stoplight Studio : Upload an OpenAPI spec, or paste into the code editor,
Search Write
and the spectral base-ruleset will automatically provide feedback. The
warning icon will toggle a side-by-side view.
Validation will return non-blocking warnings that align with best practice
(‘should’) API design guidance, as well as errors corresponding to mandatory
(‘must’) design guidance that should fail code integration and build or
deployment of an OpenAPI specification.
Wrap-up
OpenAPI 3.x is the leading specification for the documentation of
synchronous HTTP APIs, and it enjoys widespread platform support. API
developers will need to be familiar with both OAS specification guidance and
enterprise API design guidance in order to produce consistent, quality API
documentation. API validation (e.g. Spectral) should be employed to improve
the quality and consistency of API documentation and enforce mandatory
rules.