UNPKG

rdme

Version:

ReadMe's official CLI and GitHub Action.

48 lines (47 loc) 1.8 kB
import type { CommandIdForTopic } from '../index.js'; import OASNormalize from 'oas-normalize'; export type SpecFileType = OASNormalize['type']; type OpenAPIAction = CommandIdForTopic<'openapi'>; /** * Normalizes, validates, and (optionally) bundles an OpenAPI definition. */ export default function prepareOas( /** * Path to a spec file. If this is missing, the current directory is searched for * certain file names. */ path: string | undefined, /** * The command context in which this is being run within (uploading a spec, * validation, or reducing one). */ command: `openapi ${OpenAPIAction}`, opts?: { /** * An optional title to replace the value in the `info.title` field. * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#info-object} */ title?: string; }): Promise<{ preparedSpec: string; /** A string indicating whether the spec file is a local path, a URL, etc. */ specFileType: false | "json" | "buffer" | "path" | "string-json" | "string-yaml" | "url"; /** The path/URL to the spec file */ specPath: string; /** A string indicating whether the spec file is OpenAPI, Swagger, etc. */ specType: "OpenAPI" | "Postman" | "Swagger" | "Unknown"; /** * The `info.version` field, extracted from the normalized spec. * This is **not** the OpenAPI version (e.g., 3.1, 3.0), * this is a user input that we use to specify the version in ReadMe * (if they use the `useSpecVersion` flag) */ specVersion: string; /** * This is the `openapi`, `swagger`, or `postman` specification version of their API definition. */ definitionVersion: { specification: "openapi" | "postman" | "swagger"; version: string | "unknown"; }; }>; export {};