UNPKG

@autorest/openapi-to-typespec

Version:

Autorest plugin to scaffold a Typespec definition from an OpenAPI document

58 lines 3.44 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateArmResourceClientDecorator = exports.generateOperationClientDecorator = exports.generateEnumClientDecorator = exports.generateObjectClientDecorator = void 0; const pluralize_1 = __importDefault(require("pluralize")); const decorators_1 = require("../utils/decorators"); function generateObjectClientDecorator(typespecObject) { var _a; const definitions = []; definitions.push((0, decorators_1.generateAugmentedDecorators)(typespecObject.name, typespecObject.clientDecorators)); for (const property of (_a = typespecObject.properties) !== null && _a !== void 0 ? _a : []) { const decorators = (0, decorators_1.generateAugmentedDecorators)(`${typespecObject.name}.\`${property.name}\``, // TO-DO: this a workaround to add `\``, we need a better way property.clientDecorators); decorators && definitions.push(decorators); } return definitions.join("\n"); } exports.generateObjectClientDecorator = generateObjectClientDecorator; function generateEnumClientDecorator(typespecEnum) { const definitions = []; definitions.push((0, decorators_1.generateAugmentedDecorators)(typespecEnum.name, typespecEnum.clientDecorators)); for (const choice of typespecEnum.members) { const decorators = (0, decorators_1.generateAugmentedDecorators)(`${typespecEnum.name}.${choice.name}`, choice.clientDecorators); decorators && definitions.push(decorators); } return definitions.join("\n"); } exports.generateEnumClientDecorator = generateEnumClientDecorator; function generateOperationClientDecorator(operation) { const definitions = []; definitions.push((0, decorators_1.generateAugmentedDecorators)(operation.name, operation.clientDecorators)); return definitions.join("\n"); } exports.generateOperationClientDecorator = generateOperationClientDecorator; function generateArmResourceClientDecorator(resource) { const definitions = []; const formalOperationGroupName = (0, pluralize_1.default)(resource.name); const targetName = formalOperationGroupName; if (resource.clientDecorators && resource.clientDecorators.length > 0) definitions.push((0, decorators_1.generateAugmentedDecorators)(resource.name, resource.clientDecorators)); for (const op of resource.resourceOperationGroups.flatMap((g) => g.resourceOperations)) { if (op.clientDecorators && op.clientDecorators.length > 0) definitions.push((0, decorators_1.generateAugmentedDecorators)(`${targetName}.${op.name}`, op.clientDecorators)); } for (const property of resource.properties) { if (property.kind !== "property") continue; const decorators = (0, decorators_1.generateAugmentedDecorators)(`${targetName}.${property.name}`, property.clientDecorators); decorators && definitions.push(decorators); } const propertyDecorators = (0, decorators_1.generateAugmentedDecorators)(`${resource.name}.properties`, resource.propertiesPropertyClientDecorator); propertyDecorators && definitions.push(propertyDecorators); return definitions.join("\n"); } exports.generateArmResourceClientDecorator = generateArmResourceClientDecorator; //# sourceMappingURL=generate-client.js.map