@tzurp/openapi-skills 1.2.5
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 +201 -0
- package/README.md +230 -0
- package/bin/openapi-skills +4 -0
- package/dist/cli.d.ts +37 -0
- package/dist/cli.js +1646 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-schema-builder.d.ts +35 -0
- package/dist/client-schema-builder.js +268 -0
- package/dist/client-schema-builder.js.map +1 -0
- package/dist/helper/base64url-json.d.ts +3 -0
- package/dist/helper/base64url-json.js +28 -0
- package/dist/helper/base64url-json.js.map +1 -0
- package/dist/helper/dotNotation.d.ts +3 -0
- package/dist/helper/dotNotation.js +34 -0
- package/dist/helper/dotNotation.js.map +1 -0
- package/dist/helper/endpoint-filter.d.ts +16 -0
- package/dist/helper/endpoint-filter.js +165 -0
- package/dist/helper/endpoint-filter.js.map +1 -0
- package/dist/helper/endpoint-utils.d.ts +2 -0
- package/dist/helper/endpoint-utils.js +10 -0
- package/dist/helper/endpoint-utils.js.map +1 -0
- package/dist/helper/error-codes.d.ts +27 -0
- package/dist/helper/error-codes.js +116 -0
- package/dist/helper/error-codes.js.map +1 -0
- package/dist/helper/error-formatter.d.ts +46 -0
- package/dist/helper/error-formatter.js +72 -0
- package/dist/helper/error-formatter.js.map +1 -0
- package/dist/helper/get-operation-filter.d.ts +17 -0
- package/dist/helper/get-operation-filter.js +26 -0
- package/dist/helper/get-operation-filter.js.map +1 -0
- package/dist/helper/graphql.d.ts +40 -0
- package/dist/helper/graphql.js +967 -0
- package/dist/helper/graphql.js.map +1 -0
- package/dist/helper/http-client.d.ts +28 -0
- package/dist/helper/http-client.js +90 -0
- package/dist/helper/http-client.js.map +1 -0
- package/dist/helper/json-updater.d.ts +17 -0
- package/dist/helper/json-updater.js +195 -0
- package/dist/helper/json-updater.js.map +1 -0
- package/dist/helper/logger.d.ts +13 -0
- package/dist/helper/logger.js +56 -0
- package/dist/helper/logger.js.map +1 -0
- package/dist/helper/output-size.d.ts +5 -0
- package/dist/helper/output-size.js +7 -0
- package/dist/helper/output-size.js.map +1 -0
- package/dist/helper/parameter-schema.d.ts +14 -0
- package/dist/helper/parameter-schema.js +36 -0
- package/dist/helper/parameter-schema.js.map +1 -0
- package/dist/helper/paths.d.ts +11 -0
- package/dist/helper/paths.js +47 -0
- package/dist/helper/paths.js.map +1 -0
- package/dist/helper/prompt-delete.d.ts +1 -0
- package/dist/helper/prompt-delete.js +13 -0
- package/dist/helper/prompt-delete.js.map +1 -0
- package/dist/helper/request-artifacts.d.ts +14 -0
- package/dist/helper/request-artifacts.js +60 -0
- package/dist/helper/request-artifacts.js.map +1 -0
- package/dist/helper/request-preparation.d.ts +23 -0
- package/dist/helper/request-preparation.js +85 -0
- package/dist/helper/request-preparation.js.map +1 -0
- package/dist/helper/sanitizer.d.ts +1 -0
- package/dist/helper/sanitizer.js +17 -0
- package/dist/helper/sanitizer.js.map +1 -0
- package/dist/helper/update-check.d.ts +1 -0
- package/dist/helper/update-check.js +36 -0
- package/dist/helper/update-check.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +163 -0
- package/dist/index.js.map +1 -0
- package/dist/install-skill.d.ts +5 -0
- package/dist/install-skill.js +139 -0
- package/dist/install-skill.js.map +1 -0
- package/dist/parser.d.ts +12 -0
- package/dist/parser.js +393 -0
- package/dist/parser.js.map +1 -0
- package/dist/validate-response.d.ts +47 -0
- package/dist/validate-response.js +1017 -0
- package/dist/validate-response.js.map +1 -0
- package/package.json +63 -0
- package/skill-templates/SKILL.md +204 -0
- package/skill-templates/create-endpoint-test.md +413 -0
- package/skill-templates/http-client.md +141 -0
- package/skill-templates/write-client-code.md +219 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { getSchemasDir } from "./paths.js";
|
|
3
|
+
function parseClauses(value) {
|
|
4
|
+
const orGroups = value
|
|
5
|
+
.trim()
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.split("|")
|
|
8
|
+
.map(group => group.trim())
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map(group => group.split(/\s+/).filter(Boolean));
|
|
11
|
+
return { orGroups };
|
|
12
|
+
}
|
|
13
|
+
function matchesClause(text, clause) {
|
|
14
|
+
if (clause.orGroups.length === 0) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return clause.orGroups.some(group => group.every(term => text.includes(term)));
|
|
18
|
+
}
|
|
19
|
+
function normalizePathSegments(rawPath) {
|
|
20
|
+
return rawPath
|
|
21
|
+
.split("/")
|
|
22
|
+
.map(segment => segment.trim().toLowerCase())
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.flatMap(segment => {
|
|
25
|
+
if (segment.startsWith("{") && segment.endsWith("}")) {
|
|
26
|
+
const unwrapped = segment.slice(1, -1).trim();
|
|
27
|
+
return unwrapped ? [segment, unwrapped] : [segment];
|
|
28
|
+
}
|
|
29
|
+
return [segment];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function matchesPathToken(endpointPath, token) {
|
|
33
|
+
if (!token) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (token === ":param") {
|
|
37
|
+
return /\{[^/{}]+\}/.test(endpointPath);
|
|
38
|
+
}
|
|
39
|
+
if (token.startsWith("/")) {
|
|
40
|
+
return endpointPath.startsWith(token);
|
|
41
|
+
}
|
|
42
|
+
const segments = normalizePathSegments(endpointPath);
|
|
43
|
+
return segments.includes(token);
|
|
44
|
+
}
|
|
45
|
+
function matchesPathClause(endpointPath, clause) {
|
|
46
|
+
const normalizedClause = parseClauses(clause);
|
|
47
|
+
return normalizedClause.orGroups.some(group => group.every(token => matchesPathToken(endpointPath, token)));
|
|
48
|
+
}
|
|
49
|
+
function normalizePathInputs(pathInput) {
|
|
50
|
+
if (!pathInput) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
return (Array.isArray(pathInput) ? pathInput : [pathInput]).map(value => value.trim()).filter(Boolean);
|
|
54
|
+
}
|
|
55
|
+
function sliceByInclusiveRange(items, range) {
|
|
56
|
+
if (typeof range !== "string" || range.trim().length === 0 || range.trim() === ":") {
|
|
57
|
+
return items;
|
|
58
|
+
}
|
|
59
|
+
const trimmed = range.trim();
|
|
60
|
+
const singleIndexMatch = trimmed.match(/^-?\d+$/);
|
|
61
|
+
const rangeMatch = trimmed.match(/^(-?\d*)?:(-?\d*)?$/);
|
|
62
|
+
let start;
|
|
63
|
+
let end;
|
|
64
|
+
if (singleIndexMatch) {
|
|
65
|
+
start = Number(trimmed);
|
|
66
|
+
end = start;
|
|
67
|
+
}
|
|
68
|
+
else if (rangeMatch) {
|
|
69
|
+
const rawStart = rangeMatch[1];
|
|
70
|
+
const rawEnd = rangeMatch[2];
|
|
71
|
+
start = rawStart === undefined || rawStart === "" ? 0 : Number(rawStart);
|
|
72
|
+
end = rawEnd === undefined || rawEnd === "" ? items.length - 1 : Number(rawEnd);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error(`Invalid --index value: ${range}`);
|
|
76
|
+
}
|
|
77
|
+
if (Number.isNaN(start) || Number.isNaN(end)) {
|
|
78
|
+
throw new Error(`Invalid --index value: ${range}`);
|
|
79
|
+
}
|
|
80
|
+
const normalizeIndex = (index) => (index < 0 ? items.length + index : index);
|
|
81
|
+
const normalizedStart = normalizeIndex(start);
|
|
82
|
+
const normalizedEnd = normalizeIndex(end);
|
|
83
|
+
if (items.length === 0) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
const clampedStart = Math.max(0, normalizedStart);
|
|
87
|
+
const clampedEnd = Math.min(items.length - 1, normalizedEnd);
|
|
88
|
+
if (clampedStart > clampedEnd) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
return items.slice(clampedStart, clampedEnd + 1);
|
|
92
|
+
}
|
|
93
|
+
export function sliceEndpointsByIndex(items, range) {
|
|
94
|
+
return sliceByInclusiveRange(items, range);
|
|
95
|
+
}
|
|
96
|
+
export function filterEndpoints(endpoints, opts) {
|
|
97
|
+
let filtered = endpoints;
|
|
98
|
+
if (opts.operationId) {
|
|
99
|
+
const operationId = opts.operationId.toLowerCase();
|
|
100
|
+
filtered = filtered.filter(e => (e.operationId || "").toLowerCase() === operationId);
|
|
101
|
+
}
|
|
102
|
+
if (opts.method) {
|
|
103
|
+
const method = opts.method.toLowerCase();
|
|
104
|
+
filtered = filtered.filter(e => (e.method || "").toLowerCase() === method);
|
|
105
|
+
}
|
|
106
|
+
if (opts.rootType) {
|
|
107
|
+
const rootType = opts.rootType.toLowerCase();
|
|
108
|
+
filtered = filtered.filter(e => (e.rootType || "").toLowerCase() === rootType);
|
|
109
|
+
}
|
|
110
|
+
if (opts.tag) {
|
|
111
|
+
const tag = opts.tag.toLowerCase();
|
|
112
|
+
filtered = filtered.filter(endpoint => {
|
|
113
|
+
const endpointTags = Array.isArray(endpoint.tags) ? endpoint.tags : [];
|
|
114
|
+
return endpointTags.some(item => typeof item === "string" && item.toLowerCase() === tag);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const pathClauses = normalizePathInputs(opts.path);
|
|
118
|
+
if (pathClauses.length > 0) {
|
|
119
|
+
filtered = filtered.filter(endpoint => {
|
|
120
|
+
const endpointPath = (endpoint.path || "").toString().toLowerCase();
|
|
121
|
+
return pathClauses.every(clause => matchesPathClause(endpointPath, clause));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (opts.filter) {
|
|
125
|
+
const filterClause = parseClauses(opts.filter);
|
|
126
|
+
filtered = filtered.filter(ep => {
|
|
127
|
+
const fields = [ep.operationId, ep.name, ep.method, ep.rootType, ep.path, ep.summary, ep.description]
|
|
128
|
+
.map(f => (f || "").toString().toLowerCase())
|
|
129
|
+
.join(" ");
|
|
130
|
+
return matchesClause(fields, filterClause);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return filtered;
|
|
134
|
+
}
|
|
135
|
+
async function getResolvedOperationIdSet(apiName) {
|
|
136
|
+
const schemasDir = getSchemasDir(apiName);
|
|
137
|
+
try {
|
|
138
|
+
const dirents = await fs.readdir(schemasDir, { withFileTypes: true });
|
|
139
|
+
return new Set(dirents
|
|
140
|
+
.filter(dirent => dirent.isFile() && dirent.name.toLowerCase().endsWith(".json"))
|
|
141
|
+
.map(dirent => dirent.name.slice(0, -".json".length)));
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error?.code === "ENOENT") {
|
|
145
|
+
return new Set();
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export async function filterResolvedEndpoints(apiName, endpoints) {
|
|
151
|
+
const resolvedOperationIds = await getResolvedOperationIdSet(apiName);
|
|
152
|
+
if (resolvedOperationIds.size === 0) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
return endpoints.filter(endpoint => {
|
|
156
|
+
const sanitizedOperationId = typeof endpoint.sanitizedOperationId === "string"
|
|
157
|
+
? endpoint.sanitizedOperationId
|
|
158
|
+
: "";
|
|
159
|
+
return resolvedOperationIds.has(sanitizedOperationId);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export function anyEndpointMatches(endpoints, opts) {
|
|
163
|
+
return filterEndpoints(endpoints, opts).length > 0;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=endpoint-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-filter.js","sourceRoot":"","sources":["../../src/helper/endpoint-filter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAM3C,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,QAAQ,GAAG,KAAK;SACnB,IAAI,EAAE;SACN,WAAW,EAAE;SACb,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,K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AE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CACxD,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,IAAI,GAAG,EAAE,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAMD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAe,EACf,SAAqC;IAErC,MAAM,oBAAoB,GAAG,MAAM,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEtE,IAAI,oBAAoB,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;QACjC,MAAM,oBAAoB,GAAG,OAAO,QAAQ,CAAC,oBAAoB,KAAK,QAAQ;YAC5E,CAAC,CAAC,QAAQ,CAAC,oBAAoB;YAC/B,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,oBAAoB,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC;AAKD,MAAM,UAAU,kBAAkB,CAChC,SAAqC,EACrC,IAAkF;IAElF,OAAO,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { listEndpoints } from "../index.js";
|
|
2
|
+
import { filterEndpoints } from "./endpoint-filter.js";
|
|
3
|
+
export async function getSanitizedOperationId(apiName, operationId) {
|
|
4
|
+
const options = { operationId };
|
|
5
|
+
const endpoints = await listEndpoints(apiName);
|
|
6
|
+
const found = filterEndpoints(endpoints, options)[0] ?? endpoints.find((endpoint) => endpoint.name === operationId);
|
|
7
|
+
return found?.sanitizedOperationId ?? found?.operationId ?? found?.name ?? "";
|
|
8
|
+
}
|
|
9
|
+
export default getSanitizedOperationId;
|
|
10
|
+
//# sourceMappingURL=endpoint-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-utils.js","sourceRoot":"","sources":["../../src/helper/endpoint-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAAe,EAAE,WAAmB;IAChF,MAAM,OAAO,GAA6B,EAAE,WAAW,EAAE,CAAC;IAC1D,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,QAA2B,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IACvI,OAAO,KAAK,EAAE,oBAAoB,IAAI,KAAK,EAAE,WAAW,IAAI,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC;AAChF,CAAC;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum ErrorCode {
|
|
2
|
+
UNKNOWN_API = "UNKNOWN_API",
|
|
3
|
+
MISSING_FILTER_ARGUMENT = "MISSING_FILTER_ARGUMENT",
|
|
4
|
+
INVALID_FILTER_SYNTAX = "INVALID_FILTER_SYNTAX",
|
|
5
|
+
SCHEMA_TYPE_MISMATCH = "SCHEMA_TYPE_MISMATCH",
|
|
6
|
+
INVALID_VARIABLE_SYNTAX = "INVALID_VARIABLE_SYNTAX",
|
|
7
|
+
INVALID_JSON_ARGUMENT = "INVALID_JSON_ARGUMENT",
|
|
8
|
+
SCHEMA_VALIDATION_FAILED = "SCHEMA_VALIDATION_FAILED",
|
|
9
|
+
INVALID_REQUEST_UPDATE = "INVALID_REQUEST_UPDATE",
|
|
10
|
+
INVALID_UPDATE_REQUEST_JSON = "INVALID_UPDATE_REQUEST_JSON",
|
|
11
|
+
MISSING_PARSED_API = "MISSING_PARSED_API",
|
|
12
|
+
NO_ENDPOINTS_FOUND = "NO_ENDPOINTS_FOUND",
|
|
13
|
+
NO_RESPONSE_SCHEMA = "NO_RESPONSE_SCHEMA",
|
|
14
|
+
REQUEST_TEMPLATE_STALE = "REQUEST_TEMPLATE_STALE",
|
|
15
|
+
OVERSIZED_OUTPUT = "OVERSIZED_OUTPUT",
|
|
16
|
+
API_PARSE_ERROR = "API_PARSE_ERROR",
|
|
17
|
+
REQUEST_FAILED = "REQUEST_FAILED",
|
|
18
|
+
VALIDATION_FAILED = "VALIDATION_FAILED",
|
|
19
|
+
CONFIG_ERROR = "CONFIG_ERROR"
|
|
20
|
+
}
|
|
21
|
+
export type ErrorCategory = "usage" | "validation" | "configuration" | "runtime" | "state";
|
|
22
|
+
export type ErrorSeverity = "error" | "warning";
|
|
23
|
+
export declare const RemediationTemplates: Record<ErrorCode, {
|
|
24
|
+
reason: string;
|
|
25
|
+
nextCommandHint?: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const ErrorCategories: Record<ErrorCode, ErrorCategory>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export var ErrorCode;
|
|
2
|
+
(function (ErrorCode) {
|
|
3
|
+
ErrorCode["UNKNOWN_API"] = "UNKNOWN_API";
|
|
4
|
+
ErrorCode["MISSING_FILTER_ARGUMENT"] = "MISSING_FILTER_ARGUMENT";
|
|
5
|
+
ErrorCode["INVALID_FILTER_SYNTAX"] = "INVALID_FILTER_SYNTAX";
|
|
6
|
+
ErrorCode["SCHEMA_TYPE_MISMATCH"] = "SCHEMA_TYPE_MISMATCH";
|
|
7
|
+
ErrorCode["INVALID_VARIABLE_SYNTAX"] = "INVALID_VARIABLE_SYNTAX";
|
|
8
|
+
ErrorCode["INVALID_JSON_ARGUMENT"] = "INVALID_JSON_ARGUMENT";
|
|
9
|
+
ErrorCode["SCHEMA_VALIDATION_FAILED"] = "SCHEMA_VALIDATION_FAILED";
|
|
10
|
+
ErrorCode["INVALID_REQUEST_UPDATE"] = "INVALID_REQUEST_UPDATE";
|
|
11
|
+
ErrorCode["INVALID_UPDATE_REQUEST_JSON"] = "INVALID_UPDATE_REQUEST_JSON";
|
|
12
|
+
ErrorCode["MISSING_PARSED_API"] = "MISSING_PARSED_API";
|
|
13
|
+
ErrorCode["NO_ENDPOINTS_FOUND"] = "NO_ENDPOINTS_FOUND";
|
|
14
|
+
ErrorCode["NO_RESPONSE_SCHEMA"] = "NO_RESPONSE_SCHEMA";
|
|
15
|
+
ErrorCode["REQUEST_TEMPLATE_STALE"] = "REQUEST_TEMPLATE_STALE";
|
|
16
|
+
ErrorCode["OVERSIZED_OUTPUT"] = "OVERSIZED_OUTPUT";
|
|
17
|
+
ErrorCode["API_PARSE_ERROR"] = "API_PARSE_ERROR";
|
|
18
|
+
ErrorCode["REQUEST_FAILED"] = "REQUEST_FAILED";
|
|
19
|
+
ErrorCode["VALIDATION_FAILED"] = "VALIDATION_FAILED";
|
|
20
|
+
ErrorCode["CONFIG_ERROR"] = "CONFIG_ERROR";
|
|
21
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
22
|
+
export const RemediationTemplates = {
|
|
23
|
+
[ErrorCode.UNKNOWN_API]: {
|
|
24
|
+
reason: "The API name is not registered in .openapi-skills/config.json.",
|
|
25
|
+
nextCommandHint: "Run 'openapi-skills get-api-names' to list available APIs, then use the correct name.",
|
|
26
|
+
},
|
|
27
|
+
[ErrorCode.MISSING_PARSED_API]: {
|
|
28
|
+
reason: "No APIs have been parsed yet. The workspace is empty.",
|
|
29
|
+
nextCommandHint: "Run 'openapi-skills generate' with an OpenAPI or GraphQL source.",
|
|
30
|
+
},
|
|
31
|
+
[ErrorCode.NO_ENDPOINTS_FOUND]: {
|
|
32
|
+
reason: "The API endpoint file does not exist. Run generate first.",
|
|
33
|
+
nextCommandHint: "Run 'openapi-skills generate' to create endpoints.json.",
|
|
34
|
+
},
|
|
35
|
+
[ErrorCode.NO_RESPONSE_SCHEMA]: {
|
|
36
|
+
reason: "The response schema artifact has not been created yet.",
|
|
37
|
+
nextCommandHint: "Run 'openapi-skills request <operationId> --api <apiName>' to create the response-schema artifact.",
|
|
38
|
+
},
|
|
39
|
+
[ErrorCode.REQUEST_TEMPLATE_STALE]: {
|
|
40
|
+
reason: "The request template does not exist for this operation.",
|
|
41
|
+
nextCommandHint: "Run the command again with --force to regenerate the request template.",
|
|
42
|
+
},
|
|
43
|
+
[ErrorCode.SCHEMA_VALIDATION_FAILED]: {
|
|
44
|
+
reason: "The provided OpenAPI or GraphQL schema is malformed.",
|
|
45
|
+
nextCommandHint: "Fix the schema at its source and retry.",
|
|
46
|
+
},
|
|
47
|
+
[ErrorCode.INVALID_FILTER_SYNTAX]: {
|
|
48
|
+
reason: "--filter requires the target to be an array.",
|
|
49
|
+
nextCommandHint: "Use --response-schema first to inspect the response shape, then use --get to narrow the value before filtering.",
|
|
50
|
+
},
|
|
51
|
+
[ErrorCode.MISSING_FILTER_ARGUMENT]: {
|
|
52
|
+
reason: "The list command requires at least one filter to avoid returning large, unbounded result sets.",
|
|
53
|
+
nextCommandHint: "Add --path, --filter, --method, --root-type, or --index to narrow results.",
|
|
54
|
+
},
|
|
55
|
+
[ErrorCode.SCHEMA_TYPE_MISMATCH]: {
|
|
56
|
+
reason: "The flag used is incompatible with this schema type.",
|
|
57
|
+
nextCommandHint: "Use --path and --method for OpenAPI; use --root-type for GraphQL.",
|
|
58
|
+
},
|
|
59
|
+
[ErrorCode.INVALID_JSON_ARGUMENT]: {
|
|
60
|
+
reason: "The provided JSON argument is malformed.",
|
|
61
|
+
nextCommandHint: "Fix the JSON syntax and retry.",
|
|
62
|
+
},
|
|
63
|
+
[ErrorCode.INVALID_VARIABLE_SYNTAX]: {
|
|
64
|
+
reason: "Variable syntax is invalid. Expected key=value format.",
|
|
65
|
+
nextCommandHint: "Use --var key=value format.",
|
|
66
|
+
},
|
|
67
|
+
[ErrorCode.INVALID_UPDATE_REQUEST_JSON]: {
|
|
68
|
+
reason: "The --update-request JSON could not be parsed.",
|
|
69
|
+
nextCommandHint: "Fix the JSON syntax and retry.",
|
|
70
|
+
},
|
|
71
|
+
[ErrorCode.INVALID_REQUEST_UPDATE]: {
|
|
72
|
+
reason: "The request keys specified do not exist in request.json.",
|
|
73
|
+
nextCommandHint: "Use valid request.json keys. Inspect with 'openapi-skills get-operation <operationId> --api <apiName> --request' first.",
|
|
74
|
+
},
|
|
75
|
+
[ErrorCode.OVERSIZED_OUTPUT]: {
|
|
76
|
+
reason: "The output is too large to display.",
|
|
77
|
+
nextCommandHint: "Use --get or --filter to reduce output size.",
|
|
78
|
+
},
|
|
79
|
+
[ErrorCode.API_PARSE_ERROR]: {
|
|
80
|
+
reason: "An error occurred while parsing the API schema.",
|
|
81
|
+
nextCommandHint: "Review the error details and fix the schema at its source.",
|
|
82
|
+
},
|
|
83
|
+
[ErrorCode.REQUEST_FAILED]: {
|
|
84
|
+
reason: "The HTTP request failed.",
|
|
85
|
+
nextCommandHint: "Check the base URL, authentication headers, and network connectivity.",
|
|
86
|
+
},
|
|
87
|
+
[ErrorCode.VALIDATION_FAILED]: {
|
|
88
|
+
reason: "The response does not match the expected schema.",
|
|
89
|
+
nextCommandHint: "Verify that the API response matches the declared schema.",
|
|
90
|
+
},
|
|
91
|
+
[ErrorCode.CONFIG_ERROR]: {
|
|
92
|
+
reason: "Failed to read or write configuration file.",
|
|
93
|
+
nextCommandHint: "Check file permissions on .openapi-skills/config.json.",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
export const ErrorCategories = {
|
|
97
|
+
[ErrorCode.UNKNOWN_API]: "usage",
|
|
98
|
+
[ErrorCode.MISSING_FILTER_ARGUMENT]: "usage",
|
|
99
|
+
[ErrorCode.INVALID_FILTER_SYNTAX]: "usage",
|
|
100
|
+
[ErrorCode.SCHEMA_TYPE_MISMATCH]: "usage",
|
|
101
|
+
[ErrorCode.INVALID_VARIABLE_SYNTAX]: "usage",
|
|
102
|
+
[ErrorCode.INVALID_JSON_ARGUMENT]: "usage",
|
|
103
|
+
[ErrorCode.SCHEMA_VALIDATION_FAILED]: "validation",
|
|
104
|
+
[ErrorCode.INVALID_REQUEST_UPDATE]: "validation",
|
|
105
|
+
[ErrorCode.INVALID_UPDATE_REQUEST_JSON]: "validation",
|
|
106
|
+
[ErrorCode.MISSING_PARSED_API]: "state",
|
|
107
|
+
[ErrorCode.NO_ENDPOINTS_FOUND]: "state",
|
|
108
|
+
[ErrorCode.NO_RESPONSE_SCHEMA]: "state",
|
|
109
|
+
[ErrorCode.REQUEST_TEMPLATE_STALE]: "state",
|
|
110
|
+
[ErrorCode.OVERSIZED_OUTPUT]: "state",
|
|
111
|
+
[ErrorCode.API_PARSE_ERROR]: "runtime",
|
|
112
|
+
[ErrorCode.REQUEST_FAILED]: "runtime",
|
|
113
|
+
[ErrorCode.VALIDATION_FAILED]: "runtime",
|
|
114
|
+
[ErrorCode.CONFIG_ERROR]: "runtime",
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=error-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.js","sourceRoot":"","sources":["../../src/helper/error-codes.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,SA0BX;AA1BD,WAAY,SAAS;IAEnB,wCAA2B,CAAA;IAC3B,gEAAmD,CAAA;IACnD,4DAA+C,CAAA;IAC/C,0DAA6C,CAAA;IAC7C,gEAAmD,CAAA;IACnD,4DAA+C,CAAA;IAG/C,kEAAqD,CAAA;IACrD,8DAAiD,CAAA;IACjD,wEAA2D,CAAA;IAG3D,sDAAyC,CAAA;IACzC,sDAAyC,CAAA;IACzC,sDAAyC,CAAA;IACzC,8D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IAClD,CAAC,SAAS,CAAC,sBAAsB,CAAC,EAAE,YAAY;IAChD,CAAC,SAAS,CAAC,2BAA2B,CAAC,EAAE,YAAY;IAErD,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,OAAO;IACvC,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,OAAO;IACvC,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,OAAO;IACvC,CAAC,SAAS,CAAC,sBAAsB,CAAC,EAAE,OAAO;IAC3C,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,OAAO;IAErC,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,SAAS;IACtC,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,SAAS;IACrC,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,SAAS;IACxC,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,SAAS;CACpC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ErrorCode } from "./error-codes.js";
|
|
2
|
+
import type { ErrorCategory, ErrorSeverity } from "./error-codes.js";
|
|
3
|
+
export interface ResponseContext {
|
|
4
|
+
api_name?: string | null;
|
|
5
|
+
operation_id?: string | null;
|
|
6
|
+
artifact_type?: string | null;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface Remediation {
|
|
10
|
+
required: boolean;
|
|
11
|
+
next_command: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ErrorResponse {
|
|
15
|
+
ok: false;
|
|
16
|
+
error: {
|
|
17
|
+
code: ErrorCode;
|
|
18
|
+
category: ErrorCategory;
|
|
19
|
+
severity: ErrorSeverity;
|
|
20
|
+
summary: string;
|
|
21
|
+
message: string;
|
|
22
|
+
remediation: Remediation;
|
|
23
|
+
context: ResponseContext;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface SuccessResponse {
|
|
27
|
+
ok: true;
|
|
28
|
+
kind?: string;
|
|
29
|
+
data?: unknown;
|
|
30
|
+
}
|
|
31
|
+
export declare function buildError(code: ErrorCode, options: {
|
|
32
|
+
summary: string;
|
|
33
|
+
message: string;
|
|
34
|
+
nextCommand?: string;
|
|
35
|
+
reason?: string;
|
|
36
|
+
context?: ResponseContext;
|
|
37
|
+
severity?: ErrorSeverity;
|
|
38
|
+
}): ErrorResponse;
|
|
39
|
+
export declare function buildSuccess(data?: unknown, options?: {
|
|
40
|
+
kind?: string;
|
|
41
|
+
}): SuccessResponse;
|
|
42
|
+
export declare function successResult(kind: string, payload: unknown): SuccessResponse;
|
|
43
|
+
export declare function successList(items: unknown[]): unknown[];
|
|
44
|
+
export declare function remediateUnknownApi(apiName: string): Remediation;
|
|
45
|
+
export declare function remediateMissingParsedApi(source?: string): Remediation;
|
|
46
|
+
export declare function remediateNoEndpoints(apiName: string, source?: string): Remediation;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ErrorCategories, RemediationTemplates } from "./error-codes.js";
|
|
2
|
+
export function buildError(code, options) {
|
|
3
|
+
const category = ErrorCategories[code];
|
|
4
|
+
const template = RemediationTemplates[code];
|
|
5
|
+
const nextCommand = options.nextCommand ?? "None";
|
|
6
|
+
const reason = options.reason ?? template?.reason ?? "Unable to remediate automatically.";
|
|
7
|
+
const severity = options.severity ?? "error";
|
|
8
|
+
return {
|
|
9
|
+
ok: false,
|
|
10
|
+
error: {
|
|
11
|
+
code,
|
|
12
|
+
category,
|
|
13
|
+
severity,
|
|
14
|
+
summary: options.summary,
|
|
15
|
+
message: options.message,
|
|
16
|
+
remediation: {
|
|
17
|
+
required: true,
|
|
18
|
+
next_command: nextCommand,
|
|
19
|
+
reason,
|
|
20
|
+
},
|
|
21
|
+
context: options.context ?? {},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function buildSuccess(data, options) {
|
|
26
|
+
const response = {
|
|
27
|
+
ok: true,
|
|
28
|
+
data,
|
|
29
|
+
};
|
|
30
|
+
if (options?.kind !== undefined) {
|
|
31
|
+
response.kind = options.kind;
|
|
32
|
+
}
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
export function successResult(kind, payload) {
|
|
36
|
+
return {
|
|
37
|
+
ok: true,
|
|
38
|
+
kind,
|
|
39
|
+
data: payload,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function successList(items) {
|
|
43
|
+
return items;
|
|
44
|
+
}
|
|
45
|
+
export function remediateUnknownApi(apiName) {
|
|
46
|
+
return {
|
|
47
|
+
required: true,
|
|
48
|
+
next_command: "openapi-skills get-api-names",
|
|
49
|
+
reason: `API '${apiName}' is not registered. List all registered APIs and use a valid name.`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function remediateMissingParsedApi(source) {
|
|
53
|
+
const cmd = source
|
|
54
|
+
? `openapi-skills generate "${source}"`
|
|
55
|
+
: `openapi-skills generate <openapi-source>`;
|
|
56
|
+
return {
|
|
57
|
+
required: true,
|
|
58
|
+
next_command: cmd,
|
|
59
|
+
reason: "No APIs have been parsed yet. Generate an API first.",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function remediateNoEndpoints(apiName, source) {
|
|
63
|
+
const cmd = source
|
|
64
|
+
? `openapi-skills generate "${source}" --rename ${apiName}`
|
|
65
|
+
: `openapi-skills generate <openapi-source> --rename ${apiName}`;
|
|
66
|
+
return {
|
|
67
|
+
required: true,
|
|
68
|
+
next_command: cmd,
|
|
69
|
+
reason: `No endpoints.json found for API '${apiName}'. Run generate to create it.`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=error-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-formatter.js","sourceRoot":"","sources":["../../src/helper/error-formatter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAa,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAsDpF,MAAM,UAAU,UAAU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,IAAI;QACd,YAAY,EAAE,8BAA8B;QAC5C,MAAM,EAAE,QAAQ,OAAO,qEAAqE;KAC7F,CAAC;AACJ,CAAC;AAKD,MAAM,UAAU,yBAAyB,CAAC,MAAe;IACvD,MAAM,GAAG,GAAG,MAAM;QAChB,CAAC,CAAC,4BAA4B,MAAM,GAAG;QACvC,CAAC,CAAC,0CAA0C,CAAC;IAE/C,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,GAAG;QACjB,MAAM,EAAE,sDAAsD;KAC/D,CAAC;AACJ,CAAC;AAKD,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,MAAe;IACnE,MAAM,GAAG,GAAG,MAAM;QAChB,CAAC,CAAC,4BAA4B,MAAM,cAAc,OAAO,EAAE;QAC3D,CAAC,CAAC,qDAAqD,OAAO,EAAE,CAAC;IAEnE,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,GAAG;QACjB,MAAM,EAAE,oCAAoC,OAAO,+BAA+B;KACnF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type GetOperationFilterResult = {
|
|
2
|
+
kind: "count";
|
|
3
|
+
} | {
|
|
4
|
+
kind: "index";
|
|
5
|
+
index: number;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "range";
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "path";
|
|
12
|
+
path: string;
|
|
13
|
+
value: string;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "invalid";
|
|
16
|
+
};
|
|
17
|
+
export declare function parseGetOperationFilter(expr: string): GetOperationFilterResult;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function parseGetOperationFilter(expr) {
|
|
2
|
+
const trimmed = expr.trim();
|
|
3
|
+
if (trimmed === "count") {
|
|
4
|
+
return { kind: "count" };
|
|
5
|
+
}
|
|
6
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
7
|
+
return { kind: "index", index: Number(trimmed) };
|
|
8
|
+
}
|
|
9
|
+
const rangeMatch = trimmed.match(/^(-?\d*):(-?\d*)$/);
|
|
10
|
+
if (rangeMatch) {
|
|
11
|
+
return {
|
|
12
|
+
kind: "range",
|
|
13
|
+
start: rangeMatch[1] === "" ? 0 : Number(rangeMatch[1]),
|
|
14
|
+
end: rangeMatch[2] === "" ? Number.POSITIVE_INFINITY : Number(rangeMatch[2]),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const equalsIndex = trimmed.indexOf("=");
|
|
18
|
+
if (equalsIndex > 0) {
|
|
19
|
+
const path = trimmed.slice(0, equalsIndex).trim();
|
|
20
|
+
if (path) {
|
|
21
|
+
return { kind: "path", path, value: trimmed.slice(equalsIndex + 1) };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { kind: "invalid" };
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=get-operation-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-operation-filter.js","sourceRoot":"","sources":["../../src/helper/get-operation-filter.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAE5B,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACnD,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACtD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACvD,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;SAC7E,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;QAClD,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type GraphQLRootType = "query" | "mutation" | "subscription";
|
|
2
|
+
export type GraphQLTypeDescriptor = {
|
|
3
|
+
kind: "scalar" | "enum" | "object" | "input-object" | "list" | "non-null" | "unknown";
|
|
4
|
+
typeName: string;
|
|
5
|
+
fields?: Record<string, GraphQLTypeDescriptor>;
|
|
6
|
+
ofType?: GraphQLTypeDescriptor;
|
|
7
|
+
enumValues?: string[];
|
|
8
|
+
defaultValue?: unknown;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
circular?: string;
|
|
11
|
+
};
|
|
12
|
+
export type GraphQLEndpointRecord = {
|
|
13
|
+
name: string;
|
|
14
|
+
operationId: string;
|
|
15
|
+
sanitizedOperationId: string;
|
|
16
|
+
rootType: GraphQLRootType;
|
|
17
|
+
summary?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
args: Record<string, GraphQLTypeDescriptor>;
|
|
20
|
+
returns: GraphQLTypeDescriptor;
|
|
21
|
+
};
|
|
22
|
+
export type GraphQLArtifact = {
|
|
23
|
+
query: string;
|
|
24
|
+
variables: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
export declare const typescriptInstallCommand = "npm install typescript";
|
|
27
|
+
export declare function isTypeScriptUnavailableError(error: unknown): boolean;
|
|
28
|
+
export declare function looksLikeBuilderTsSchema(sourceText: string, sourcePath?: string): boolean;
|
|
29
|
+
export declare function loadSourceText(source: string): Promise<string>;
|
|
30
|
+
export declare function isGraphQL(text: string): boolean;
|
|
31
|
+
export declare function extractGraphQLEndpoints(sourceText: string, sourcePath?: string): Promise<GraphQLEndpointRecord[]>;
|
|
32
|
+
export declare function findGraphQLEndpoint(sourceText: string, rootType: GraphQLRootType, fieldName: string, sourcePath?: string): Promise<GraphQLEndpointRecord>;
|
|
33
|
+
export declare function buildGraphQLArtifact(endpoint: GraphQLEndpointRecord): GraphQLArtifact;
|
|
34
|
+
export declare function buildGraphQLOperationSchema(endpoint: GraphQLEndpointRecord): GraphQLEndpointRecord;
|
|
35
|
+
export declare function getGraphQLRootTypeFromMethod(method: string): GraphQLRootType | undefined;
|
|
36
|
+
export declare function isGraphQLTypeName(typeName: string): boolean;
|
|
37
|
+
export declare function defaultValueForDescriptor(descriptor: GraphQLTypeDescriptor): unknown;
|
|
38
|
+
export declare function typeStringForDescriptor(descriptor: GraphQLTypeDescriptor): string;
|
|
39
|
+
export declare function selectionSetForDescriptor(descriptor: GraphQLTypeDescriptor): string;
|
|
40
|
+
export declare function descriptorIsLeaf(descriptor: GraphQLTypeDescriptor): boolean;
|