@mintlify/common
Version:
Commonly shared code within Mintlify
20 lines (19 loc) • 940 B
JavaScript
/**
* Converts an OpenAPI meta tag to a docs.json endpoint reference string.
*
* Meta tag format: "/openapi.json GET /plants" (leading slash on file path)
* Endpoint ref: "openapi.json GET /plants" (no leading slash)
*
* The full format includes the spec file path so it's self-contained —
* endpoints from different spec files can coexist in the same group.
*/
import { optionallyRemoveLeadingSlash } from '../optionallyRemoveLeadingSlash.js';
import { potentiallyParseOpenApiString } from './parseOpenApiString.js';
export function openApiMetaTagToEndpointRef(metaTag) {
const parsed = potentiallyParseOpenApiString(metaTag);
if (!parsed)
return undefined;
const method = parsed.method.toUpperCase();
const filename = parsed.filename ? optionallyRemoveLeadingSlash(parsed.filename) : undefined;
return filename ? `${filename} ${method} ${parsed.endpoint}` : `${method} ${parsed.endpoint}`;
}