@autorest/go
Version:
AutoRest Go Generator
88 lines • 4.2 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CodeModelError } from './errors.js';
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
export class CodeModel {
constructor(info, type, packageName, options) {
this.clients = new Array();
this.constants = new Array();
this.info = info;
this.interfaces = new Array();
this.models = new Array();
this.options = options;
this.packageName = packageName;
this.paramGroups = new Array();
this.responseEnvelopes = new Array();
this.type = type;
}
sortContent() {
const sortAscending = function (a, b) {
return a < b ? -1 : a > b ? 1 : 0;
};
this.constants.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const enm of this.constants) {
enm.values.sort((a, b) => { return sortAscending(a.name, b.name); });
}
this.interfaces.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const iface of this.interfaces) {
// we sort by literal value so that the switch/case statements in polymorphic_helpers.go
// are ordered by the literal value which can be somewhat different from the model name.
iface.possibleTypes.sort((a, b) => { return sortAscending(a.discriminatorValue.literal, b.discriminatorValue.literal); });
}
this.models.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const model of this.models) {
model.fields.sort((a, b) => { return sortAscending(a.name, b.name); });
}
this.paramGroups.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const paramGroup of this.paramGroups) {
paramGroup.fields.sort((a, b) => { return sortAscending(a.name, b.name); });
}
this.responseEnvelopes.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const respEnv of this.responseEnvelopes) {
respEnv.headers.sort((a, b) => { return sortAscending(a.fieldName, b.fieldName); });
}
this.clients.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const client of this.clients) {
client.methods.sort((a, b) => { return sortAscending(a.name, b.name); });
client.clientAccessors.sort((a, b) => { return sortAscending(a.name, b.name); });
for (const method of client.methods) {
method.httpStatusCodes.sort();
}
}
}
}
export class Info {
constructor(title) {
this.title = title;
}
}
export class Module {
constructor(name, version) {
if (name.match(/\/v\d+$/)) {
throw new CodeModelError('module name must not contain major version suffix');
}
if (!version.match(/^(\d+\.\d+\.\d+(?:-beta\.\d+)?)?$/)) {
throw new CodeModelError(`module version ${version} must be in the format major.minor.patch[-beta.N]`);
}
// if the module's major version is greater than one, add a major version suffix to the module name
const majorVersion = version.substring(0, version.indexOf('.'));
if (Number(majorVersion) > 1) {
name += '/v' + majorVersion;
}
this.name = name;
this.version = version;
}
}
export class Options {
constructor(headerText, generateFakes, injectSpans, disallowUnknownFields, generateExamples) {
this.headerText = headerText;
this.generateFakes = generateFakes;
this.injectSpans = injectSpans;
this.disallowUnknownFields = disallowUnknownFields;
this.generateExamples = generateExamples;
}
}
//# sourceMappingURL=package.js.map