UNPKG

@autorest/openapi-to-typespec

Version:

Autorest plugin to scaffold a Typespec definition from an OpenAPI document

65 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateObjectClientDecorator = generateObjectClientDecorator; exports.generateEnumClientDecorator = generateEnumClientDecorator; exports.generateOperationClientDecorator = generateOperationClientDecorator; exports.generateOperationGroupClientDecorator = generateOperationGroupClientDecorator; exports.generateArmResourceClientDecorator = generateArmResourceClientDecorator; 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"); } 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"); } function generateOperationClientDecorator(operation) { const definitions = []; definitions.push((0, decorators_1.generateAugmentedDecorators)(operation.name, operation.clientDecorators)); return definitions.join("\n"); } function generateOperationGroupClientDecorator(operationGroup) { const definitions = []; definitions.push((0, decorators_1.generateAugmentedDecorators)(operationGroup.name, operationGroup.clientDecorators)); for (const operation of operationGroup.operations) { const decorators = (0, decorators_1.generateAugmentedDecorators)(`${operationGroup.name ? `${operationGroup.name}.` : ""}${operation.name}`, operation.clientDecorators); decorators && definitions.push(decorators); } return definitions.join("\n"); } function generateArmResourceClientDecorator(resource) { const definitions = []; if (resource.clientDecorators && resource.clientDecorators.length > 0) definitions.push((0, decorators_1.generateAugmentedDecorators)(resource.name, resource.clientDecorators)); for (const group of resource.resourceOperationGroups) { const interfaceName = group.interfaceName; for (const op of group.resourceOperations) { if (op.clientDecorators && op.clientDecorators.length > 0) { definitions.push((0, decorators_1.generateAugmentedDecorators)(`${interfaceName}.${op.name}`, op.clientDecorators)); } } } for (const property of resource.properties) { if (property.kind !== "property") continue; const decorators = (0, decorators_1.generateAugmentedDecorators)(`${resource.name}.${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"); } //# sourceMappingURL=generate-client.js.map