mcp-openapi-schema-explorer 1.0.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/.devcontainer/devcontainer.json +24 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/ci.yml +111 -0
- package/.husky/pre-commit +6 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +12 -0
- package/.releaserc.json +23 -0
- package/CHANGELOG.md +32 -0
- package/CONTRIBUTING.md +67 -0
- package/Dockerfile +3 -0
- package/LICENSE +21 -0
- package/README.md +127 -0
- package/dist/src/config.d.ts +15 -0
- package/dist/src/config.js +19 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/handlers/component-detail-handler.d.ts +14 -0
- package/dist/src/handlers/component-detail-handler.js +87 -0
- package/dist/src/handlers/component-detail-handler.js.map +1 -0
- package/dist/src/handlers/component-map-handler.d.ts +14 -0
- package/dist/src/handlers/component-map-handler.js +63 -0
- package/dist/src/handlers/component-map-handler.js.map +1 -0
- package/dist/src/handlers/handler-utils.d.ts +69 -0
- package/dist/src/handlers/handler-utils.js +180 -0
- package/dist/src/handlers/handler-utils.js.map +1 -0
- package/dist/src/handlers/operation-handler.d.ts +14 -0
- package/dist/src/handlers/operation-handler.js +86 -0
- package/dist/src/handlers/operation-handler.js.map +1 -0
- package/dist/src/handlers/path-item-handler.d.ts +14 -0
- package/dist/src/handlers/path-item-handler.js +66 -0
- package/dist/src/handlers/path-item-handler.js.map +1 -0
- package/dist/src/handlers/top-level-field-handler.d.ts +14 -0
- package/dist/src/handlers/top-level-field-handler.js +72 -0
- package/dist/src/handlers/top-level-field-handler.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +177 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/rendering/components.d.ts +67 -0
- package/dist/src/rendering/components.js +177 -0
- package/dist/src/rendering/components.js.map +1 -0
- package/dist/src/rendering/document.d.ts +36 -0
- package/dist/src/rendering/document.js +147 -0
- package/dist/src/rendering/document.js.map +1 -0
- package/dist/src/rendering/path-item.d.ts +45 -0
- package/dist/src/rendering/path-item.js +141 -0
- package/dist/src/rendering/path-item.js.map +1 -0
- package/dist/src/rendering/paths.d.ts +26 -0
- package/dist/src/rendering/paths.js +78 -0
- package/dist/src/rendering/paths.js.map +1 -0
- package/dist/src/rendering/types.d.ts +50 -0
- package/dist/src/rendering/types.js +12 -0
- package/dist/src/rendering/types.js.map +1 -0
- package/dist/src/rendering/utils.d.ts +31 -0
- package/dist/src/rendering/utils.js +79 -0
- package/dist/src/rendering/utils.js.map +1 -0
- package/dist/src/services/formatters.d.ts +36 -0
- package/dist/src/services/formatters.js +52 -0
- package/dist/src/services/formatters.js.map +1 -0
- package/dist/src/services/reference-transform.d.ts +27 -0
- package/dist/src/services/reference-transform.js +75 -0
- package/dist/src/services/reference-transform.js.map +1 -0
- package/dist/src/services/spec-loader.d.ts +27 -0
- package/dist/src/services/spec-loader.js +77 -0
- package/dist/src/services/spec-loader.js.map +1 -0
- package/dist/src/types.d.ts +11 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/uri-builder.d.ts +81 -0
- package/dist/src/utils/uri-builder.js +121 -0
- package/dist/src/utils/uri-builder.js.map +1 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +4 -0
- package/dist/src/version.js.map +1 -0
- package/eslint.config.js +88 -0
- package/jest.config.js +32 -0
- package/justfile +66 -0
- package/memory-bank/activeContext.md +139 -0
- package/memory-bank/productContext.md +39 -0
- package/memory-bank/progress.md +141 -0
- package/memory-bank/projectbrief.md +50 -0
- package/memory-bank/systemPatterns.md +224 -0
- package/memory-bank/techContext.md +131 -0
- package/package.json +76 -0
- package/scripts/generate-version.js +49 -0
- package/src/config.ts +33 -0
- package/src/handlers/component-detail-handler.ts +121 -0
- package/src/handlers/component-map-handler.ts +92 -0
- package/src/handlers/handler-utils.ts +230 -0
- package/src/handlers/operation-handler.ts +114 -0
- package/src/handlers/path-item-handler.ts +88 -0
- package/src/handlers/top-level-field-handler.ts +92 -0
- package/src/index.ts +222 -0
- package/src/rendering/components.ts +228 -0
- package/src/rendering/document.ts +167 -0
- package/src/rendering/path-item.ts +157 -0
- package/src/rendering/paths.ts +87 -0
- package/src/rendering/types.ts +63 -0
- package/src/rendering/utils.ts +107 -0
- package/src/services/formatters.ts +71 -0
- package/src/services/reference-transform.ts +105 -0
- package/src/services/spec-loader.ts +88 -0
- package/src/types.ts +17 -0
- package/src/utils/uri-builder.ts +134 -0
- package/src/version.ts +4 -0
- package/test/__tests__/e2e/format.test.ts +224 -0
- package/test/__tests__/e2e/resources.test.ts +369 -0
- package/test/__tests__/e2e/spec-loading.test.ts +172 -0
- package/test/__tests__/unit/config.test.ts +39 -0
- package/test/__tests__/unit/handlers/component-detail-handler.test.ts +241 -0
- package/test/__tests__/unit/handlers/component-map-handler.test.ts +187 -0
- package/test/__tests__/unit/handlers/handler-utils.test.ts +255 -0
- package/test/__tests__/unit/handlers/operation-handler.test.ts +202 -0
- package/test/__tests__/unit/handlers/path-item-handler.test.ts +153 -0
- package/test/__tests__/unit/handlers/top-level-field-handler.test.ts +182 -0
- package/test/__tests__/unit/rendering/components.test.ts +269 -0
- package/test/__tests__/unit/rendering/document.test.ts +172 -0
- package/test/__tests__/unit/rendering/path-item.test.ts +197 -0
- package/test/__tests__/unit/rendering/paths.test.ts +115 -0
- package/test/__tests__/unit/services/formatters.test.ts +109 -0
- package/test/__tests__/unit/services/reference-transform.test.ts +320 -0
- package/test/__tests__/unit/services/spec-loader.test.ts +214 -0
- package/test/__tests__/unit/utils/uri-builder.test.ts +103 -0
- package/test/fixtures/complex-endpoint.json +146 -0
- package/test/fixtures/empty-api.json +8 -0
- package/test/fixtures/multi-component-types.json +55 -0
- package/test/fixtures/paths-test.json +61 -0
- package/test/fixtures/sample-api.json +68 -0
- package/test/fixtures/sample-v2-api.json +39 -0
- package/test/setup.ts +32 -0
- package/test/utils/console-helpers.ts +48 -0
- package/test/utils/mcp-test-helpers.ts +66 -0
- package/test/utils/test-types.ts +54 -0
- package/tsconfig.json +25 -0
- package/tsconfig.test.json +5 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { RenderableSpecObject, RenderContext, RenderResultItem } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps an OpenAPIV3.PathItemObject to make it renderable.
|
|
5
|
+
* Handles rendering the list of methods for a specific path and
|
|
6
|
+
* the details of specific operations (methods).
|
|
7
|
+
*/
|
|
8
|
+
export declare class RenderablePathItem implements RenderableSpecObject {
|
|
9
|
+
private pathItem;
|
|
10
|
+
private path;
|
|
11
|
+
private pathUriSuffix;
|
|
12
|
+
constructor(pathItem: OpenAPIV3.PathItemObject | undefined, path: string, // The raw, decoded path string e.g., "/users/{userId}"
|
|
13
|
+
pathUriSuffix: string);
|
|
14
|
+
/**
|
|
15
|
+
* Renders a token-efficient list of methods available for this path.
|
|
16
|
+
* Corresponds to the `openapi://paths/{path}` URI.
|
|
17
|
+
*/
|
|
18
|
+
renderList(context: RenderContext): RenderResultItem[];
|
|
19
|
+
/**
|
|
20
|
+
* Renders the detail view for one or more specific operations (methods)
|
|
21
|
+
* Renders the detail view. For a PathItem, this usually means listing
|
|
22
|
+
* the methods, similar to renderList. The handler should call
|
|
23
|
+
* `renderOperationDetail` for specific method details.
|
|
24
|
+
*/
|
|
25
|
+
renderDetail(context: RenderContext): RenderResultItem[];
|
|
26
|
+
/**
|
|
27
|
+
* Renders the detail view for one or more specific operations (methods)
|
|
28
|
+
* within this path item.
|
|
29
|
+
* Corresponds to the `openapi://paths/{path}/{method*}` URI.
|
|
30
|
+
* This is called by the handler after identifying the method(s).
|
|
31
|
+
*
|
|
32
|
+
* @param context - The rendering context.
|
|
33
|
+
* @param methods - Array of method names (e.g., ['get', 'post']).
|
|
34
|
+
* @returns An array of RenderResultItem representing the operation details.
|
|
35
|
+
*/
|
|
36
|
+
renderOperationDetail(_context: RenderContext, // Context might be needed later
|
|
37
|
+
methods: string[]): RenderResultItem[];
|
|
38
|
+
/**
|
|
39
|
+
* Gets the OperationObject for a specific HTTP method within this path item.
|
|
40
|
+
* Performs case-insensitive lookup.
|
|
41
|
+
* @param method - The HTTP method string (e.g., 'get', 'POST').
|
|
42
|
+
* @returns The OperationObject or undefined if not found.
|
|
43
|
+
*/
|
|
44
|
+
getOperation(method: string): OpenAPIV3.OperationObject | undefined;
|
|
45
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { getOperationSummary, createErrorResult, generateListHint } from './utils.js'; // Add .js
|
|
3
|
+
/**
|
|
4
|
+
* Wraps an OpenAPIV3.PathItemObject to make it renderable.
|
|
5
|
+
* Handles rendering the list of methods for a specific path and
|
|
6
|
+
* the details of specific operations (methods).
|
|
7
|
+
*/
|
|
8
|
+
export class RenderablePathItem {
|
|
9
|
+
constructor(pathItem, path, // The raw, decoded path string e.g., "/users/{userId}"
|
|
10
|
+
pathUriSuffix // Built using buildPathItemUriSuffix(path) e.g., 'paths/users%7BuserId%7D'
|
|
11
|
+
) {
|
|
12
|
+
this.pathItem = pathItem;
|
|
13
|
+
this.path = path;
|
|
14
|
+
this.pathUriSuffix = pathUriSuffix;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Renders a token-efficient list of methods available for this path.
|
|
18
|
+
* Corresponds to the `openapi://paths/{path}` URI.
|
|
19
|
+
*/
|
|
20
|
+
renderList(context) {
|
|
21
|
+
if (!this.pathItem) {
|
|
22
|
+
return createErrorResult(this.pathUriSuffix, 'Path item not found.');
|
|
23
|
+
}
|
|
24
|
+
// Correctly check if the lowercase key is one of the enum values
|
|
25
|
+
const methods = Object.keys(this.pathItem).filter(key => Object.values(OpenAPIV3.HttpMethods).includes(key.toLowerCase()));
|
|
26
|
+
// Check if methods array is empty *after* filtering
|
|
27
|
+
if (methods.length === 0) {
|
|
28
|
+
// Return a specific non-error message indicating no methods were found
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
uriSuffix: this.pathUriSuffix,
|
|
32
|
+
data: `No standard HTTP methods found for path: ${decodeURIComponent(this.pathUriSuffix.substring('paths/'.length) // Get original path for display
|
|
33
|
+
)}`,
|
|
34
|
+
renderAsList: true,
|
|
35
|
+
// isError is implicitly false here
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
// Generate hint first using the new structure
|
|
40
|
+
const hint = generateListHint(context, {
|
|
41
|
+
itemType: 'pathMethod',
|
|
42
|
+
parentPath: this.path, // Use the stored raw path
|
|
43
|
+
});
|
|
44
|
+
// Hint includes leading newline, so start output with it directly
|
|
45
|
+
let outputLines = [hint.trim(), '']; // Trim leading newline from hint for first line
|
|
46
|
+
methods.sort().forEach(method => {
|
|
47
|
+
const operation = this.getOperation(method);
|
|
48
|
+
// Use summary or operationId (via getOperationSummary)
|
|
49
|
+
const summaryText = getOperationSummary(operation);
|
|
50
|
+
// Format as METHOD: Summary or just METHOD if no summary/opId
|
|
51
|
+
outputLines.push(`${method.toUpperCase()}${summaryText ? `: ${summaryText}` : ''}`);
|
|
52
|
+
});
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
uriSuffix: this.pathUriSuffix,
|
|
56
|
+
data: outputLines.join('\n'), // Join lines into a single string
|
|
57
|
+
renderAsList: true,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Renders the detail view for one or more specific operations (methods)
|
|
63
|
+
* Renders the detail view. For a PathItem, this usually means listing
|
|
64
|
+
* the methods, similar to renderList. The handler should call
|
|
65
|
+
* `renderOperationDetail` for specific method details.
|
|
66
|
+
*/
|
|
67
|
+
renderDetail(context) {
|
|
68
|
+
// Delegate to renderList as the primary view for a path item itself.
|
|
69
|
+
return this.renderList(context);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Renders the detail view for one or more specific operations (methods)
|
|
73
|
+
* within this path item.
|
|
74
|
+
* Corresponds to the `openapi://paths/{path}/{method*}` URI.
|
|
75
|
+
* This is called by the handler after identifying the method(s).
|
|
76
|
+
*
|
|
77
|
+
* @param context - The rendering context.
|
|
78
|
+
* @param methods - Array of method names (e.g., ['get', 'post']).
|
|
79
|
+
* @returns An array of RenderResultItem representing the operation details.
|
|
80
|
+
*/
|
|
81
|
+
renderOperationDetail(_context, // Context might be needed later
|
|
82
|
+
methods) {
|
|
83
|
+
if (!this.pathItem) {
|
|
84
|
+
// Create error results for all requested methods if path item is missing
|
|
85
|
+
return methods.map(method => ({
|
|
86
|
+
uriSuffix: `${this.pathUriSuffix}/${method}`,
|
|
87
|
+
data: null,
|
|
88
|
+
isError: true,
|
|
89
|
+
errorText: 'Path item not found.',
|
|
90
|
+
renderAsList: true,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
const results = [];
|
|
94
|
+
for (const method of methods) {
|
|
95
|
+
const operation = this.getOperation(method);
|
|
96
|
+
const operationUriSuffix = `${this.pathUriSuffix}/${method}`;
|
|
97
|
+
if (!operation) {
|
|
98
|
+
results.push({
|
|
99
|
+
uriSuffix: operationUriSuffix,
|
|
100
|
+
data: null,
|
|
101
|
+
isError: true,
|
|
102
|
+
errorText: `Method "${method.toUpperCase()}" not found for path.`,
|
|
103
|
+
renderAsList: true,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Return the raw operation object; handler will format it
|
|
108
|
+
results.push({
|
|
109
|
+
uriSuffix: operationUriSuffix,
|
|
110
|
+
data: operation,
|
|
111
|
+
// isError: false (default)
|
|
112
|
+
// renderAsList: false (default)
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return results;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets the OperationObject for a specific HTTP method within this path item.
|
|
120
|
+
* Performs case-insensitive lookup.
|
|
121
|
+
* @param method - The HTTP method string (e.g., 'get', 'POST').
|
|
122
|
+
* @returns The OperationObject or undefined if not found.
|
|
123
|
+
*/
|
|
124
|
+
getOperation(method) {
|
|
125
|
+
if (!this.pathItem) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
const lowerMethod = method.toLowerCase();
|
|
129
|
+
// Check if the key is a standard HTTP method defined in the enum
|
|
130
|
+
if (Object.values(OpenAPIV3.HttpMethods).includes(lowerMethod)) {
|
|
131
|
+
const operation = this.pathItem[lowerMethod];
|
|
132
|
+
// Basic check to ensure it looks like an operation object
|
|
133
|
+
if (typeof operation === 'object' && operation !== null && 'responses' in operation) {
|
|
134
|
+
// The check above narrows the type sufficiently, assertion is redundant
|
|
135
|
+
return operation;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return undefined; // Not a valid method or not an operation object
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=path-item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-item.js","sourceRoot":"","sources":["../../../src/rendering/path-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC,CAAC,UAAU;AAEjG;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAC7B,YACU,QAA8C,EAC9C,IAAY,EAAE,uDAAuD;IACrE,aAAqB,CAAC,2EAA2E;;QAFjG,aAAQ,GAAR,QAAQ,CAAsC;QAC9C,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;IAC5B,CAAC;IAEJ;;;OAGG;IACH,UAAU,CAAC,OAAsB;QAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,iBAAiB,CAAC,IAAI,CAAC,aAAa,EAAE,sBAAsB,CAA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;gBACN,0DAA0D;gBAC1D,OAAO,CAAC,IAAI,CAAC;oBACX,SAAS,EAAE,kBAAkB;oBAC7B,IAAI,EAAE,SAAS;oBACf,2BAA2B;oBAC3B,gCAAgC;iBACjC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,MAAc;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QAEzC,iEAAiE;QACjE,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,WAAoC,CAAC,EAAE,CAAC;YACxF,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,WAA6C,CAAC,CAAC;YAC/E,0DAA0D;YAC1D,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,IAAI,WAAW,IAAI,SAAS,EAAE,CAAC;gBACpF,wEAAwE;gBACxE,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC,CAAC,gDAAgD;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { RenderableSpecObject, RenderContext, RenderResultItem } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps an OpenAPIV3.PathsObject to make it renderable.
|
|
5
|
+
* Handles rendering the list of all paths and methods.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RenderablePaths implements RenderableSpecObject {
|
|
8
|
+
private paths;
|
|
9
|
+
constructor(paths: OpenAPIV3.PathsObject | undefined);
|
|
10
|
+
/**
|
|
11
|
+
* Renders a token-efficient list of all paths and their methods.
|
|
12
|
+
* Corresponds to the `openapi://paths` URI.
|
|
13
|
+
*/
|
|
14
|
+
renderList(context: RenderContext): RenderResultItem[];
|
|
15
|
+
/**
|
|
16
|
+
* Renders the detail view. For the Paths object level, this isn't
|
|
17
|
+
* typically used directly. Details are requested per path or operation.
|
|
18
|
+
*/
|
|
19
|
+
renderDetail(context: RenderContext): RenderResultItem[];
|
|
20
|
+
/**
|
|
21
|
+
* Gets the PathItemObject for a specific path.
|
|
22
|
+
* @param path - The decoded path string.
|
|
23
|
+
* @returns The PathItemObject or undefined if not found.
|
|
24
|
+
*/
|
|
25
|
+
getPathItem(path: string): OpenAPIV3.PathItemObject | undefined;
|
|
26
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps an OpenAPIV3.PathsObject to make it renderable.
|
|
4
|
+
* Handles rendering the list of all paths and methods.
|
|
5
|
+
*/
|
|
6
|
+
export class RenderablePaths {
|
|
7
|
+
constructor(paths) {
|
|
8
|
+
this.paths = paths;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Renders a token-efficient list of all paths and their methods.
|
|
12
|
+
* Corresponds to the `openapi://paths` URI.
|
|
13
|
+
*/
|
|
14
|
+
renderList(context) {
|
|
15
|
+
if (!this.paths || Object.keys(this.paths).length === 0) {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
uriSuffix: 'paths',
|
|
19
|
+
data: 'No paths found in the specification.',
|
|
20
|
+
renderAsList: true,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
// Generate hint first and prepend "Hint: "
|
|
25
|
+
const hintText = `Use '${context.baseUri}paths/{encoded_path}' to list methods for a specific path, or '${context.baseUri}paths/{encoded_path}/{method}' to view details for a specific operation.`;
|
|
26
|
+
let outputLines = [`Hint: ${hintText}`, '']; // Start with hint and a blank line
|
|
27
|
+
const pathEntries = Object.entries(this.paths).sort(([pathA], [pathB]) => pathA.localeCompare(pathB));
|
|
28
|
+
for (const [path, pathItem] of pathEntries) {
|
|
29
|
+
if (!pathItem)
|
|
30
|
+
continue;
|
|
31
|
+
// Create a list of valid, sorted, uppercase methods for the current path
|
|
32
|
+
const methods = [];
|
|
33
|
+
for (const key in pathItem) {
|
|
34
|
+
const lowerKey = key.toLowerCase();
|
|
35
|
+
if (Object.values(OpenAPIV3.HttpMethods).includes(lowerKey)) {
|
|
36
|
+
// Check if it's a valid operation object before adding the method
|
|
37
|
+
const operation = pathItem[key];
|
|
38
|
+
if (typeof operation === 'object' && operation !== null && 'responses' in operation) {
|
|
39
|
+
methods.push(lowerKey.toUpperCase());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
methods.sort(); // Sort methods alphabetically
|
|
44
|
+
// Format the line: METHODS /path
|
|
45
|
+
const methodsString = methods.length > 0 ? methods.join(' ') : '(No methods)';
|
|
46
|
+
outputLines.push(`${methodsString} ${path}`);
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
uriSuffix: 'paths',
|
|
51
|
+
data: outputLines.join('\n'), // Join lines into a single string
|
|
52
|
+
renderAsList: true, // This result is always plain text
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Renders the detail view. For the Paths object level, this isn't
|
|
58
|
+
* typically used directly. Details are requested per path or operation.
|
|
59
|
+
*/
|
|
60
|
+
renderDetail(context) {
|
|
61
|
+
// Delegate to renderList as the primary view for the collection of paths
|
|
62
|
+
return this.renderList(context);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets the PathItemObject for a specific path.
|
|
66
|
+
* @param path - The decoded path string.
|
|
67
|
+
* @returns The PathItemObject or undefined if not found.
|
|
68
|
+
*/
|
|
69
|
+
getPathItem(path) {
|
|
70
|
+
// Use Map for safe access
|
|
71
|
+
if (!this.paths) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const pathsMap = new Map(Object.entries(this.paths));
|
|
75
|
+
return pathsMap.get(path); // Map.get returns ValueType | undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/rendering/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C;;;GAGG;AACH,MAAM,OAAO,eAAe;IAC1B,YAAoB,KAAwC;QAAxC,UAAK,GAAL,KAAK,CAAmC;IAAG,CAAC;IAEhE;;;OAGG;IACH,UAAU,CAAC,OAAsB;QAC/B,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO;gBACL;oBACE,SAAS,EAAE,OAAO;oBAClB,IAAI,EAAE,sCAAsC;oBAC5C,YAAY,EAAE,IAAI;iBACnB;aACF,CAAC;QACJ,CAAC;QAED,2CAA2C;QAC3C,MAAM,QAAQ,GAAG,QAAQ,OAAO,CAAC,OAAO,kEAAkE,OAAO,CAAC,OAAO,0EAA0E,CAAC;QACpM,IAAI,WAAW,GAAa,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,mCAAmC;QAE1F,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,CACvE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAC3B,CAAC;QAEF,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC;YAC3C,IAAI,CAAC,QAAQ;gBAAE,SAAS;YAExB,yEAAyE;YACzE,MAAM,OAAO,GAA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,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,wCAAwC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { IFormatter } from '../services/formatters';
|
|
2
|
+
/**
|
|
3
|
+
* Intermediate result structure returned by render methods.
|
|
4
|
+
* Contains the core data needed to build the final ResourceContent.
|
|
5
|
+
*/
|
|
6
|
+
export interface RenderResultItem {
|
|
7
|
+
/** The raw data object to be formatted. */
|
|
8
|
+
data: unknown;
|
|
9
|
+
/** The suffix to append to the base URI (e.g., 'info', 'paths/users', 'components/schemas/User'). */
|
|
10
|
+
uriSuffix: string;
|
|
11
|
+
/** Optional flag indicating an error for this specific item. */
|
|
12
|
+
isError?: boolean;
|
|
13
|
+
/** Optional error message if isError is true. */
|
|
14
|
+
errorText?: string;
|
|
15
|
+
/** Optional flag to indicate this should be rendered as a list (text/plain). */
|
|
16
|
+
renderAsList?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Context required for rendering OpenAPI specification objects.
|
|
20
|
+
*/
|
|
21
|
+
export interface RenderContext {
|
|
22
|
+
/** Formatter instance for handling output (JSON/YAML). */
|
|
23
|
+
formatter: IFormatter;
|
|
24
|
+
/** Base URI for generating resource links (e.g., "openapi://"). */
|
|
25
|
+
baseUri: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents an OpenAPI specification object that can be rendered
|
|
29
|
+
* in different formats (list or detail).
|
|
30
|
+
*/
|
|
31
|
+
export interface RenderableSpecObject {
|
|
32
|
+
/**
|
|
33
|
+
* Generates data for a token-efficient list representation.
|
|
34
|
+
* @param context - The rendering context.
|
|
35
|
+
* @returns An array of RenderResultItem.
|
|
36
|
+
*/
|
|
37
|
+
renderList(context: RenderContext): RenderResultItem[];
|
|
38
|
+
/**
|
|
39
|
+
* Generates data for a detailed representation.
|
|
40
|
+
* @param context - The rendering context.
|
|
41
|
+
* @returns An array of RenderResultItem.
|
|
42
|
+
*/
|
|
43
|
+
renderDetail(context: RenderContext): RenderResultItem[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to check if an object implements RenderableSpecObject.
|
|
47
|
+
* @param obj - The object to check.
|
|
48
|
+
* @returns True if the object implements RenderableSpecObject, false otherwise.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isRenderableSpecObject(obj: unknown): obj is RenderableSpecObject;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if an object implements RenderableSpecObject.
|
|
3
|
+
* @param obj - The object to check.
|
|
4
|
+
* @returns True if the object implements RenderableSpecObject, false otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export function isRenderableSpecObject(obj) {
|
|
7
|
+
return (typeof obj === 'object' &&
|
|
8
|
+
obj !== null &&
|
|
9
|
+
typeof obj.renderList === 'function' &&
|
|
10
|
+
typeof obj.renderDetail === 'function');
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/rendering/types.ts"],"names":[],"mappings":"AAkDA;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAY;IACjD,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,OAAQ,GAA4B,CAAC,UAAU,KAAK,UAAU;QAC9D,OAAQ,GAA4B,CAAC,YAAY,KAAK,UAAU,CACjE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { RenderContext, RenderResultItem } from './types.js';
|
|
3
|
+
type ListItemType = 'componentType' | 'componentName' | 'pathMethod';
|
|
4
|
+
interface HintContext {
|
|
5
|
+
itemType: ListItemType;
|
|
6
|
+
parentComponentType?: string;
|
|
7
|
+
parentPath?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Safely retrieves the summary from an Operation object.
|
|
11
|
+
* Handles cases where the operation might be undefined or lack a summary.
|
|
12
|
+
*
|
|
13
|
+
* @param operation - The Operation object or undefined.
|
|
14
|
+
* @returns The operation summary or operationId string, truncated if necessary, or null if neither is available.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getOperationSummary(operation: OpenAPIV3.OperationObject | undefined): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Helper to generate a standard hint text for list views, using the centralized URI builders.
|
|
19
|
+
* @param renderContext - The rendering context containing the base URI.
|
|
20
|
+
* @param hintContext - Context about the type of items being listed and their parent context.
|
|
21
|
+
* @returns The hint string.
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateListHint(renderContext: RenderContext, hintContext: HintContext): string;
|
|
24
|
+
/**
|
|
25
|
+
* Helper to generate a standard error item for RenderResultItem arrays.
|
|
26
|
+
* @param uriSuffix - The URI suffix for the error context.
|
|
27
|
+
* @param message - The error message.
|
|
28
|
+
* @returns A RenderResultItem array containing the error.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createErrorResult(uriSuffix: string, message: string): RenderResultItem[];
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { buildComponentDetailUriSuffix, buildComponentMapUriSuffix, buildOperationUriSuffix,
|
|
2
|
+
// buildPathItemUriSuffix, // Not currently used by generateListHint
|
|
3
|
+
} from '../utils/uri-builder.js'; // Added .js extension
|
|
4
|
+
/**
|
|
5
|
+
* Safely retrieves the summary from an Operation object.
|
|
6
|
+
* Handles cases where the operation might be undefined or lack a summary.
|
|
7
|
+
*
|
|
8
|
+
* @param operation - The Operation object or undefined.
|
|
9
|
+
* @returns The operation summary or operationId string, truncated if necessary, or null if neither is available.
|
|
10
|
+
*/
|
|
11
|
+
export function getOperationSummary(operation) {
|
|
12
|
+
// Return summary or operationId without truncation
|
|
13
|
+
return operation?.summary || operation?.operationId || null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Helper to generate a standard hint text for list views, using the centralized URI builders.
|
|
17
|
+
* @param renderContext - The rendering context containing the base URI.
|
|
18
|
+
* @param hintContext - Context about the type of items being listed and their parent context.
|
|
19
|
+
* @returns The hint string.
|
|
20
|
+
*/
|
|
21
|
+
export function generateListHint(renderContext, hintContext) {
|
|
22
|
+
let detailUriSuffixPattern;
|
|
23
|
+
let itemTypeName; // User-friendly name for the item type in the hint text
|
|
24
|
+
switch (hintContext.itemType) {
|
|
25
|
+
case 'componentType':
|
|
26
|
+
// Listing component types (e.g., schemas, responses) at openapi://components
|
|
27
|
+
// Hint should point to openapi://components/{type}
|
|
28
|
+
detailUriSuffixPattern = buildComponentMapUriSuffix('{type}'); // Use placeholder
|
|
29
|
+
itemTypeName = 'component type';
|
|
30
|
+
break;
|
|
31
|
+
case 'componentName':
|
|
32
|
+
// Listing component names (e.g., MySchema, User) at openapi://components/{type}
|
|
33
|
+
// Hint should point to openapi://components/{type}/{name}
|
|
34
|
+
if (!hintContext.parentComponentType) {
|
|
35
|
+
console.warn('generateListHint called for componentName without parentComponentType');
|
|
36
|
+
return ''; // Avoid generating a broken hint
|
|
37
|
+
}
|
|
38
|
+
// Use the actual parent type and a placeholder for the name
|
|
39
|
+
detailUriSuffixPattern = buildComponentDetailUriSuffix(hintContext.parentComponentType, '{name}');
|
|
40
|
+
itemTypeName = hintContext.parentComponentType.slice(0, -1); // e.g., 'schema' from 'schemas'
|
|
41
|
+
break;
|
|
42
|
+
case 'pathMethod':
|
|
43
|
+
// Listing methods (e.g., get, post) at openapi://paths/{path}
|
|
44
|
+
// Hint should point to openapi://paths/{path}/{method}
|
|
45
|
+
if (!hintContext.parentPath) {
|
|
46
|
+
console.warn('generateListHint called for pathMethod without parentPath');
|
|
47
|
+
return ''; // Avoid generating a broken hint
|
|
48
|
+
}
|
|
49
|
+
// Use the actual parent path and a placeholder for the method
|
|
50
|
+
detailUriSuffixPattern = buildOperationUriSuffix(hintContext.parentPath, '{method}');
|
|
51
|
+
itemTypeName = 'operation'; // Or 'method'? 'operation' seems clearer
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
// Explicitly cast to string to avoid potential 'never' type issue in template literal
|
|
55
|
+
console.warn(`Unknown itemType in generateListHint: ${String(hintContext.itemType)}`);
|
|
56
|
+
return ''; // Avoid generating a hint if context is unknown
|
|
57
|
+
}
|
|
58
|
+
// Construct the full hint URI pattern using the base URI
|
|
59
|
+
const fullHintPattern = `${renderContext.baseUri}${detailUriSuffixPattern}`;
|
|
60
|
+
return `\nHint: Use '${fullHintPattern}' to view details for a specific ${itemTypeName}.`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Helper to generate a standard error item for RenderResultItem arrays.
|
|
64
|
+
* @param uriSuffix - The URI suffix for the error context.
|
|
65
|
+
* @param message - The error message.
|
|
66
|
+
* @returns A RenderResultItem array containing the error.
|
|
67
|
+
*/
|
|
68
|
+
export function createErrorResult(uriSuffix, message) {
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
uriSuffix: uriSuffix,
|
|
72
|
+
data: null,
|
|
73
|
+
isError: true,
|
|
74
|
+
errorText: message,
|
|
75
|
+
renderAsList: true, // Errors are typically plain text
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/rendering/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,uBAAuB;AACvB,oEAAoE;EACrE,MAAM,yBAAyB,CAAC,CAAC,sBAAsB;AAcxD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAgD;IAEhD,mDAAmD;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,CAAC,yCAAyC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACtF,OAAO,EAAE,CAAC,CAAC,gDAAgD;IAC/D,CAAC;IAED,yDAAyD;IACzD,MAAM,eAAe,GAAG,GAAG,aAAa,CAAC,OAAO,GAAG,sBAAsB,EAAE,CAAC;IAE5E,OAAO,gBAAgB,eAAe,oCAAoC,YAAY,GAAG,CAAC;AAC5F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,OAAe;IAClE,OAAO;QACL;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,OAAO;YAClB,YAAY,EAAE,IAAI,EAAE,kCAAkC;SACvD;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported output formats
|
|
3
|
+
*/
|
|
4
|
+
export type OutputFormat = 'json' | 'yaml' | 'json-minified';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for formatters that handle different output formats
|
|
7
|
+
*/
|
|
8
|
+
export interface IFormatter {
|
|
9
|
+
format(data: unknown): string;
|
|
10
|
+
getMimeType(): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* JSON formatter with pretty printing
|
|
14
|
+
*/
|
|
15
|
+
export declare class JsonFormatter implements IFormatter {
|
|
16
|
+
format(data: unknown): string;
|
|
17
|
+
getMimeType(): string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Formats data as minified JSON.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MinifiedJsonFormatter implements IFormatter {
|
|
23
|
+
format(data: unknown): string;
|
|
24
|
+
getMimeType(): string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* YAML formatter using js-yaml library
|
|
28
|
+
*/
|
|
29
|
+
export declare class YamlFormatter implements IFormatter {
|
|
30
|
+
format(data: unknown): string;
|
|
31
|
+
getMimeType(): string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a formatter instance based on format name
|
|
35
|
+
*/
|
|
36
|
+
export declare function createFormatter(format: OutputFormat): IFormatter;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { dump as yamlDump } from 'js-yaml';
|
|
2
|
+
/**
|
|
3
|
+
* JSON formatter with pretty printing
|
|
4
|
+
*/
|
|
5
|
+
export class JsonFormatter {
|
|
6
|
+
format(data) {
|
|
7
|
+
return JSON.stringify(data, null, 2);
|
|
8
|
+
}
|
|
9
|
+
getMimeType() {
|
|
10
|
+
return 'application/json';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Formats data as minified JSON.
|
|
15
|
+
*/
|
|
16
|
+
export class MinifiedJsonFormatter {
|
|
17
|
+
format(data) {
|
|
18
|
+
return JSON.stringify(data);
|
|
19
|
+
}
|
|
20
|
+
getMimeType() {
|
|
21
|
+
return 'application/json';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* YAML formatter using js-yaml library
|
|
26
|
+
*/
|
|
27
|
+
export class YamlFormatter {
|
|
28
|
+
format(data) {
|
|
29
|
+
return yamlDump(data, {
|
|
30
|
+
indent: 2,
|
|
31
|
+
lineWidth: -1, // Don't wrap long lines
|
|
32
|
+
noRefs: true, // Don't use references
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getMimeType() {
|
|
36
|
+
return 'text/yaml';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a formatter instance based on format name
|
|
41
|
+
*/
|
|
42
|
+
export function createFormatter(format) {
|
|
43
|
+
switch (format) {
|
|
44
|
+
case 'json':
|
|
45
|
+
return new JsonFormatter();
|
|
46
|
+
case 'yaml':
|
|
47
|
+
return new YamlFormatter();
|
|
48
|
+
case 'json-minified':
|
|
49
|
+
return new MinifiedJsonFormatter();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../../src/services/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,SAAS,CAAC;AAe3C;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,IAAa;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,WAAW;QACT,OAAO,kBAAkB,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAChC,MAAM,CAAC,IAAa;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,WAAW;QACT,OAAO,kBAAkB,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,IAAa;QAClB,OAAO,QAAQ,CAAC,IAAI,EAAE;YACpB,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,CAAC,CAAC,EAAE,wBAAwB;YACvC,MAAM,EAAE,IAAI,EAAE,uBAAuB;SACtC,CAAC,CAAC;IACL,CAAC;IAED,WAAW;QACT,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAoB;IAClD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,IAAI,aAAa,EAAE,CAAC;QAC7B,KAAK,MAAM;YACT,OAAO,IAAI,aAAa,EAAE,CAAC;QAC7B,KAAK,eAAe;YAClB,OAAO,IAAI,qBAAqB,EAAE,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
export interface TransformContext {
|
|
3
|
+
resourceType: 'endpoint' | 'schema';
|
|
4
|
+
format: 'openapi' | 'asyncapi' | 'graphql';
|
|
5
|
+
path?: string;
|
|
6
|
+
method?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ReferenceObject {
|
|
9
|
+
$ref: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TransformedReference {
|
|
12
|
+
$ref: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ReferenceTransform<T> {
|
|
15
|
+
transformRefs(document: T, context: TransformContext): T;
|
|
16
|
+
}
|
|
17
|
+
export declare class ReferenceTransformService {
|
|
18
|
+
private transformers;
|
|
19
|
+
registerTransformer<T>(format: string, transformer: ReferenceTransform<T>): void;
|
|
20
|
+
transformDocument<T>(document: T, context: TransformContext): T;
|
|
21
|
+
}
|
|
22
|
+
export declare class OpenAPITransformer implements ReferenceTransform<OpenAPIV3.Document> {
|
|
23
|
+
private transformObject;
|
|
24
|
+
private isReferenceObject;
|
|
25
|
+
private transformReference;
|
|
26
|
+
transformRefs(document: OpenAPIV3.Document, context: TransformContext): OpenAPIV3.Document;
|
|
27
|
+
}
|