@mintlify/common 1.0.323 → 1.0.325
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asyncapi/getAsyncApiChannelMetadata.d.ts +2 -0
- package/dist/asyncapi/getAsyncApiChannelMetadata.js +30 -0
- package/dist/asyncapi/parseAsyncApiString.d.ts +2 -0
- package/dist/asyncapi/parseAsyncApiString.js +21 -0
- package/dist/asyncapi/prepAsyncApiFrontmatter.d.ts +1 -0
- package/dist/asyncapi/prepAsyncApiFrontmatter.js +18 -0
- package/dist/camelToSentenceCase.d.ts +1 -0
- package/dist/camelToSentenceCase.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/openapi/index.d.ts +0 -1
- package/dist/openapi/index.js +0 -1
- package/dist/openapi/prepOpenApiFrontmatter.js +3 -3
- package/dist/schema/common.d.ts +1 -0
- package/dist/schema/common.js +6 -0
- package/dist/slug/getDecoratedNavPageAndSlug.d.ts +2 -1
- package/dist/slug/getDecoratedNavPageAndSlug.js +15 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/asyncapi.d.ts +6 -0
- package/package.json +4 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parseAsyncApiString } from './parseAsyncApiString.js';
|
|
2
|
+
export const getAsyncApiChannelMetadata = (asyncApiMetaField, asyncApiFiles) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const potentiallyParsedAsyncApiString = parseAsyncApiString(asyncApiMetaField);
|
|
5
|
+
if (potentiallyParsedAsyncApiString == undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const { channelId, filename } = potentiallyParsedAsyncApiString;
|
|
9
|
+
let asyncApiFile = undefined;
|
|
10
|
+
for (const file of asyncApiFiles) {
|
|
11
|
+
const asyncApiSpec = file.spec;
|
|
12
|
+
const hasAsyncApiChannel = asyncApiSpec.allChannels().has(channelId);
|
|
13
|
+
const filenameMatches = !filename || filename === file.filename || filename === file.originalFileLocation;
|
|
14
|
+
if (hasAsyncApiChannel && filenameMatches) {
|
|
15
|
+
asyncApiFile = file;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (asyncApiFile == null) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const channelInterface = asyncApiFile.spec.channels().get(channelId);
|
|
22
|
+
const channelTitle = (_a = channelInterface.title()) !== null && _a !== void 0 ? _a : '';
|
|
23
|
+
const channelDescription = (_b = channelInterface.description()) !== null && _b !== void 0 ? _b : '';
|
|
24
|
+
return {
|
|
25
|
+
channelId,
|
|
26
|
+
filename: asyncApiFile.filename,
|
|
27
|
+
title: channelTitle,
|
|
28
|
+
description: channelDescription,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const parseAsyncApiString = (str) => {
|
|
2
|
+
const components = str.trim().split(/\s+/);
|
|
3
|
+
let filename;
|
|
4
|
+
let channelId;
|
|
5
|
+
if (components.length > 2) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
else if (components[0] && components[1]) {
|
|
9
|
+
[filename, channelId] = components;
|
|
10
|
+
}
|
|
11
|
+
else if (components[0]) {
|
|
12
|
+
channelId = components[0];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
filename,
|
|
19
|
+
channelId,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prepAsyncApiFrontmatter(currPath: string, asyncApiFrontmatter?: string): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parse } from 'path';
|
|
2
|
+
import { parseAsyncApiString } from '../asyncapi/parseAsyncApiString.js';
|
|
3
|
+
import { normalizeRelativePath } from '../fs/normalizeRelativePath.js';
|
|
4
|
+
import { schemaFileFrontmatterIsOriginalFileLocation } from '../schema/common.js';
|
|
5
|
+
export function prepAsyncApiFrontmatter(currPath, asyncApiFrontmatter) {
|
|
6
|
+
if (!asyncApiFrontmatter)
|
|
7
|
+
return undefined;
|
|
8
|
+
const asyncApiObj = parseAsyncApiString(asyncApiFrontmatter);
|
|
9
|
+
if ((asyncApiObj === null || asyncApiObj === void 0 ? void 0 : asyncApiObj.filename) && schemaFileFrontmatterIsOriginalFileLocation(asyncApiObj.filename)) {
|
|
10
|
+
if (asyncApiObj.filename.startsWith('https://')) {
|
|
11
|
+
return `${asyncApiObj.filename} ${asyncApiObj.channelId}`;
|
|
12
|
+
}
|
|
13
|
+
const currDir = parse(currPath).dir;
|
|
14
|
+
const newAsyncApiFilename = normalizeRelativePath(currDir, asyncApiObj.filename);
|
|
15
|
+
return `${newAsyncApiFilename} ${asyncApiObj.channelId}`;
|
|
16
|
+
}
|
|
17
|
+
return asyncApiFrontmatter;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const camelToSentenceCase: (str: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const camelToSentenceCase = (str) => {
|
|
2
|
+
// Split on capital letters and convert to lowercase
|
|
3
|
+
const words = str.split(/(?=[A-Z])/).map((word) => word.toLowerCase());
|
|
4
|
+
// Capitalize first word and join with spaces
|
|
5
|
+
return words
|
|
6
|
+
.map((word, index) => (index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word))
|
|
7
|
+
.join(' ');
|
|
8
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/openapi/index.d.ts
CHANGED
|
@@ -6,4 +6,3 @@ export { getOpenApiTitleAndDescription } from './getOpenApiTitleAndDescription.j
|
|
|
6
6
|
export { validate, safeValidate } from './validate.js';
|
|
7
7
|
export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
|
|
8
8
|
export { prepOpenApiFrontmatter } from './prepOpenApiFrontmatter.js';
|
|
9
|
-
export { openApiFrontmatterIsOriginalFileLocation } from './openApiFrontmatterIsOriginalFileLocation.js';
|
package/dist/openapi/index.js
CHANGED
|
@@ -6,4 +6,3 @@ export { getOpenApiTitleAndDescription } from './getOpenApiTitleAndDescription.j
|
|
|
6
6
|
export { validate, safeValidate } from './validate.js';
|
|
7
7
|
export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
|
|
8
8
|
export { prepOpenApiFrontmatter } from './prepOpenApiFrontmatter.js';
|
|
9
|
-
export { openApiFrontmatterIsOriginalFileLocation } from './openApiFrontmatterIsOriginalFileLocation.js';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { parse, isAbsolute } from 'path';
|
|
2
2
|
import { normalizeRelativePath } from '../fs/normalizeRelativePath.js';
|
|
3
|
-
import {
|
|
3
|
+
import { schemaFileFrontmatterIsOriginalFileLocation } from '../schema/common.js';
|
|
4
4
|
import { potentiallyParseOpenApiString } from './parseOpenApiString.js';
|
|
5
5
|
export function prepOpenApiFrontmatter(currPath, openapiFrontmatter) {
|
|
6
6
|
if (!openapiFrontmatter)
|
|
7
7
|
return undefined;
|
|
8
8
|
const openapiObj = potentiallyParseOpenApiString(openapiFrontmatter);
|
|
9
|
-
if ((openapiObj === null || openapiObj === void 0 ? void 0 : openapiObj.filename) &&
|
|
10
|
-
if (openapiObj.filename.startsWith('
|
|
9
|
+
if ((openapiObj === null || openapiObj === void 0 ? void 0 : openapiObj.filename) && schemaFileFrontmatterIsOriginalFileLocation(openapiObj.filename)) {
|
|
10
|
+
if (openapiObj.filename.startsWith('https://')) {
|
|
11
11
|
return `${openapiObj.filename} ${openapiObj.method.toLowerCase()} ${openapiObj.endpoint}`;
|
|
12
12
|
}
|
|
13
13
|
const filenameIsAbsolute = isAbsolute(openapiObj.filename);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const schemaFileFrontmatterIsOriginalFileLocation: (filenameFromFrontmatter: string) => boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Functions used for both OpenAPI and AsyncAPI schemas
|
|
2
|
+
export const schemaFileFrontmatterIsOriginalFileLocation = (filenameFromFrontmatter) => {
|
|
3
|
+
return (filenameFromFrontmatter.toLowerCase().endsWith('.json') ||
|
|
4
|
+
filenameFromFrontmatter.toLowerCase().endsWith('.yaml') ||
|
|
5
|
+
filenameFromFrontmatter.toLowerCase().endsWith('.yml'));
|
|
6
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenApiFile, DecoratedNavigationPage } from '@mintlify/models';
|
|
2
|
-
|
|
2
|
+
import { AsyncAPIFile } from '../types/asyncapi.js';
|
|
3
|
+
export declare const getDecoratedNavPageAndSlug: (pagePath: string, pageContent: string, openApiFiles: OpenApiFile[], asyncApiFiles: AsyncAPIFile[]) => {
|
|
3
4
|
pageMetadata: DecoratedNavigationPage;
|
|
4
5
|
slug: string;
|
|
5
6
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import matter from 'gray-matter';
|
|
2
|
+
import { getAsyncApiChannelMetadata } from '../asyncapi/getAsyncApiChannelMetadata.js';
|
|
3
|
+
import { prepAsyncApiFrontmatter } from '../asyncapi/prepAsyncApiFrontmatter.js';
|
|
2
4
|
import { removeLeadingSlash, optionallyAddLeadingSlash } from '../fs/index.js';
|
|
3
5
|
import { getOpenApiTitleAndDescription } from '../openapi/getOpenApiTitleAndDescription.js';
|
|
4
6
|
import { prepOpenApiFrontmatter } from '../openapi/prepOpenApiFrontmatter.js';
|
|
5
7
|
import { pagePathToSlug } from './pagePathToSlug.js';
|
|
6
8
|
import { slugToTitle } from './slugToTitle.js';
|
|
7
|
-
export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles) => {
|
|
9
|
+
export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles, asyncApiFiles) => {
|
|
8
10
|
let metadata = {};
|
|
9
11
|
try {
|
|
10
12
|
metadata = matter(pageContent).data;
|
|
@@ -26,16 +28,21 @@ export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles)
|
|
|
26
28
|
}
|
|
27
29
|
const slug = pagePathToSlug(pagePath);
|
|
28
30
|
const defaultTitle = slugToTitle(slug);
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
let openApiDescription;
|
|
31
|
+
let schemaTitle;
|
|
32
|
+
let schemaDescription;
|
|
32
33
|
if (metadata.openapi) {
|
|
33
34
|
metadata.openapi = prepOpenApiFrontmatter(pagePath, metadata.openapi);
|
|
34
|
-
const { title, description } = getOpenApiTitleAndDescription(openApiFiles, metadata.openapi);
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const { title: openApiSchemaTitle, description: openApiSchemaDescription } = getOpenApiTitleAndDescription(openApiFiles, metadata.openapi);
|
|
36
|
+
schemaTitle = openApiSchemaTitle;
|
|
37
|
+
schemaDescription = openApiSchemaDescription;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
if (metadata.asyncapi) {
|
|
40
|
+
metadata.asyncapi = prepAsyncApiFrontmatter(pagePath, metadata.asyncapi);
|
|
41
|
+
const parsedMetadata = getAsyncApiChannelMetadata(metadata.asyncapi, asyncApiFiles);
|
|
42
|
+
schemaTitle = parsedMetadata === null || parsedMetadata === void 0 ? void 0 : parsedMetadata.title;
|
|
43
|
+
schemaDescription = parsedMetadata === null || parsedMetadata === void 0 ? void 0 : parsedMetadata.description;
|
|
44
|
+
}
|
|
45
|
+
const pageMetadata = Object.assign(Object.assign({ title: schemaTitle !== null && schemaTitle !== void 0 ? schemaTitle : defaultTitle, description: schemaDescription }, metadata), { href: optionallyAddLeadingSlash(slug) });
|
|
39
46
|
return {
|
|
40
47
|
pageMetadata,
|
|
41
48
|
slug: removeLeadingSlash(slug),
|