@dimassetoid/openapi-mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +144 -2
- package/dist/cli/update.d.ts +38 -0
- package/dist/cli/update.js +235 -0
- package/dist/engine/budget.d.ts +40 -0
- package/dist/engine/budget.js +96 -0
- package/dist/engine/example-generator.d.ts +47 -0
- package/dist/engine/example-generator.js +273 -0
- package/dist/engine/index-builder.d.ts +50 -0
- package/dist/engine/index-builder.js +155 -0
- package/dist/engine/index.d.ts +12 -0
- package/dist/engine/index.js +12 -0
- package/dist/engine/json.d.ts +1 -0
- package/dist/engine/json.js +3 -0
- package/dist/engine/lazy-expander.d.ts +37 -0
- package/dist/engine/lazy-expander.js +235 -0
- package/dist/engine/openapi-utils.d.ts +13 -0
- package/dist/engine/openapi-utils.js +48 -0
- package/dist/engine/query-sandbox.d.ts +29 -0
- package/dist/engine/query-sandbox.js +345 -0
- package/dist/engine/schema-index.d.ts +42 -0
- package/dist/engine/schema-index.js +145 -0
- package/dist/engine/source-map.d.ts +15 -0
- package/dist/engine/source-map.js +50 -0
- package/dist/engine/spec-catalog.d.ts +14 -0
- package/dist/engine/spec-catalog.js +99 -0
- package/dist/engine/spec-diagnostics.d.ts +28 -0
- package/dist/engine/spec-diagnostics.js +393 -0
- package/dist/engine/spec-diff.d.ts +32 -0
- package/dist/engine/spec-diff.js +406 -0
- package/dist/engine/spec-loader.d.ts +100 -0
- package/dist/engine/spec-loader.js +528 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +371 -0
- package/dist/mcp/prompts.d.ts +51 -0
- package/dist/mcp/prompts.js +161 -0
- package/dist/mcp/resources.d.ts +33 -0
- package/dist/mcp/resources.js +207 -0
- package/dist/mcp/server.d.ts +88 -0
- package/dist/mcp/server.js +588 -0
- package/dist/telemetry/telemetry.d.ts +90 -0
- package/dist/telemetry/telemetry.js +299 -0
- package/docs/feature/README.md +53 -0
- package/docs/feature/getting-started.md +167 -0
- package/docs/feature/index-and-prompts.md +53 -0
- package/docs/feature/openapi-query.md +53 -0
- package/docs/feature/spec-loader.md +34 -0
- package/package.json +77 -4
- package/skills/use-openapi-mcp/SKILL.md +43 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { HTTP_METHODS } from './index-builder.js';
|
|
2
|
+
import { isRecord } from './json.js';
|
|
3
|
+
import { mergeOperationParameters } from './openapi-utils.js';
|
|
4
|
+
const MAX_DIFF_CHANGES_PER_BUCKET = 250;
|
|
5
|
+
const MAX_SCHEMA_DIFF_DEPTH = 6;
|
|
6
|
+
function normalizeType(schema) {
|
|
7
|
+
if (typeof schema === 'boolean')
|
|
8
|
+
return schema ? 'any' : 'never';
|
|
9
|
+
if (!isRecord(schema))
|
|
10
|
+
return 'unknown';
|
|
11
|
+
if (typeof schema.type === 'string')
|
|
12
|
+
return schema.type;
|
|
13
|
+
if (Array.isArray(schema.type)) {
|
|
14
|
+
return schema.type.filter((t) => typeof t === 'string').sort().join('|') || 'unknown';
|
|
15
|
+
}
|
|
16
|
+
if (isRecord(schema.properties))
|
|
17
|
+
return 'object';
|
|
18
|
+
if (schema.items !== undefined)
|
|
19
|
+
return 'array';
|
|
20
|
+
if (Array.isArray(schema.oneOf))
|
|
21
|
+
return 'oneOf';
|
|
22
|
+
if (Array.isArray(schema.anyOf))
|
|
23
|
+
return 'anyOf';
|
|
24
|
+
if (Array.isArray(schema.allOf))
|
|
25
|
+
return 'allOf';
|
|
26
|
+
return 'unknown';
|
|
27
|
+
}
|
|
28
|
+
function mergeObjectShape(schema, depth = 0) {
|
|
29
|
+
const properties = new Map();
|
|
30
|
+
const required = new Set();
|
|
31
|
+
if (depth > 4 || !isRecord(schema))
|
|
32
|
+
return { properties, required };
|
|
33
|
+
if (isRecord(schema.properties)) {
|
|
34
|
+
for (const [k, v] of Object.entries(schema.properties))
|
|
35
|
+
properties.set(k, v);
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(schema.required)) {
|
|
38
|
+
for (const r of schema.required) {
|
|
39
|
+
if (typeof r === 'string')
|
|
40
|
+
required.add(r);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(schema.allOf)) {
|
|
44
|
+
for (const branch of schema.allOf) {
|
|
45
|
+
const sub = mergeObjectShape(branch, depth + 1);
|
|
46
|
+
for (const [k, v] of sub.properties)
|
|
47
|
+
properties.set(k, v);
|
|
48
|
+
for (const r of sub.required)
|
|
49
|
+
required.add(r);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { properties, required };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Semantically compares two resolved OpenAPI specifications and classifies changes into
|
|
56
|
+
* `breaking` vs `nonBreaking` using O(E + P + F) indexed lookups.
|
|
57
|
+
* Caps `breaking` and `nonBreaking` independently so non-breaking volume never starves breaking detections.
|
|
58
|
+
*/
|
|
59
|
+
export function diffOpenApiSpecs(baseSpec, targetSpec, labels) {
|
|
60
|
+
const breaking = [];
|
|
61
|
+
const nonBreaking = [];
|
|
62
|
+
let totalBreaking = 0;
|
|
63
|
+
let totalNonBreaking = 0;
|
|
64
|
+
let addedEndpoints = 0;
|
|
65
|
+
let removedEndpoints = 0;
|
|
66
|
+
let truncated = false;
|
|
67
|
+
const record = (change) => {
|
|
68
|
+
if (change.classification === 'breaking') {
|
|
69
|
+
totalBreaking++;
|
|
70
|
+
if (breaking.length < MAX_DIFF_CHANGES_PER_BUCKET) {
|
|
71
|
+
breaking.push(change);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
truncated = true;
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
totalNonBreaking++;
|
|
79
|
+
if (nonBreaking.length < MAX_DIFF_CHANGES_PER_BUCKET) {
|
|
80
|
+
nonBreaking.push(change);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
truncated = true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function diffSchemas(baseSchema, targetSchema, direction, endpoint, loc, depth) {
|
|
87
|
+
if (depth > MAX_SCHEMA_DIFF_DEPTH)
|
|
88
|
+
return;
|
|
89
|
+
if (typeof baseSchema === 'string' && baseSchema.startsWith('[Circular:'))
|
|
90
|
+
return;
|
|
91
|
+
if (typeof targetSchema === 'string' && targetSchema.startsWith('[Circular:'))
|
|
92
|
+
return;
|
|
93
|
+
const baseType = normalizeType(baseSchema);
|
|
94
|
+
const targetType = normalizeType(targetSchema);
|
|
95
|
+
if (baseType !== 'unknown' && targetType !== 'unknown' && baseType !== targetType) {
|
|
96
|
+
record({
|
|
97
|
+
classification: 'breaking',
|
|
98
|
+
code: direction === 'request' ? 'REQUEST_TYPE_CHANGED' : 'RESPONSE_TYPE_CHANGED',
|
|
99
|
+
endpoint,
|
|
100
|
+
location: loc,
|
|
101
|
+
message: `${direction} schema type at '${loc}' changed from '${baseType}' to '${targetType}'.`,
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (isRecord(baseSchema) && isRecord(targetSchema)) {
|
|
106
|
+
// Enum changes
|
|
107
|
+
if (Array.isArray(baseSchema.enum) && Array.isArray(targetSchema.enum)) {
|
|
108
|
+
const baseEnums = new Set(baseSchema.enum.map((v) => JSON.stringify(v)));
|
|
109
|
+
const targetEnums = new Set(targetSchema.enum.map((v) => JSON.stringify(v)));
|
|
110
|
+
if (direction === 'request') {
|
|
111
|
+
for (const val of baseEnums) {
|
|
112
|
+
if (!targetEnums.has(val)) {
|
|
113
|
+
record({
|
|
114
|
+
classification: 'breaking',
|
|
115
|
+
code: 'REQUEST_ENUM_VALUE_REMOVED',
|
|
116
|
+
endpoint,
|
|
117
|
+
location: loc,
|
|
118
|
+
message: `Request enum value ${val} removed at '${loc}'.`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
for (const val of targetEnums) {
|
|
125
|
+
if (!baseEnums.has(val)) {
|
|
126
|
+
record({
|
|
127
|
+
classification: 'breaking',
|
|
128
|
+
code: 'RESPONSE_ENUM_VALUE_ADDED',
|
|
129
|
+
endpoint,
|
|
130
|
+
location: loc,
|
|
131
|
+
message: `Response enum value ${val} added at '${loc}'.`,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Array items
|
|
138
|
+
if (baseType === 'array' && targetType === 'array' && baseSchema.items !== undefined && targetSchema.items !== undefined) {
|
|
139
|
+
diffSchemas(baseSchema.items, targetSchema.items, direction, endpoint, `${loc}[]`, depth + 1);
|
|
140
|
+
}
|
|
141
|
+
// Object properties & required fields
|
|
142
|
+
const baseShape = mergeObjectShape(baseSchema);
|
|
143
|
+
const targetShape = mergeObjectShape(targetSchema);
|
|
144
|
+
if (baseShape.properties.size > 0 || targetShape.properties.size > 0) {
|
|
145
|
+
for (const [prop, basePropSchema] of baseShape.properties) {
|
|
146
|
+
const propLoc = `${loc}.${prop}`;
|
|
147
|
+
if (!targetShape.properties.has(prop)) {
|
|
148
|
+
record({
|
|
149
|
+
classification: 'breaking',
|
|
150
|
+
code: direction === 'request' ? 'REQUEST_PROPERTY_REMOVED' : 'RESPONSE_PROPERTY_REMOVED',
|
|
151
|
+
endpoint,
|
|
152
|
+
location: propLoc,
|
|
153
|
+
message: `${direction} property '${prop}' removed at '${propLoc}'.`,
|
|
154
|
+
});
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const wasReq = baseShape.required.has(prop);
|
|
158
|
+
const isReq = targetShape.required.has(prop);
|
|
159
|
+
if (direction === 'request' && !wasReq && isReq) {
|
|
160
|
+
record({
|
|
161
|
+
classification: 'breaking',
|
|
162
|
+
code: 'REQUEST_PROPERTY_BECAME_REQUIRED',
|
|
163
|
+
endpoint,
|
|
164
|
+
location: propLoc,
|
|
165
|
+
message: `Request property '${prop}' changed from optional to required.`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else if (direction === 'response' && wasReq && !isReq) {
|
|
169
|
+
record({
|
|
170
|
+
classification: 'breaking',
|
|
171
|
+
code: 'RESPONSE_PROPERTY_BECAME_OPTIONAL',
|
|
172
|
+
endpoint,
|
|
173
|
+
location: propLoc,
|
|
174
|
+
message: `Response property '${prop}' changed from required to optional.`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
diffSchemas(basePropSchema, targetShape.properties.get(prop), direction, endpoint, propLoc, depth + 1);
|
|
178
|
+
}
|
|
179
|
+
for (const prop of targetShape.properties.keys()) {
|
|
180
|
+
if (baseShape.properties.has(prop))
|
|
181
|
+
continue;
|
|
182
|
+
const propLoc = `${loc}.${prop}`;
|
|
183
|
+
const isReq = targetShape.required.has(prop);
|
|
184
|
+
if (direction === 'request' && isReq) {
|
|
185
|
+
record({
|
|
186
|
+
classification: 'breaking',
|
|
187
|
+
code: 'REQUEST_REQUIRED_PROPERTY_ADDED',
|
|
188
|
+
endpoint,
|
|
189
|
+
location: propLoc,
|
|
190
|
+
message: `New required request property '${prop}' added.`,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
record({
|
|
195
|
+
classification: 'non_breaking',
|
|
196
|
+
code: direction === 'request' ? 'REQUEST_OPTIONAL_PROPERTY_ADDED' : 'RESPONSE_PROPERTY_ADDED',
|
|
197
|
+
endpoint,
|
|
198
|
+
location: propLoc,
|
|
199
|
+
message: `New ${direction} property '${prop}' added.`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const indexOperations = (spec) => {
|
|
207
|
+
const ops = new Map();
|
|
208
|
+
const paths = isRecord(spec.paths) ? spec.paths : {};
|
|
209
|
+
for (const [pathKey, pathItem] of Object.entries(paths)) {
|
|
210
|
+
if (!isRecord(pathItem))
|
|
211
|
+
continue;
|
|
212
|
+
for (const method of HTTP_METHODS) {
|
|
213
|
+
const op = pathItem[method];
|
|
214
|
+
if (!isRecord(op))
|
|
215
|
+
continue;
|
|
216
|
+
ops.set(`${method.toUpperCase()} ${pathKey}`, { pathItem, op });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return ops;
|
|
220
|
+
};
|
|
221
|
+
const baseOps = indexOperations(baseSpec);
|
|
222
|
+
const targetOps = indexOperations(targetSpec);
|
|
223
|
+
for (const [endpoint, baseEntry] of baseOps) {
|
|
224
|
+
const targetEntry = targetOps.get(endpoint);
|
|
225
|
+
if (!targetEntry) {
|
|
226
|
+
removedEndpoints++;
|
|
227
|
+
record({
|
|
228
|
+
classification: 'breaking',
|
|
229
|
+
code: 'ENDPOINT_REMOVED',
|
|
230
|
+
endpoint,
|
|
231
|
+
message: `Endpoint ${endpoint} was removed.`,
|
|
232
|
+
});
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (baseEntry.op.deprecated !== true && targetEntry.op.deprecated === true) {
|
|
236
|
+
record({
|
|
237
|
+
classification: 'non_breaking',
|
|
238
|
+
code: 'ENDPOINT_DEPRECATED',
|
|
239
|
+
endpoint,
|
|
240
|
+
message: `Endpoint ${endpoint} was marked deprecated.`,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
// Parameters
|
|
244
|
+
const baseParams = mergeOperationParameters(baseEntry.pathItem, baseEntry.op);
|
|
245
|
+
const targetParams = mergeOperationParameters(targetEntry.pathItem, targetEntry.op);
|
|
246
|
+
for (const [key, baseParam] of baseParams) {
|
|
247
|
+
const targetParam = targetParams.get(key);
|
|
248
|
+
if (!targetParam) {
|
|
249
|
+
record({
|
|
250
|
+
classification: 'breaking',
|
|
251
|
+
code: 'PARAMETER_REMOVED',
|
|
252
|
+
endpoint,
|
|
253
|
+
location: `parameters.${key}`,
|
|
254
|
+
message: `Parameter '${key}' was removed.`,
|
|
255
|
+
});
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (baseParam.required !== true && targetParam.required === true) {
|
|
259
|
+
record({
|
|
260
|
+
classification: 'breaking',
|
|
261
|
+
code: 'PARAMETER_BECAME_REQUIRED',
|
|
262
|
+
endpoint,
|
|
263
|
+
location: `parameters.${key}`,
|
|
264
|
+
message: `Parameter '${key}' became required.`,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (baseParam.schema !== undefined && targetParam.schema !== undefined) {
|
|
268
|
+
diffSchemas(baseParam.schema, targetParam.schema, 'request', endpoint, `parameters.${key}`, 0);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (const [key, targetParam] of targetParams) {
|
|
272
|
+
if (baseParams.has(key))
|
|
273
|
+
continue;
|
|
274
|
+
if (targetParam.required === true) {
|
|
275
|
+
record({
|
|
276
|
+
classification: 'breaking',
|
|
277
|
+
code: 'REQUIRED_PARAMETER_ADDED',
|
|
278
|
+
endpoint,
|
|
279
|
+
location: `parameters.${key}`,
|
|
280
|
+
message: `New required parameter '${key}' was added.`,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
record({
|
|
285
|
+
classification: 'non_breaking',
|
|
286
|
+
code: 'OPTIONAL_PARAMETER_ADDED',
|
|
287
|
+
endpoint,
|
|
288
|
+
location: `parameters.${key}`,
|
|
289
|
+
message: `New optional parameter '${key}' was added.`,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// RequestBody
|
|
294
|
+
const baseReq = isRecord(baseEntry.op.requestBody) ? baseEntry.op.requestBody : undefined;
|
|
295
|
+
const targetReq = isRecord(targetEntry.op.requestBody) ? targetEntry.op.requestBody : undefined;
|
|
296
|
+
if (baseReq?.required !== true && targetReq?.required === true) {
|
|
297
|
+
record({
|
|
298
|
+
classification: 'breaking',
|
|
299
|
+
code: 'REQUEST_BODY_BECAME_REQUIRED',
|
|
300
|
+
endpoint,
|
|
301
|
+
location: 'requestBody',
|
|
302
|
+
message: 'Request body became required.',
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
const baseReqContent = isRecord(baseReq?.content) ? baseReq.content : {};
|
|
306
|
+
const targetReqContent = isRecord(targetReq?.content) ? targetReq.content : {};
|
|
307
|
+
for (const [mediaType, baseMedia] of Object.entries(baseReqContent)) {
|
|
308
|
+
const targetMedia = targetReqContent[mediaType];
|
|
309
|
+
if (!isRecord(targetMedia)) {
|
|
310
|
+
record({
|
|
311
|
+
classification: 'breaking',
|
|
312
|
+
code: 'REQUEST_MEDIA_TYPE_REMOVED',
|
|
313
|
+
endpoint,
|
|
314
|
+
location: `requestBody.${mediaType}`,
|
|
315
|
+
message: `Request media type '${mediaType}' was removed.`,
|
|
316
|
+
});
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (isRecord(baseMedia) && baseMedia.schema !== undefined && targetMedia.schema !== undefined) {
|
|
320
|
+
diffSchemas(baseMedia.schema, targetMedia.schema, 'request', endpoint, `requestBody.${mediaType}`, 0);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
for (const mediaType of Object.keys(targetReqContent)) {
|
|
324
|
+
if (!(mediaType in baseReqContent)) {
|
|
325
|
+
record({
|
|
326
|
+
classification: 'non_breaking',
|
|
327
|
+
code: 'REQUEST_MEDIA_TYPE_ADDED',
|
|
328
|
+
endpoint,
|
|
329
|
+
location: `requestBody.${mediaType}`,
|
|
330
|
+
message: `Request media type '${mediaType}' was added.`,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// Responses
|
|
335
|
+
const baseResps = isRecord(baseEntry.op.responses) ? baseEntry.op.responses : {};
|
|
336
|
+
const targetResps = isRecord(targetEntry.op.responses) ? targetEntry.op.responses : {};
|
|
337
|
+
for (const [status, baseResp] of Object.entries(baseResps)) {
|
|
338
|
+
const targetResp = targetResps[status];
|
|
339
|
+
if (!isRecord(targetResp)) {
|
|
340
|
+
record({
|
|
341
|
+
classification: 'breaking',
|
|
342
|
+
code: 'RESPONSE_STATUS_REMOVED',
|
|
343
|
+
endpoint,
|
|
344
|
+
location: `responses.${status}`,
|
|
345
|
+
message: `Response status '${status}' was removed.`,
|
|
346
|
+
});
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const baseContent = isRecord(baseResp) && isRecord(baseResp.content) ? baseResp.content : {};
|
|
350
|
+
const targetContent = isRecord(targetResp.content) ? targetResp.content : {};
|
|
351
|
+
for (const [mediaType, baseMedia] of Object.entries(baseContent)) {
|
|
352
|
+
const targetMedia = targetContent[mediaType];
|
|
353
|
+
if (!isRecord(targetMedia)) {
|
|
354
|
+
record({
|
|
355
|
+
classification: 'breaking',
|
|
356
|
+
code: 'RESPONSE_MEDIA_TYPE_REMOVED',
|
|
357
|
+
endpoint,
|
|
358
|
+
location: `responses.${status}.${mediaType}`,
|
|
359
|
+
message: `Response media type '${mediaType}' for status '${status}' was removed.`,
|
|
360
|
+
});
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (isRecord(baseMedia) && baseMedia.schema !== undefined && targetMedia.schema !== undefined) {
|
|
364
|
+
diffSchemas(baseMedia.schema, targetMedia.schema, 'response', endpoint, `responses.${status}.${mediaType}`, 0);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
for (const status of Object.keys(targetResps)) {
|
|
369
|
+
if (!(status in baseResps)) {
|
|
370
|
+
record({
|
|
371
|
+
classification: 'non_breaking',
|
|
372
|
+
code: 'RESPONSE_STATUS_ADDED',
|
|
373
|
+
endpoint,
|
|
374
|
+
location: `responses.${status}`,
|
|
375
|
+
message: `Response status '${status}' was added.`,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
for (const endpoint of targetOps.keys()) {
|
|
381
|
+
if (!baseOps.has(endpoint)) {
|
|
382
|
+
addedEndpoints++;
|
|
383
|
+
record({
|
|
384
|
+
classification: 'non_breaking',
|
|
385
|
+
code: 'ENDPOINT_ADDED',
|
|
386
|
+
endpoint,
|
|
387
|
+
message: `Endpoint ${endpoint} was added.`,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
...(labels?.base ? { baseSpec: labels.base } : {}),
|
|
393
|
+
...(labels?.target ? { targetSpec: labels.target } : {}),
|
|
394
|
+
hasBreakingChanges: totalBreaking > 0,
|
|
395
|
+
summary: {
|
|
396
|
+
breakingCount: totalBreaking,
|
|
397
|
+
nonBreakingCount: totalNonBreaking,
|
|
398
|
+
addedEndpoints,
|
|
399
|
+
removedEndpoints,
|
|
400
|
+
totalChanges: totalBreaking + totalNonBreaking,
|
|
401
|
+
truncated,
|
|
402
|
+
},
|
|
403
|
+
breaking,
|
|
404
|
+
nonBreaking,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type SourceLocation } from './source-map.js';
|
|
2
|
+
import type { SchemaUsageRef } from './schema-index.js';
|
|
3
|
+
export declare const DEFAULT_SPEC_CANDIDATES: readonly ["openapi.yml", "openapi.yaml", "openapi.json", "api/openapi.yml", "api/openapi.yaml", "api/openapi.json", "docs/openapi.yml", "docs/openapi.yaml", "docs/openapi.json"];
|
|
4
|
+
export declare const MAX_SPEC_BYTES: number;
|
|
5
|
+
export declare const MAX_SPEC_FILES = 128;
|
|
6
|
+
export declare const MAX_DEPTH = 128;
|
|
7
|
+
export interface SpecLimits {
|
|
8
|
+
maxSpecBytes: number;
|
|
9
|
+
maxSpecFiles: number;
|
|
10
|
+
maxNodeVisits: number;
|
|
11
|
+
maxCachedSpecs: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function resolveSpecLimits(env?: NodeJS.ProcessEnv): SpecLimits;
|
|
14
|
+
export declare class MissingReferenceError extends Error {
|
|
15
|
+
readonly code = "REF_FILE_NOT_FOUND";
|
|
16
|
+
constructor(target: string, source: string);
|
|
17
|
+
}
|
|
18
|
+
export interface FileFingerprint {
|
|
19
|
+
filePath: string;
|
|
20
|
+
mtimeMs: number;
|
|
21
|
+
ctimeMs: number;
|
|
22
|
+
size: number;
|
|
23
|
+
sha256: string;
|
|
24
|
+
}
|
|
25
|
+
export interface LoadedOpenApiSpec {
|
|
26
|
+
spec: Record<string, unknown>;
|
|
27
|
+
specPath: string;
|
|
28
|
+
rootDir: string;
|
|
29
|
+
cacheKey: string;
|
|
30
|
+
fromCache: boolean;
|
|
31
|
+
dependencies: FileFingerprint[];
|
|
32
|
+
sourceLocations: Readonly<Record<string, SourceLocation>>;
|
|
33
|
+
schemaUsages: Readonly<Record<string, readonly SchemaUsageRef[]>>;
|
|
34
|
+
}
|
|
35
|
+
export interface LoadOpenApiSpecOptions {
|
|
36
|
+
specPath?: string;
|
|
37
|
+
rootDir?: string;
|
|
38
|
+
allowedRootDir?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface FileSnapshot {
|
|
41
|
+
fingerprint: FileFingerprint;
|
|
42
|
+
content: string;
|
|
43
|
+
size: number;
|
|
44
|
+
}
|
|
45
|
+
/** Serialize loader-owned snapshots once. Library callers can also supply their own data. */
|
|
46
|
+
export declare function serializeSpec(spec: unknown): string;
|
|
47
|
+
export declare function isSpecFileMissingError(error: unknown): boolean;
|
|
48
|
+
export declare function resolveSpecWorkspaceRoot(path: string): string;
|
|
49
|
+
export declare function resolveLocalSpecFile(target: string, root: string, base: string, rawRoot?: string): {
|
|
50
|
+
candidate: string;
|
|
51
|
+
canonical: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
export declare function resolveSafeSpecPath(targetPath: string, rootRealPath: string, baseDir?: string, rawRootDir?: string): string;
|
|
54
|
+
export declare function discoverSpec(root: string, rawRoot: string, explicitPath?: string): string;
|
|
55
|
+
export declare function assertWorkspaceRoot(rootInput: string, allowedRootDir?: string): string;
|
|
56
|
+
export declare function findOpenApiSpecFile(rootDir: string, explicitPath?: string): string;
|
|
57
|
+
export declare function readBoundedFileSnapshot(path: string, availableBytes: number, maxSpecBytes?: number): FileSnapshot;
|
|
58
|
+
export declare function resolveJsonPointerSafe(document: unknown, fragment: string): {
|
|
59
|
+
ok: true;
|
|
60
|
+
value: unknown;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
reason: string;
|
|
64
|
+
};
|
|
65
|
+
export declare function resolvePointer(document: unknown, fragment: string, ref: string): unknown;
|
|
66
|
+
export type ExpanderPosition = 'document' | 'named-map' | 'example-map' | 'example-object' | 'schema' | 'schema-map' | 'schema-list' | 'literal';
|
|
67
|
+
type Position = ExpanderPosition;
|
|
68
|
+
export interface SubtreeExpanderOptions {
|
|
69
|
+
root: string;
|
|
70
|
+
entry: string;
|
|
71
|
+
schema31: boolean;
|
|
72
|
+
limits: SpecLimits;
|
|
73
|
+
parseFile: (canonicalPath: string) => unknown;
|
|
74
|
+
locations: Map<string, string>;
|
|
75
|
+
schemaUsageMap?: Map<string, Map<string, SchemaUsageRef>>;
|
|
76
|
+
}
|
|
77
|
+
export declare function inferPointerPosition(pointer: string): ExpanderPosition;
|
|
78
|
+
export declare function deepFreeze<T>(value: T, seen?: WeakSet<object>): T;
|
|
79
|
+
interface OperationContext {
|
|
80
|
+
method: string;
|
|
81
|
+
path: string;
|
|
82
|
+
section?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare function createSpecNodeExpander(options: SubtreeExpanderOptions): {
|
|
85
|
+
expand: (node: unknown, file: string, pointer: string, depth: number, position: Position, opCtx?: OperationContext) => unknown;
|
|
86
|
+
getStats: () => {
|
|
87
|
+
nodeVisits: number;
|
|
88
|
+
expandedBytes: number;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Returns a bounded, immutable snapshot shared by library, index, and query consumers.
|
|
93
|
+
*/
|
|
94
|
+
export declare function loadOpenApiSpec(options?: LoadOpenApiSpecOptions): LoadedOpenApiSpec;
|
|
95
|
+
export declare function clearSpecCache(): void;
|
|
96
|
+
export declare function getSpecCacheStats(): {
|
|
97
|
+
size: number;
|
|
98
|
+
entries: string[];
|
|
99
|
+
};
|
|
100
|
+
export {};
|