@author.io/openapi

Create and modify OpenAPI specification documents.

Usage no npm install needed!

<script type="module">
  import authorIoOpenapi from 'https://cdn.skypack.dev/@author.io/openapi';
</script>

README

Sponsored by enabledb.com Sponsored by enabledb.com

npm install @author.io/openapi

import OAS from 'https://cdn.jsdelivr.net/npm/author.io/openapi/index.js'

OpenAPI Document

The OpenAPI Specification (OAS) is a widely used specification for defining HTTP APIs. This is a lower level JavaScript library for creating OpenAPI specifications in JSON format. The library is used to create an OpenAPI spec as an object. There are methods, attributes, and classes for each part of the OpenAPI 3.1 spec. These can be used to construct an OAS document and respond to changes. For example:

import { Document } from 'https://cdn.jsdelivr.net/npm/author.io/openapi/index.js'

const oas = new Document({
  name: 'My API'
})

oas.on('update.name', doSomething)

oas.addEndpoint('/path/:id', cfg_object)

console.log(oas.JSON)

The code above creates a new OpenAPI spec document and adds an endpoint to it before outputting the spec in JSON format.

What this library doesn't do...

  1. This library is not designed to support YAML/YML, even though it is a legitimate OpenAPI spec format. JavaScript only understands JSON. There are many libraries for converting YAML to JSON (or vice versa). This library doesn't need to recreate those projects.

  2. This library doesn't generate servers or clients.

Features

The library primarily contains objects which, when combined, produce a complete OpenAPI spec. Additionally, the library is built on an event emitter, allowing developers to respond to document changes in realtime.

update.<attribute_name> invalid.<attribute_name>