wrekenfile-converter
Version:
Convert OpenAPI and Postman specs into Wrekenfiles, with chunking for vector database storage
71 lines • 2.31 kB
JavaScript
;
/**
* Shared utilities for processing responses in v2 converters
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateReturnVarName = generateReturnVarName;
exports.generateErrorWhen = generateErrorWhen;
/**
* Generate descriptive RETURNVAR name based on operation and response code
*/
function generateReturnVarName(operationId, code) {
const baseName = operationId.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/^_/, '');
if (code === '200') {
// For 200 OK, use operation name with _result suffix
return `${baseName}_result`;
}
else {
// For other 2xx codes (201, 202, etc.), use operation name with status code
return `${baseName}_${code}`;
}
}
/**
* Well-known HTTP status code descriptions for richer error messages
*/
const HTTP_STATUS_DESCRIPTIONS = {
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
412: 'Precondition Failed',
413: 'Payload Too Large',
415: 'Unsupported Media Type',
422: 'Unprocessable Entity',
429: 'Too Many Requests',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Timeout',
};
/**
* Generate descriptive WHEN clause for error responses with HTTP status code.
* Uses the spec description when available, falls back to well-known HTTP
* status descriptions, and finally to generic client/server error labels.
*/
function generateErrorWhen(response, code) {
const statusCode = parseInt(code);
if (response && typeof response === 'object' && response.description) {
return `${response.description} (HTTP ${code})`;
}
const knownDescription = HTTP_STATUS_DESCRIPTIONS[statusCode];
if (knownDescription) {
return `${knownDescription} (HTTP ${code})`;
}
if (statusCode >= 400 && statusCode < 500) {
return `Client error (HTTP ${code})`;
}
else if (statusCode >= 500) {
return `Server error (HTTP ${code})`;
}
else {
return `HTTP ${code}`;
}
}
//# sourceMappingURL=response-utils.js.map