Skip to content

dgarcia360/openapi-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

135 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenAPI linter License: MIT

OpenAPI boilerplate

A starter template for OpenAPI Specification (OAS) projects.

This project splits the Swagger Petstore example from the official documentation into smaller files. It also adds handy commands to build, lint, and preview the OpenAPI document from the terminal.

You can use this template as a starting point, whether you are creating a new OpenAPI document from scratch or splitting an existing one into multiple files.

Features

  • πŸ“ Write OpenAPI definitions in different files.
  • πŸ”€ Combine all files with redocly-cli.
  • βœ… Validate and lint the OpenAPI document with Spectral.
  • ✨ Publish reference docs with Scalar & GitHub Pages.

Why?

When I used to document APIs following the OpenAPI spec, I always ended up with documents of thousands of lines, which were a nightmare to maintain.

For this reason, I explored how to split OpenAPI documents. Jump over to my blog to learn more about the process. Based on my research, I created this opinionated template to define, test, and publish modular OpenAPI projects.

I've found that splitting a large spec into smaller files makes it easier to maintain and encourages other devs to contribute, as the structure feels more approachable.

Getting started

Requirements

  • Node.js 18+

Installation

  1. Clone the repository.

    git clone https://github.com/dgarcia360/openapi-boilerplate.git
    
  2. Install the project dependencies.

    npm install
    
  3. Edit the files under src/ to fit your API definition. If you’re not familiar with the OpenAPI Specification, read Getting started with OAS first.

Useful commands

The project will build, lint, and preview the OpenAPI document from the terminal, with the following commands:

Build

The command bundles the spec as one .yaml file.

npm run build

The bundled document is stored in _build/openapi.yaml.

Test

The command checks if the document follows the OpenAPI 3.1 Specification.

npm run test

Preview

The command builds a docs site so that you can view the rendering on your local browser.

npm run preview

The server starts on http://localhost:3000.

The site is generated with Scalar. Here's a preview: Swagger Petstore Reference Documentation.

Ready-to-use workflows

The project uses GitHub Actions for Continuous Integration (CI).

On every new pull request, the OpenAPI document is linted with Spectral. If there are changes that introduce errors, the workflow will fail and highlight them.

On every push to master and on pull requests, the build is tested against Node 18, 20, and 22.

When the default branch (e.g. master) receives an update, a workflow automatically publishes the API reference documentation site to GitHub Pages. This workflow can also be triggered manually from the Actions tab.

See .github/workflows to customize the available workflows. If you don't plan to use GitHub to host your spec or prefer to keep docs private, delete the .github folder.

Contributing

Contributions are welcome and appreciated! If you want to enhance the boilerplate, please read CONTRIBUTING.md file first.

License

Copyright (c) 2019-present David Garcia (@dgarcia360). Licensed under the MIT License.

The PetStore example used is derived from OAI/OpenAPI-Specification, Copyright The Linux Foundation, Licensed under the Apache License, Version 2.0.

About

πŸ“˜ Multi-file boilerplate for Open API Specification

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors