in packages/autorest.go/src/m4togocodemodel/adapter.ts [19:99]
export async function m4ToGoCodeModel(host: AutorestExtensionHost) {
const debug = await host.getValue('debug') || false;
try {
const session = await startSession<m4.CodeModel>(host, m4.codeModelSchema);
const info = new go.Info(session.model.info.title);
const options = new go.Options(
await session.getValue('header-text', 'MISSING LICENSE HEADER'),
await session.getValue('generate-fakes', session.model.language.go!.azureARM),
await session.getValue('inject-spans', session.model.language.go!.azureARM),
await session.getValue('disallow-unknown-fields', false),
await session.getValue('generate-sdk-example', false));
const azcoreVersion = await session.getValue('azcore-version', '');
if (azcoreVersion !== '') {
options.azcoreVersion = azcoreVersion;
}
let type: go.CodeModelType = 'data-plane';
if (session.model.language.go!.azureARM) {
type = 'azure-arm';
}
const codeModel = new go.CodeModel(info, type, session.model.language.go!.packageName, options);
if (session.model.language.go!.host) {
codeModel.host = <string>session.model.language.go!.host;
}
if (session.model.language.go!.module && session.model.language.go!.moduleVersion) {
codeModel.options.module = new go.Module(session.model.language.go!.module, session.model.language.go!.moduleVersion);
} else if (session.model.language.go!.module || session.model.language.go!.moduleVersion) {
throw new Error('--module and --module-version must both or neither be set');
} else if (session.model.language.go!.containingModule !== '') {
codeModel.options.containingModule = <string>session.model.language.go!.containingModule;
}
adaptConstantTypes(session.model, codeModel);
adaptInterfaceTypes(session.model, codeModel);
adaptModels(session.model, codeModel);
adaptClients(session.model, codeModel);
const paramGroups = new Map<string, go.ParameterGroup>();
for (const client of values(codeModel.clients)) {
for (const method of client.methods) {
codeModel.responseEnvelopes.push(method.responseEnvelope);
for (const param of values(method.parameters)) {
if (param.group) {
if (!paramGroups.has(param.group.groupName)) {
paramGroups.set(param.group.groupName, param.group);
}
}
}
if (!paramGroups.has(method.optionalParamsGroup.groupName)) {
// the optional params group wasn't present, that means that it's empty.
paramGroups.set(method.optionalParamsGroup.groupName, method.optionalParamsGroup);
}
}
}
if (paramGroups.size > 0) {
// adapt all of the parameter groups
for (const groupName of paramGroups.keys()) {
const paramGroup = paramGroups.get(groupName);
codeModel.paramGroups.push(adaptParameterGroup(paramGroup!));
}
}
codeModel.sortContent();
// output the model to the pipeline
host.writeFile({
filename: 'go-code-model.yaml',
content: serialize(codeModel),
artifactType: 'go-code-model'
});
} catch (E) {
if (debug) {
console.error(`${fileURLToPath(import.meta.url)} - FAILURE ${JSON.stringify(E)} ${(<Error>E).stack}`);
}
throw E;
}
}