UNPKG

@autorest/openapi-to-typespec

Version:

Autorest plugin to scaffold a Typespec definition from an OpenAPI document

47 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateLroHeaders = exports.hasLROExtension = exports.markLRO = void 0; const codemodel_1 = require("@autorest/codemodel"); const schemas_1 = require("./schemas"); function markLRO(codeModel) { var _a, _b; for (const operationGroup of codeModel.operationGroups) { for (const operation of operationGroup.operations) { (_a = operation.extensions) !== null && _a !== void 0 ? _a : {}; if (!hasLROExtension(operation)) { continue; } for (const response of (_b = operation.responses) !== null && _b !== void 0 ? _b : []) { if (!(0, schemas_1.isResponseSchema)(response)) { continue; } if (!(0, codemodel_1.isObjectSchema)(response.schema)) { continue; } response.schema.language.default.lro = { ...response.schema.language.default.lro, isLRO: true, }; // TODO: mark the response as an LRO } } } } exports.markLRO = markLRO; function hasLROExtension(operation) { var _a, _b; return (((_a = operation.extensions) === null || _a === void 0 ? void 0 : _a["x-ms-long-running-operation"]) || ((_b = operation.extensions) === null || _b === void 0 ? void 0 : _b["x-ms-long-running-operation-options"])); } exports.hasLROExtension = hasLROExtension; function generateLroHeaders(lroHeaders) { if (lroHeaders === "Azure-AsyncOperation") { return "ArmAsyncOperationHeader & Azure.Core.Foundations.RetryAfterHeader"; } else if (lroHeaders === "Location") { return "ArmLroLocationHeader & Azure.Core.Foundations.RetryAfterHeader"; } throw new Error(`Unknown LRO header: ${lroHeaders}`); } exports.generateLroHeaders = generateLroHeaders; //# sourceMappingURL=lro.js.map