3 API linting: Automating API consistency
This chapter covers
- Using linting to ensure your API is consistent with your style guide
- Writing custom API linting rules
- Creating AI-assisted linting rules
In chapter 1, I introduced APIOps and its benefits, and chapter 2 gave you some conceptual tools to approach your APIOps transformation. In this chapter, you’ll take a more hands-on first step of applying APIOps. This chapter introduces you to running API linting rules to check that your API is consistent with your API style guides. This chapter is relevant to developers designing and implementing APIs, but API product owners and product managers will also benefit from getting an overview of how API linting works. I’ll show you how to run API linting in your API design editor and on your command line, as well as how to create a simple API linting rule. I’ll also show you how AI can support you when creating linting rules.
Follow the instructions in appendix B to install the tools you require for this chapter, that is, Spectral CLI, Visual Studio Code (VS Code), OpenAPI (Swagger) Editor VS Code plugin, yq, jpp, and GitHub Copilot. To work along with the exercises in this chapter, clone the book’s code repository at https://github.com/apiopsbook/apiops, and navigate to the chapter3 directory. However, if you just want to see the files with the completed exercises, navigate to the chapter3-completed folder.