OpenAPI-Directory JS demo

node v10.24.1
version: 1.0.0
// For context on this, see const { findApi } = require('openapi-directory'); /** * The openapi-directory npm module exports a findIndex function, that takes a * URL (without the protocol) and returns the id for that API's OpenAPI specification. * * You can load the specification itself with require('openapi-directory/api/<id>'). * * Let's test it out: */ // Some example URLs: const requestUrls = [ "", "", "", ]; // For each, we look up the id, load the spec, and print the root URL for its documentation: requestUrls.forEach((url) => { console.log(url); // Look up the API spec id from the URL: const apiId = findApi(url); // With the id, you can require() a full specification for this API: const apiSpec = require(`openapi-directory/api/${apiId}`); // Includes lots of things, e.g. a link straight to the API docs: console.log(` -> Docs: ${apiSpec.externalDocs.url}`); }); // This is just the basics info though: OpenAPI specs like these also contain per-endpoint // info and schemas, detailed request & response examples, and a whole bunch more.

no comments

    sign in to comment