UNPKG

@autorest/go

Version:
47 lines 2.68 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { comment } from '@azure-tools/codegen'; import { contentPreamble, sortAscending } from './helpers.js'; // Creates the content in interfaces.go export function generateInterfaces(codeModel) { return __awaiter(this, void 0, void 0, function* () { if (codeModel.interfaceTypes.length === 0) { // no polymorphic types return ''; } let text = contentPreamble(codeModel); for (const iface of codeModel.interfaceTypes) { const methodName = `Get${iface.rootType.name}`; text += `// ${iface.name} provides polymorphic access to related types.\n`; text += `// Call the interface's ${methodName}() method to access the common type.\n`; text += '// Use a type switch to determine the concrete type. The possible types are:\n'; const possibleTypeNames = new Array(); possibleTypeNames.push(`*${iface.rootType.name}`); for (const possibleType of iface.possibleTypes) { possibleTypeNames.push(`*${possibleType.name}`); } possibleTypeNames.sort(sortAscending); text += comment(possibleTypeNames.join(', '), '// - '); text += `\ntype ${iface.name} interface {\n`; if (iface.parent) { text += `\t${iface.parent.name}\n`; } text += `\t// ${methodName} returns the ${iface.rootType.name} content of the underlying type.\n`; text += `\t${methodName}() *${iface.rootType.name}\n`; text += '}\n\n'; } return text; }); } //# sourceMappingURL=interfaces.js.map