UNPKG

koas-spec-handler

Version:

Koas spec handler exposes the Open API document as a JSON API call.

20 lines (19 loc) 615 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.specHandler = void 0; /** * Serve the Koas OpenAPI document as JSON. * * @param options - Options to configure how the OpenAPI document is served. * @returns A Koas plugin to serve the OpenAPI document. */ function specHandler({ url = '/api.json' } = {}) { return ({ document, runAlways }) => runAlways((ctx, next) => { ctx.openApi.specURL = url; if (ctx.url !== url || ctx.method !== 'GET') { return next(); } ctx.body = document; }); } exports.specHandler = specHandler;