@sdk-it/spec 0.19.1 → 0.20.0
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/lib/operation.d.ts +3 -2
- package/dist/lib/operation.d.ts.map +1 -1
- package/dist/lib/operation.js +27 -47
- package/dist/lib/operation.js.map +2 -2
- package/dist/lib/sidebar.d.ts +47 -0
- package/dist/lib/sidebar.d.ts.map +1 -0
- package/dist/lib/sidebar.js +33 -0
- package/dist/lib/sidebar.js.map +7 -0
- package/package.json +3 -2
package/dist/lib/operation.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { OpenAPIObject, OperationObject, ParameterObject, ReferenceObject } from 'openapi3-ts/oas31';
|
|
1
|
+
import type { OpenAPIObject, OperationObject, ParameterObject, ReferenceObject, ResponseObject } from 'openapi3-ts/oas31';
|
|
2
2
|
export declare const defaults: Partial<GenerateSdkConfig> & Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>>;
|
|
3
|
-
export type TunedOperationObject = OperationObject & {
|
|
3
|
+
export type TunedOperationObject = Omit<OperationObject, 'operationId' | 'parameters' | 'responses'> & {
|
|
4
4
|
operationId: string;
|
|
5
5
|
parameters: (ParameterObject | ReferenceObject)[];
|
|
6
|
+
responses: Record<string, ResponseObject>;
|
|
6
7
|
};
|
|
7
8
|
export interface OperationEntry {
|
|
8
9
|
name?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/lib/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/lib/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACf,MAAM,mBAAmB,CAAC;AAK3B,eAAO,M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WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,iBAuB1E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,OAAO,CAoBT;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,OAAO,CAET;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAGxE"}
|
package/dist/lib/operation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { camelcase } from "stringcase";
|
|
2
|
+
import { followRef, isRef } from "@sdk-it/core";
|
|
2
3
|
const defaults = {
|
|
3
4
|
operationId: (operation, path, method) => {
|
|
4
5
|
if (operation.operationId) {
|
|
@@ -13,9 +14,18 @@ const defaults = {
|
|
|
13
14
|
);
|
|
14
15
|
},
|
|
15
16
|
tag: (operation, path) => {
|
|
16
|
-
return operation.tags?.[0]
|
|
17
|
+
return operation.tags?.[0] ? sanitizeTag(operation.tags?.[0]) : determineGenericTag(path, operation);
|
|
17
18
|
}
|
|
18
19
|
};
|
|
20
|
+
function resolveResponses(spec, operation) {
|
|
21
|
+
const responses = operation.responses ?? {};
|
|
22
|
+
const resolved = {};
|
|
23
|
+
for (const status in responses) {
|
|
24
|
+
const response = isRef(responses[status]) ? followRef(spec, responses[status].$ref) : responses[status];
|
|
25
|
+
resolved[status] = response;
|
|
26
|
+
}
|
|
27
|
+
return resolved;
|
|
28
|
+
}
|
|
19
29
|
function forEachOperation(config, callback) {
|
|
20
30
|
const result = [];
|
|
21
31
|
for (const [path, pathItem] of Object.entries(config.spec.paths ?? {})) {
|
|
@@ -39,7 +49,8 @@ function forEachOperation(config, callback) {
|
|
|
39
49
|
{
|
|
40
50
|
...operation,
|
|
41
51
|
parameters: [...parameters, ...operation.parameters ?? []],
|
|
42
|
-
operationId: operationName
|
|
52
|
+
operationId: operationName,
|
|
53
|
+
responses: resolveResponses(config.spec, operation)
|
|
43
54
|
}
|
|
44
55
|
)
|
|
45
56
|
);
|
|
@@ -48,15 +59,11 @@ function forEachOperation(config, callback) {
|
|
|
48
59
|
return result;
|
|
49
60
|
}
|
|
50
61
|
const reservedKeywords = /* @__PURE__ */ new Set([
|
|
51
|
-
"abstract",
|
|
52
|
-
"arguments",
|
|
53
62
|
"await",
|
|
54
|
-
|
|
63
|
+
// Reserved in async functions
|
|
55
64
|
"break",
|
|
56
|
-
"byte",
|
|
57
65
|
"case",
|
|
58
66
|
"catch",
|
|
59
|
-
"char",
|
|
60
67
|
"class",
|
|
61
68
|
"const",
|
|
62
69
|
"continue",
|
|
@@ -64,85 +71,59 @@ const reservedKeywords = /* @__PURE__ */ new Set([
|
|
|
64
71
|
"default",
|
|
65
72
|
"delete",
|
|
66
73
|
"do",
|
|
67
|
-
"double",
|
|
68
74
|
"else",
|
|
69
75
|
"enum",
|
|
70
|
-
"eval",
|
|
71
76
|
"export",
|
|
72
77
|
"extends",
|
|
73
78
|
"false",
|
|
74
|
-
"final",
|
|
75
79
|
"finally",
|
|
76
|
-
"float",
|
|
77
80
|
"for",
|
|
78
81
|
"function",
|
|
79
|
-
"goto",
|
|
80
82
|
"if",
|
|
81
83
|
"implements",
|
|
84
|
+
// Strict mode
|
|
82
85
|
"import",
|
|
83
86
|
"in",
|
|
84
87
|
"instanceof",
|
|
85
|
-
"int",
|
|
86
88
|
"interface",
|
|
89
|
+
// Strict mode
|
|
87
90
|
"let",
|
|
88
|
-
|
|
89
|
-
"native",
|
|
91
|
+
// Strict mode
|
|
90
92
|
"new",
|
|
91
93
|
"null",
|
|
92
94
|
"package",
|
|
95
|
+
// Strict mode
|
|
93
96
|
"private",
|
|
97
|
+
// Strict mode
|
|
94
98
|
"protected",
|
|
99
|
+
// Strict mode
|
|
95
100
|
"public",
|
|
101
|
+
// Strict mode
|
|
96
102
|
"return",
|
|
97
|
-
"short",
|
|
98
103
|
"static",
|
|
104
|
+
// Strict mode
|
|
99
105
|
"super",
|
|
100
106
|
"switch",
|
|
101
|
-
"synchronized",
|
|
102
107
|
"this",
|
|
103
108
|
"throw",
|
|
104
|
-
"throws",
|
|
105
|
-
"transient",
|
|
106
109
|
"true",
|
|
107
110
|
"try",
|
|
108
111
|
"typeof",
|
|
109
112
|
"var",
|
|
110
113
|
"void",
|
|
111
|
-
"volatile",
|
|
112
114
|
"while",
|
|
113
115
|
"with",
|
|
114
116
|
"yield",
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"
|
|
119
|
-
"any",
|
|
120
|
-
"unknown",
|
|
121
|
-
"never",
|
|
122
|
-
"get",
|
|
123
|
-
"list",
|
|
124
|
-
"create",
|
|
125
|
-
"update",
|
|
126
|
-
"delete",
|
|
127
|
-
"post",
|
|
128
|
-
"put",
|
|
129
|
-
"patch",
|
|
130
|
-
"do",
|
|
131
|
-
"send",
|
|
132
|
-
"add",
|
|
133
|
-
"remove",
|
|
134
|
-
"set",
|
|
135
|
-
"find",
|
|
136
|
-
"search",
|
|
137
|
-
"check",
|
|
138
|
-
"make"
|
|
139
|
-
// Added make, check
|
|
117
|
+
// Strict mode / Generator functions
|
|
118
|
+
// 'arguments' is not technically a reserved word, but it's a special identifier within functions
|
|
119
|
+
// and assigning to it or declaring it can cause issues or unexpected behavior.
|
|
120
|
+
"arguments"
|
|
140
121
|
]);
|
|
141
122
|
function sanitizeTag(camelCasedTag) {
|
|
142
123
|
if (/^\d/.test(camelCasedTag)) {
|
|
143
124
|
return `_${camelCasedTag}`;
|
|
144
125
|
}
|
|
145
|
-
return reservedKeywords.has(camelCasedTag) ? `${camelCasedTag}_` : camelCasedTag;
|
|
126
|
+
return reservedKeywords.has(camelcase(camelCasedTag)) ? `${camelCasedTag}_` : camelCasedTag;
|
|
146
127
|
}
|
|
147
128
|
function determineGenericTag(pathString, operation) {
|
|
148
129
|
const operationId = operation.operationId || "";
|
|
@@ -166,7 +147,6 @@ function determineGenericTag(pathString, operation) {
|
|
|
166
147
|
"search",
|
|
167
148
|
"check",
|
|
168
149
|
"make"
|
|
169
|
-
// Added make
|
|
170
150
|
]);
|
|
171
151
|
const segments = pathString.split("/").filter(Boolean);
|
|
172
152
|
const potentialCandidates = segments.filter(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n OpenAPIObject,\n OperationObject,\n ParameterObject,\n ReferenceObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nexport const defaults: Partial<GenerateSdkConfig> &\n Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>> = {\n operationId: (operation, path, method) => {\n if (operation.operationId) {\n return camelcase(operation.operationId);\n }\n const metadata = operation['x-oaiMeta'];\n if (metadata && metadata.name) {\n return camelcase(metadata.name);\n }\n return camelcase(\n [method, ...path.replace(/[\\\\/\\\\{\\\\}]/g, ' ').split(' ')]\n .filter(Boolean)\n .join(' ')\n .trim(),\n );\n },\n tag: (operation, path) => {\n return operation.tags?.[0] || determineGenericTag(path, operation);\n },\n};\n\nexport type TunedOperationObject = OperationObject & {\n operationId: string;\n parameters: (ParameterObject | ReferenceObject)[];\n};\n\nexport interface OperationEntry {\n name?: string;\n method: string;\n path: string;\n groupName: string;\n tag: string;\n}\nexport type Operation = {\n entry: OperationEntry;\n operation: TunedOperationObject;\n};\n\nexport function forEachOperation<T>(\n config: GenerateSdkConfig,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(config.spec.paths ?? {})) {\n const { parameters = [], ...methods } = pathItem;\n\n // Convert Express-style routes (:param) to OpenAPI-style routes ({param})\n const fixedPath = path.replace(/:([^/]+)/g, '{$1}');\n\n for (const [method, operation] of Object.entries(methods) as [\n string,\n OperationObject,\n ][]) {\n const formatOperationId = config.operationId ?? defaults.operationId;\n const formatTag = config.tag ?? defaults.tag;\n const operationName = formatOperationId(operation, fixedPath, method);\n const operationTag = formatTag(operation, fixedPath);\n const metadata = operation['x-oaiMeta'] ?? {};\n result.push(\n callback(\n {\n name: metadata.name,\n method,\n path: fixedPath,\n groupName: operationTag,\n tag: operationTag,\n },\n {\n ...operation,\n parameters: [...parameters, ...(operation.parameters ?? [])],\n operationId: operationName,\n },\n ),\n );\n }\n }\n return result;\n}\n\nexport interface GenerateSdkConfig {\n spec: OpenAPIObject;\n operationId?: (\n operation: OperationObject,\n path: string,\n method: string,\n ) => string;\n tag?: (operation: OperationObject, path: string) => string;\n}\n\n// --- Function Definition (determineGenericTag, sanitizeTag, reservedKeywords, commonVerbs) ---\n/**\n * Set of reserved TypeScript keywords and common verbs potentially used as tags.\n */\nconst reservedKeywords = new Set([\n 'abstract',\n 'arguments',\n 'await',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n // Potentially problematic identifiers / Common Verbs used as tags\n 'object',\n 'string',\n 'number',\n 'any',\n 'unknown',\n 'never',\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make', // Added make, check\n]);\n\n/**\n * Sanitizes a potential tag name (assumed to be already camelCased)\n * to avoid conflicts with reserved keywords or invalid starting characters (numbers).\n * Appends an underscore if the tag matches a reserved keyword.\n * Prepends an underscore if the tag starts with a number.\n * @param camelCasedTag The potential tag name, already camelCased.\n * @returns The sanitized tag name.\n */\nfunction sanitizeTag(camelCasedTag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(camelCasedTag)) {\n return `_${camelCasedTag}`;\n }\n // Append underscore if it's a reserved keyword\n return reservedKeywords.has(camelCasedTag)\n ? `${camelCasedTag}_`\n : camelCasedTag;\n}\n\n/**\n * Attempts to determine a generic tag for an OpenAPI operation based on path and operationId.\n * Rules and fallbacks are documented within the code.\n * @param pathString The path string.\n * @param operation The OpenAPI Operation Object.\n * @returns A sanitized, camelCased tag name string.\n */\nexport function determineGenericTag(\n pathString: string,\n operation: OperationObject,\n): string {\n const operationId = operation.operationId || '';\n const VERSION_REGEX = /^[vV]\\d+$/;\n const commonVerbs = new Set([\n // Verbs to potentially strip from operationId prefix\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make', // Added make\n ]);\n\n const segments = pathString.split('/').filter(Boolean);\n\n const potentialCandidates = segments.filter(\n (segment) =>\n segment &&\n !segment.startsWith('{') &&\n !segment.endsWith('}') &&\n !VERSION_REGEX.test(segment),\n );\n\n // --- Heuristic 1: Last non-'@' path segment ---\n for (let i = potentialCandidates.length - 1; i >= 0; i--) {\n const segment = potentialCandidates[i];\n if (!segment.startsWith('@')) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(segment));\n }\n }\n\n const canFallbackToPathSegment = potentialCandidates.length > 0;\n\n // --- Heuristic 2: OperationId parsing ---\n if (operationId) {\n const lowerOpId = operationId.toLowerCase();\n const parts = operationId\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')\n .replace(/([a-zA-Z])(\\d)/g, '$1_$2')\n .replace(/(\\d)([a-zA-Z])/g, '$1_$2')\n .toLowerCase()\n .split(/[_-\\s]+/);\n\n const validParts = parts.filter(Boolean);\n\n // Quick skip: If opId is just a verb and we can use Heuristic 3, prefer that.\n if (\n commonVerbs.has(lowerOpId) &&\n validParts.length === 1 &&\n canFallbackToPathSegment\n ) {\n // Proceed directly to Heuristic 3\n }\n // Only process if there are valid parts and the quick skip didn't happen\n else if (validParts.length > 0) {\n const firstPart = validParts[0];\n const isFirstPartVerb = commonVerbs.has(firstPart);\n\n // Case 2a: Starts with verb, has following parts\n if (isFirstPartVerb && validParts.length > 1) {\n const verbPrefixLength = firstPart.length;\n let nextPartStartIndex = -1;\n if (operationId.length > verbPrefixLength) {\n // Simplified check for next part start\n const charAfterPrefix = operationId[verbPrefixLength];\n if (charAfterPrefix >= 'A' && charAfterPrefix <= 'Z') {\n nextPartStartIndex = verbPrefixLength;\n } else if (charAfterPrefix >= '0' && charAfterPrefix <= '9') {\n nextPartStartIndex = verbPrefixLength;\n } else if (['_', '-'].includes(charAfterPrefix)) {\n nextPartStartIndex = verbPrefixLength + 1;\n } else {\n const match = operationId\n .substring(verbPrefixLength)\n .match(/[A-Z0-9]/);\n if (match && match.index !== undefined) {\n nextPartStartIndex = verbPrefixLength + match.index;\n }\n if (\n nextPartStartIndex === -1 &&\n operationId.length > verbPrefixLength\n ) {\n nextPartStartIndex = verbPrefixLength; // Default guess\n }\n }\n }\n\n if (\n nextPartStartIndex !== -1 &&\n nextPartStartIndex < operationId.length\n ) {\n const remainingOriginalSubstring =\n operationId.substring(nextPartStartIndex);\n const potentialTag = camelcase(remainingOriginalSubstring);\n if (potentialTag) {\n // Sanitize just before returning\n return sanitizeTag(potentialTag);\n }\n }\n\n // Fallback: join remaining lowercased parts\n const potentialTagJoined = camelcase(validParts.slice(1).join('_'));\n if (potentialTagJoined) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagJoined);\n }\n }\n\n // Case 2b: Doesn't start with verb, or only one part (might be verb)\n const potentialTagFull = camelcase(operationId);\n if (potentialTagFull) {\n const isResultSingleVerb = validParts.length === 1 && isFirstPartVerb;\n\n // Avoid returning only a verb if Heuristic 3 is possible\n if (!(isResultSingleVerb && canFallbackToPathSegment)) {\n if (potentialTagFull.length > 0) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagFull);\n }\n }\n }\n\n // Case 2c: Further fallbacks within OpId if above failed/skipped\n const firstPartCamel = camelcase(firstPart);\n if (firstPartCamel) {\n const isFirstPartCamelVerb = commonVerbs.has(firstPartCamel);\n if (\n !isFirstPartCamelVerb ||\n validParts.length === 1 ||\n !canFallbackToPathSegment\n ) {\n // Sanitize just before returning\n return sanitizeTag(firstPartCamel);\n }\n }\n if (\n isFirstPartVerb &&\n validParts.length > 1 &&\n validParts[1] &&\n canFallbackToPathSegment\n ) {\n const secondPartCamel = camelcase(validParts[1]);\n if (secondPartCamel) {\n // Sanitize just before returning\n return sanitizeTag(secondPartCamel);\n }\n }\n } // End if(validParts.length > 0) after quick skip check\n } // End if(operationId)\n\n // --- Heuristic 3: First path segment (stripping '@') ---\n if (potentialCandidates.length > 0) {\n let firstCandidate = potentialCandidates[0];\n if (firstCandidate.startsWith('@')) {\n firstCandidate = firstCandidate.substring(1);\n }\n if (firstCandidate) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(firstCandidate));\n }\n }\n\n // --- Heuristic 4: Default ---\n console.warn(\n `Could not determine a suitable tag for path: ${pathString}, operationId: ${operationId}. Using 'unknown'.`,\n );\n return 'unknown'; // 'unknown' is safe\n}\n\nexport function parseJsonContentType(contentType: string | null | undefined) {\n if (!contentType) {\n return null;\n }\n\n // 1. Trim whitespace\n let mainType = contentType.trim();\n\n // 2. Remove parameters (anything after the first ';')\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n mainType = mainType.substring(0, semicolonIndex).trim(); // Trim potential space before ';'\n }\n\n // 3. Convert to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n if (mainType.endsWith('/json')) {\n return mainType.split('/')[1];\n } else if (mainType.endsWith('+json')) {\n return mainType.split('+')[1];\n }\n return null;\n}\n\n/**\n * Checks if a given content type string represents Server-Sent Events (SSE).\n * Handles case-insensitivity, parameters (like charset), and leading/trailing whitespace.\n *\n * @param contentType The content type string to check (e.g., from a Content-Type header).\n * @returns True if the content type is 'text/event-stream', false otherwise.\n */\nexport function isSseContentType(\n contentType: string | null | undefined,\n): boolean {\n if (!contentType) {\n return false; // Handle null, undefined, or empty string\n }\n\n // 1. Trim whitespace from the input string\n let mainType = contentType.trim();\n\n // 2. Find the position of the first semicolon (if any) to remove parameters\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n // Extract the part before the semicolon and trim potential space\n mainType = mainType.substring(0, semicolonIndex).trim();\n }\n\n // 3. Convert the main type part to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n // 4. Compare against the standard SSE MIME type\n return mainType === 'text/event-stream';\n}\n\nexport function isStreamingContentType(\n contentType: string | null | undefined,\n): boolean {\n return contentType === 'application/octet-stream';\n}\n\nexport function isSuccessStatusCode(statusCode: number | string): boolean {\n statusCode = Number(statusCode);\n return statusCode >= 200 && statusCode < 300;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type {\n OpenAPIObject,\n OperationObject,\n ParameterObject,\n ReferenceObject,\n ResponseObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nimport { followRef, isRef } from '@sdk-it/core';\n\nexport const defaults: Partial<GenerateSdkConfig> &\n Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>> = {\n operationId: (operation, path, method) => {\n if (operation.operationId) {\n return camelcase(operation.operationId);\n }\n const metadata = operation['x-oaiMeta'];\n if (metadata && metadata.name) {\n return camelcase(metadata.name);\n }\n return camelcase(\n [method, ...path.replace(/[\\\\/\\\\{\\\\}]/g, ' ').split(' ')]\n .filter(Boolean)\n .join(' ')\n .trim(),\n );\n },\n tag: (operation, path) => {\n return operation.tags?.[0]\n ? sanitizeTag(operation.tags?.[0])\n : determineGenericTag(path, operation);\n },\n};\n\nexport type TunedOperationObject = Omit<\n OperationObject,\n 'operationId' | 'parameters' | 'responses'\n> & {\n operationId: string;\n parameters: (ParameterObject | ReferenceObject)[];\n responses: Record<string, ResponseObject>;\n};\n\nexport interface OperationEntry {\n name?: string;\n method: string;\n path: string;\n groupName: string;\n tag: string;\n}\nexport type Operation = {\n entry: OperationEntry;\n operation: TunedOperationObject;\n};\n\nfunction resolveResponses(spec: OpenAPIObject, operation: OperationObject) {\n const responses = operation.responses ?? {};\n const resolved: Record<string, ResponseObject> = {};\n for (const status in responses) {\n const response = isRef(responses[status] as ReferenceObject)\n ? followRef<ResponseObject>(spec, responses[status].$ref)\n : (responses[status] as ResponseObject);\n resolved[status] = response;\n }\n return resolved;\n}\n\nexport function forEachOperation<T>(\n config: GenerateSdkConfig,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(config.spec.paths ?? {})) {\n const { parameters = [], ...methods } = pathItem;\n\n // Convert Express-style routes (:param) to OpenAPI-style routes ({param})\n const fixedPath = path.replace(/:([^/]+)/g, '{$1}');\n\n for (const [method, operation] of Object.entries(methods) as [\n string,\n OperationObject,\n ][]) {\n const formatOperationId = config.operationId ?? defaults.operationId;\n const formatTag = config.tag ?? defaults.tag;\n const operationName = formatOperationId(operation, fixedPath, method);\n const operationTag = formatTag(operation, fixedPath);\n const metadata = operation['x-oaiMeta'] ?? {};\n\n result.push(\n callback(\n {\n name: metadata.name,\n method,\n path: fixedPath,\n groupName: operationTag,\n tag: operationTag,\n },\n {\n ...operation,\n parameters: [...parameters, ...(operation.parameters ?? [])],\n operationId: operationName,\n responses: resolveResponses(config.spec, operation),\n },\n ),\n );\n }\n }\n return result;\n}\n\nexport interface GenerateSdkConfig {\n spec: OpenAPIObject;\n operationId?: (\n operation: OperationObject,\n path: string,\n method: string,\n ) => string;\n tag?: (operation: OperationObject, path: string) => string;\n}\n\n/**\n * Set of reserved TypeScript keywords and common verbs potentially used as tags.\n */\n\nconst reservedKeywords = new Set([\n 'await', // Reserved in async functions\n 'break',\n 'case',\n 'catch',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'else',\n 'enum',\n 'export',\n 'extends',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'implements', // Strict mode\n 'import',\n 'in',\n 'instanceof',\n 'interface', // Strict mode\n 'let', // Strict mode\n 'new',\n 'null',\n 'package', // Strict mode\n 'private', // Strict mode\n 'protected', // Strict mode\n 'public', // Strict mode\n 'return',\n 'static', // Strict mode\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n 'yield', // Strict mode / Generator functions\n // 'arguments' is not technically a reserved word, but it's a special identifier within functions\n // and assigning to it or declaring it can cause issues or unexpected behavior.\n 'arguments',\n]);\n\n/**\n * Sanitizes a potential tag name (assumed to be already camelCased)\n * to avoid conflicts with reserved keywords or invalid starting characters (numbers).\n * Appends an underscore if the tag matches a reserved keyword.\n * Prepends an underscore if the tag starts with a number.\n * @param camelCasedTag The potential tag name, already camelCased.\n * @returns The sanitized tag name.\n */\nfunction sanitizeTag(camelCasedTag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(camelCasedTag)) {\n return `_${camelCasedTag}`;\n }\n // Append underscore if it's a reserved keyword\n return reservedKeywords.has(camelcase(camelCasedTag))\n ? `${camelCasedTag}_`\n : camelCasedTag;\n}\n\n/**\n * Attempts to determine a generic tag for an OpenAPI operation based on path and operationId.\n * Rules and fallbacks are documented within the code.\n * @param pathString The path string.\n * @param operation The OpenAPI Operation Object.\n * @returns A sanitized, camelCased tag name string.\n */\nexport function determineGenericTag(\n pathString: string,\n operation: OperationObject,\n): string {\n const operationId = operation.operationId || '';\n const VERSION_REGEX = /^[vV]\\d+$/;\n const commonVerbs = new Set([\n // Verbs to potentially strip from operationId prefix\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make',\n ]);\n\n const segments = pathString.split('/').filter(Boolean);\n\n const potentialCandidates = segments.filter(\n (segment) =>\n segment &&\n !segment.startsWith('{') &&\n !segment.endsWith('}') &&\n !VERSION_REGEX.test(segment),\n );\n\n // --- Heuristic 1: Last non-'@' path segment ---\n for (let i = potentialCandidates.length - 1; i >= 0; i--) {\n const segment = potentialCandidates[i];\n if (!segment.startsWith('@')) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(segment));\n }\n }\n\n const canFallbackToPathSegment = potentialCandidates.length > 0;\n\n // --- Heuristic 2: OperationId parsing ---\n if (operationId) {\n const lowerOpId = operationId.toLowerCase();\n const parts = operationId\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')\n .replace(/([a-zA-Z])(\\d)/g, '$1_$2')\n .replace(/(\\d)([a-zA-Z])/g, '$1_$2')\n .toLowerCase()\n .split(/[_-\\s]+/);\n\n const validParts = parts.filter(Boolean);\n\n // Quick skip: If opId is just a verb and we can use Heuristic 3, prefer that.\n if (\n commonVerbs.has(lowerOpId) &&\n validParts.length === 1 &&\n canFallbackToPathSegment\n ) {\n // Proceed directly to Heuristic 3\n }\n // Only process if there are valid parts and the quick skip didn't happen\n else if (validParts.length > 0) {\n const firstPart = validParts[0];\n const isFirstPartVerb = commonVerbs.has(firstPart);\n\n // Case 2a: Starts with verb, has following parts\n if (isFirstPartVerb && validParts.length > 1) {\n const verbPrefixLength = firstPart.length;\n let nextPartStartIndex = -1;\n if (operationId.length > verbPrefixLength) {\n // Simplified check for next part start\n const charAfterPrefix = operationId[verbPrefixLength];\n if (charAfterPrefix >= 'A' && charAfterPrefix <= 'Z') {\n nextPartStartIndex = verbPrefixLength;\n } else if (charAfterPrefix >= '0' && charAfterPrefix <= '9') {\n nextPartStartIndex = verbPrefixLength;\n } else if (['_', '-'].includes(charAfterPrefix)) {\n nextPartStartIndex = verbPrefixLength + 1;\n } else {\n const match = operationId\n .substring(verbPrefixLength)\n .match(/[A-Z0-9]/);\n if (match && match.index !== undefined) {\n nextPartStartIndex = verbPrefixLength + match.index;\n }\n if (\n nextPartStartIndex === -1 &&\n operationId.length > verbPrefixLength\n ) {\n nextPartStartIndex = verbPrefixLength; // Default guess\n }\n }\n }\n\n if (\n nextPartStartIndex !== -1 &&\n nextPartStartIndex < operationId.length\n ) {\n const remainingOriginalSubstring =\n operationId.substring(nextPartStartIndex);\n const potentialTag = camelcase(remainingOriginalSubstring);\n if (potentialTag) {\n // Sanitize just before returning\n return sanitizeTag(potentialTag);\n }\n }\n\n // Fallback: join remaining lowercased parts\n const potentialTagJoined = camelcase(validParts.slice(1).join('_'));\n if (potentialTagJoined) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagJoined);\n }\n }\n\n // Case 2b: Doesn't start with verb, or only one part (might be verb)\n const potentialTagFull = camelcase(operationId);\n if (potentialTagFull) {\n const isResultSingleVerb = validParts.length === 1 && isFirstPartVerb;\n\n // Avoid returning only a verb if Heuristic 3 is possible\n if (!(isResultSingleVerb && canFallbackToPathSegment)) {\n if (potentialTagFull.length > 0) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagFull);\n }\n }\n }\n\n // Case 2c: Further fallbacks within OpId if above failed/skipped\n const firstPartCamel = camelcase(firstPart);\n if (firstPartCamel) {\n const isFirstPartCamelVerb = commonVerbs.has(firstPartCamel);\n if (\n !isFirstPartCamelVerb ||\n validParts.length === 1 ||\n !canFallbackToPathSegment\n ) {\n // Sanitize just before returning\n return sanitizeTag(firstPartCamel);\n }\n }\n if (\n isFirstPartVerb &&\n validParts.length > 1 &&\n validParts[1] &&\n canFallbackToPathSegment\n ) {\n const secondPartCamel = camelcase(validParts[1]);\n if (secondPartCamel) {\n // Sanitize just before returning\n return sanitizeTag(secondPartCamel);\n }\n }\n } // End if(validParts.length > 0) after quick skip check\n } // End if(operationId)\n\n // --- Heuristic 3: First path segment (stripping '@') ---\n if (potentialCandidates.length > 0) {\n let firstCandidate = potentialCandidates[0];\n if (firstCandidate.startsWith('@')) {\n firstCandidate = firstCandidate.substring(1);\n }\n if (firstCandidate) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(firstCandidate));\n }\n }\n\n // --- Heuristic 4: Default ---\n console.warn(\n `Could not determine a suitable tag for path: ${pathString}, operationId: ${operationId}. Using 'unknown'.`,\n );\n return 'unknown'; // 'unknown' is safe\n}\n\nexport function parseJsonContentType(contentType: string | null | undefined) {\n if (!contentType) {\n return null;\n }\n\n // 1. Trim whitespace\n let mainType = contentType.trim();\n\n // 2. Remove parameters (anything after the first ';')\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n mainType = mainType.substring(0, semicolonIndex).trim(); // Trim potential space before ';'\n }\n\n // 3. Convert to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n if (mainType.endsWith('/json')) {\n return mainType.split('/')[1];\n } else if (mainType.endsWith('+json')) {\n return mainType.split('+')[1];\n }\n return null;\n}\n\n/**\n * Checks if a given content type string represents Server-Sent Events (SSE).\n * Handles case-insensitivity, parameters (like charset), and leading/trailing whitespace.\n *\n * @param contentType The content type string to check (e.g., from a Content-Type header).\n * @returns True if the content type is 'text/event-stream', false otherwise.\n */\nexport function isSseContentType(\n contentType: string | null | undefined,\n): boolean {\n if (!contentType) {\n return false; // Handle null, undefined, or empty string\n }\n\n // 1. Trim whitespace from the input string\n let mainType = contentType.trim();\n\n // 2. Find the position of the first semicolon (if any) to remove parameters\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n // Extract the part before the semicolon and trim potential space\n mainType = mainType.substring(0, semicolonIndex).trim();\n }\n\n // 3. Convert the main type part to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n // 4. Compare against the standard SSE MIME type\n return mainType === 'text/event-stream';\n}\n\nexport function isStreamingContentType(\n contentType: string | null | undefined,\n): boolean {\n return contentType === 'application/octet-stream';\n}\n\nexport function isSuccessStatusCode(statusCode: number | string): boolean {\n statusCode = Number(statusCode);\n return statusCode >= 200 && statusCode < 300;\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,iBAAiB;AAE1B,SAAS,WAAW,aAAa;AAE1B,MAAM,WACgD;AAAA,EAC3D,aAAa,CAAC,WAAW,MAAM,WAAW;AACxC,QAAI,UAAU,aAAa;AACzB,aAAO,UAAU,UAAU,WAAW;AAAA,IACxC;AACA,UAAM,WAAW,UAAU,WAAW;AACtC,QAAI,YAAY,SAAS,MAAM;AAC7B,aAAO,UAAU,SAAS,IAAI;AAAA,IAChC;AACA,WAAO;AAAA,MACL,CAAC,QAAQ,GAAG,KAAK,QAAQ,gBAAgB,GAAG,EAAE,MAAM,GAAG,CAAC,EACrD,OAAO,OAAO,EACd,KAAK,GAAG,EACR,KAAK;AAAA,IACV;AAAA,EACF;AAAA,EACA,KAAK,CAAC,WAAW,SAAS;AACxB,WAAO,UAAU,OAAO,CAAC,IACrB,YAAY,UAAU,OAAO,CAAC,CAAC,IAC/B,oBAAoB,MAAM,SAAS;AAAA,EACzC;AACF;AAuBA,SAAS,iBAAiB,MAAqB,WAA4B;AACzE,QAAM,YAAY,UAAU,aAAa,CAAC;AAC1C,QAAM,WAA2C,CAAC;AAClD,aAAW,UAAU,WAAW;AAC9B,UAAM,WAAW,MAAM,UAAU,MAAM,CAAoB,IACvD,UAA0B,MAAM,UAAU,MAAM,EAAE,IAAI,IACrD,UAAU,MAAM;AACrB,aAAS,MAAM,IAAI;AAAA,EACrB;AACA,SAAO;AACT;AAEO,SAAS,iBACd,QACA,UACA;AACA,QAAM,SAAc,CAAC;AACrB,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,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9B,WAAW,SAAS,SAAS,OAAO,GAAG;AACrC,WAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,EAC9B;AACA,SAAO;AACT;AASO,SAAS,iBACd,aACS;AACT,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AAGA,MAAI,WAAW,YAAY,KAAK;AAGhC,QAAM,iBAAiB,SAAS,QAAQ,GAAG;AAC3C,MAAI,mBAAmB,IAAI;AAEzB,eAAW,SAAS,UAAU,GAAG,cAAc,EAAE,KAAK;AAAA,EACxD;AAGA,aAAW,SAAS,YAAY;AAGhC,SAAO,aAAa;AACtB;AAEO,SAAS,uBACd,aACS;AACT,SAAO,gBAAgB;AACzB;AAEO,SAAS,oBAAoB,YAAsC;AACxE,eAAa,OAAO,UAAU;AAC9B,SAAO,cAAc,OAAO,aAAa;AAC3C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
|
+
export type ChildNavItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
url: string;
|
|
6
|
+
isActive?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type NavItem = {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
url: string;
|
|
13
|
+
isActive?: boolean;
|
|
14
|
+
items?: ChildNavItem[];
|
|
15
|
+
};
|
|
16
|
+
export type CategoryItem = {
|
|
17
|
+
category: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
items: NavItem[];
|
|
20
|
+
isActive?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type SidebarData = CategoryItem[];
|
|
23
|
+
export declare function toSidebar(spec: OpenAPIObject, route: string): SidebarData;
|
|
24
|
+
export interface XOaiMeta {
|
|
25
|
+
navigationGroups: NavigationGroup[];
|
|
26
|
+
groups: Group[];
|
|
27
|
+
}
|
|
28
|
+
export interface Group {
|
|
29
|
+
id: string;
|
|
30
|
+
title: string;
|
|
31
|
+
description: string;
|
|
32
|
+
navigationGroup: string;
|
|
33
|
+
sections?: Section[];
|
|
34
|
+
beta?: boolean;
|
|
35
|
+
legacy?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface Section {
|
|
38
|
+
type: 'endpoint' | 'object';
|
|
39
|
+
key: string;
|
|
40
|
+
path: string;
|
|
41
|
+
}
|
|
42
|
+
export interface NavigationGroup {
|
|
43
|
+
id: string;
|
|
44
|
+
title: string;
|
|
45
|
+
beta?: boolean;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=sidebar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidebar.d.ts","sourceRoot":"","sources":["../../src/lib/sidebar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,YAAY,EAAE,CAAC;AAGzC,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,eA6B3D;AAED,MAAM,WAAW,QAAQ;IACvB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { camelcase } from "stringcase";
|
|
2
|
+
function toSidebar(spec, route) {
|
|
3
|
+
const openapi = spec;
|
|
4
|
+
const sidebar = [];
|
|
5
|
+
const [activeGroup] = route.split("/");
|
|
6
|
+
for (const navGroup of openapi["x-oaiMeta"].navigationGroups) {
|
|
7
|
+
const group = openapi["x-oaiMeta"].groups.filter(
|
|
8
|
+
(group2) => group2.navigationGroup === navGroup.id
|
|
9
|
+
);
|
|
10
|
+
sidebar.push({
|
|
11
|
+
category: navGroup.title,
|
|
12
|
+
isActive: false,
|
|
13
|
+
items: group.map((item) => ({
|
|
14
|
+
id: item.id,
|
|
15
|
+
title: item.title,
|
|
16
|
+
url: `/${item.id}`,
|
|
17
|
+
isActive: activeGroup === item.id,
|
|
18
|
+
description: item.description,
|
|
19
|
+
items: (item.sections ?? []).filter((it) => it.type === "endpoint").map((section) => ({
|
|
20
|
+
id: section.key,
|
|
21
|
+
title: section.key,
|
|
22
|
+
url: `/${item.id}/${camelcase(section.key)}`,
|
|
23
|
+
isActive: `/${item.id}/${camelcase(section.key)}` === `/${route}`
|
|
24
|
+
}))
|
|
25
|
+
}))
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return sidebar;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
toSidebar
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=sidebar.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/sidebar.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIObject } from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nexport type ChildNavItem = {\n id: string;\n title: string;\n url: string;\n isActive?: boolean;\n};\n\nexport type NavItem = {\n id: string;\n title: string;\n description?: string;\n url: string;\n isActive?: boolean;\n items?: ChildNavItem[];\n};\n\nexport type CategoryItem = {\n category: string;\n description?: string;\n items: NavItem[];\n isActive?: boolean;\n};\n\nexport type SidebarData = CategoryItem[];\n\n\nexport function toSidebar(spec: OpenAPIObject, route: string) {\n const openapi: OpenAPIObject & { 'x-oaiMeta': XOaiMeta } = spec as any;\n const sidebar: SidebarData = [];\n const [activeGroup] = route.split('/');\n for (const navGroup of openapi['x-oaiMeta'].navigationGroups) {\n const group = openapi['x-oaiMeta'].groups.filter(\n (group) => group.navigationGroup === navGroup.id,\n );\n sidebar.push({\n category: navGroup.title,\n isActive: false,\n items: group.map((item) => ({\n id: item.id,\n title: item.title,\n url: `/${item.id}`,\n isActive: activeGroup === item.id,\n description: item.description,\n items: (item.sections ?? [])\n .filter((it) => it.type === 'endpoint')\n .map((section) => ({\n id: section.key,\n title: section.key,\n url: `/${item.id}/${camelcase(section.key)}`,\n isActive: `/${item.id}/${camelcase(section.key)}` === `/${route}`,\n })),\n })),\n });\n }\n return sidebar;\n}\n\nexport interface XOaiMeta {\n navigationGroups: NavigationGroup[];\n groups: Group[];\n}\n\nexport interface Group {\n id: string;\n title: string;\n description: string;\n navigationGroup: string;\n sections?: Section[];\n beta?: boolean;\n legacy?: boolean;\n}\n\nexport interface Section {\n type: 'endpoint' | 'object';\n key: string;\n path: string;\n}\n\nexport interface NavigationGroup {\n id: string;\n title: string;\n beta?: boolean;\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,iBAAiB;AA4BnB,SAAS,UAAU,MAAqB,OAAe;AAC5D,QAAM,UAAqD;AAC3D,QAAM,UAAuB,CAAC;AAC9B,QAAM,CAAC,WAAW,IAAI,MAAM,MAAM,GAAG;AACrC,aAAW,YAAY,QAAQ,WAAW,EAAE,kBAAkB;AAC5D,UAAM,QAAQ,QAAQ,WAAW,EAAE,OAAO;AAAA,MACxC,CAACA,WAAUA,OAAM,oBAAoB,SAAS;AAAA,IAChD;AACA,YAAQ,KAAK;AAAA,MACX,UAAU,SAAS;AAAA,MACnB,UAAU;AAAA,MACV,OAAO,MAAM,IAAI,CAAC,UAAU;AAAA,QAC1B,IAAI,KAAK;AAAA,QACT,OAAO,KAAK;AAAA,QACZ,KAAK,IAAI,KAAK,EAAE;AAAA,QAChB,UAAU,gBAAgB,KAAK;AAAA,QAC/B,aAAa,KAAK;AAAA,QAClB,QAAQ,KAAK,YAAY,CAAC,GACvB,OAAO,CAAC,OAAO,GAAG,SAAS,UAAU,EACrC,IAAI,CAAC,aAAa;AAAA,UACjB,IAAI,QAAQ;AAAA,UACZ,OAAO,QAAQ;AAAA,UACf,KAAK,IAAI,KAAK,EAAE,IAAI,UAAU,QAAQ,GAAG,CAAC;AAAA,UAC1C,UAAU,IAAI,KAAK,EAAE,IAAI,UAAU,QAAQ,GAAG,CAAC,OAAO,IAAI,KAAK;AAAA,QACjE,EAAE;AAAA,MACN,EAAE;AAAA,IACJ,CAAC;AAAA,EACH;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["group"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/spec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"openapi3-ts": "4.4.0",
|
|
30
30
|
"yaml": "^2.7.0",
|
|
31
|
-
"stringcase": "^4.3.1"
|
|
31
|
+
"stringcase": "^4.3.1",
|
|
32
|
+
"@sdk-it/core": "0.20.0"
|
|
32
33
|
}
|
|
33
34
|
}
|