Join our community of software engineering leaders and aspirational developers. Always
stay in-the-know by getting the most important news and exclusive content delivered
fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter
in the past. Click the button below to open the re-subscribe form
in a new tab. When you're done, simply close that tab and continue
with this form to complete your subscription.
The New Stack does not sell your information or share it with
unaffiliated third parties. By continuing, you agree to our
Terms of Use and
Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!
We’re so glad you’re here. You can expect all the best TNS content to arrive
Monday through Friday to keep you on top of the news and at the top of your game.
What’s next?
Check your inbox for a confirmation email where you can adjust your preferences
and even join additional groups.
Follow TNS on your favorite social media networks.
Featured image by Christopher Burns from Unsplash.
API governance is a cornerstone of good API experiences for both producers and consumers. We talk a lot about how OpenAPI is about much more than the tools, but the tools can help a lot, too. Let’s take a look at the options available and how they fit your workflow.
Tools for API Governance
The main tool in the API governance toolbox is the linter, sometimes also called a validator. These tools check an OpenAPI description against a set of standards. Which standards? The ones you configure. Investing the time to configure the linter to support the agreed API standards is a key ingredient to implementing good API governance.
There are multiple decent tools available for linting, and most of them are open source, which means you can easily try them out and find one you like. Try these for starters:
Each of these tools will offer a default “recommended” ruleset. However, these tend to be rather stringent, and I wouldn’t actually recommend them as a starting point unless they align closely with the API standards you identified for yourselves. Especially when retrofitting API governance to an existing API project, slow and iterative is the real recommended approach.
Start Simple
Start by picking a tool: in these examples, I’m using Vacuum, but Spectral supports the same rule configuration if you prefer that. Turn off the default rules and enable what makes sense for your situation. A great place to start is to enable the `oas3-schema` rule and check that the OpenAPI description you have is valid. It’s surprising how many OpenAPI tools don’t quite output valid OpenAPI in every situation.
To turn off the default rules and check for a valid description, use a `ruleset.yaml` file like this:
Run this ruleset over your `openapi.yaml` file with Vacuum using the following command:
If you don’t have an OpenAPI file handy, you’re welcome to grab the Blog OpenAPI example I used and try that. (It includes some problems that will be exposed when we add a few more rules.)
If the OpenAPI description is invalid, the problems and where in the file they occur will be displayed in the output. The command also returns an error, so this tool is useful in a CI setup, where it will return a failure status and alert you of a problem.
Selectively Add Rules
One reason why the recommended rulesets are such a challenge for existing APIs is that they don’t have the context of what your application does and what’s important. It’s better to focus on the areas that matter to your organization instead of a generic set of priorities.
In this example, the focus is on developer experience, creating an API that our technical users will be happy to integrate with. To support this, the first rules to add are:
`operation-operationId` and `operation-operationId-unique` make sure that each operation has a unique identifier; these values are used as anchors in documentation and often as method names in generated SDKs.
`operation-tag-defined` and `tag-description` require every tag used in the API description to be declared in the top-level `tags` section and to have a description.
`operation-description`, `schema-description`, and `component-description` ensure that there are description fields throughout the API description. Adding meaningful information, written by humans, is low-hanging fruit when it comes to improving the developer experience of your API.
`description-duplication` provides a low-level information message if two description fields are identical, as this usually indicates a copy/paste error.
With the additional rules, here is the updated `ruleset.yaml` file:
You might notice that when we run the command this time, the output reports some problems:
Vacuum’s output reports errors.
The errors are caused by one of the endpoints missing both an `operationId` (technically not a required field in OpenAPI but definitely a good idea) and a description. Try fixing the error yourself and rerunning the command to see the updated output.
For your own API descriptions, pick the rules that fit the priorities you have. Dig into the Vacuum rulesets documentation and build out a starter set of rules to fit your own project.
Integrate Checks Into Your Workflow
Having API linting running at multiple points in the API development lifecycle is good practice because it keeps the feedback cycles short and helps developers innovate faster.
For design-first projects, having linting set up on local development platforms is a must-have. Some tools integrate into IDEs, or you can run the tools on the CLI on your development machine.
Whether designed or generated, OpenAPI changes should be reviewed in a pull request, and API governance checks including linting definitely belong there! Use the CLI command from above in your existing CI workflow setup, such as GitHub Actions or GitLab/Azure pipelines.
Vacuum can produce an interactive HTML report that is a very user-friendly way to review the output of the linting rules. Use it locally for a nicer way to see what’s happening, or build it in your CI process to give reviewers a pleasing interface to look at. Vacuum’s support for documentation for every rule (including any custom rules you create) is a great way to provide more context and advice to support each rule.
Vacuum’s dashboard provides interactive reports.
You might also want to look at the dashboard command, which produces a terminal-based dashboard of linting output, or generate a report in JSON or Spectral format.
API Governance Is More Than Automation
API governance is more than automation, but automating the easy stuff really helps. Don’t feel daunted by the long lists of things that aren’t perfect or rules that aren’t enabled.
Adding linting to your day-to-day work brings quality and consistency to your API development, and even if there are things you can’t fix today, the checks can be added to avoid any regressions or mistakes in new API features as it grows.
So look at where you are with API governance, and where you’d like to go, and use linting to help you take a step or two along the way.
Hasura makes data access easy, by instantly composing a GraphQL API that is backed by databases and services so that the developer team (or API consumers) get immediately productive. The nature of GraphQL itself and Hasura’s dynamic approach makes integration and iteration easy.