@autorest/go
Version:
AutoRest Go Generator
168 lines • 5.81 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';
import * as method from './method.js';
import * as type from './type.js';
/**
* returns true if the provided parameter is for the service API version
*
* @param param the parameter to inspect
* @returns true if the parameter is for the API version
*/
export function isAPIVersionParameter(param) {
switch (param.kind) {
case 'headerScalarParam':
case 'pathScalarParam':
case 'queryScalarParam':
case 'uriParam':
return param.isApiVersion;
default:
return false;
}
}
/** narrows method to a LRO method type within the conditional block */
export function isLROMethod(method) {
return method.kind === 'lroMethod' || method.kind === 'lroPageableMethod';
}
/** narrows method to a pageable method type within the conditional block */
export function isPageableMethod(method) {
return method.kind === 'lroPageableMethod' || method.kind === 'pageableMethod';
}
/** creates the ClientOptions type from the specified input */
export function newClientOptions(modelType, clientName) {
if (modelType === 'azure-arm') {
return new type.ArmClientOptions();
}
const optionsTypeName = `${clientName}Options`;
let options = new ClientOptions(optionsTypeName);
options.docs.summary = `${optionsTypeName} contains the optional values for creating a [${clientName}]`;
return options;
}
class HttpMethodBase extends method.Method {
constructor(name, client, httpPath, httpMethod, statusCodes, naming) {
if (statusCodes.length === 0) {
throw new CodeModelError('statusCodes cannot be empty');
}
super(name, new method.Receiver('client', client, false));
this.apiVersions = new Array();
this.httpMethod = httpMethod;
this.httpPath = httpPath;
this.httpStatusCodes = statusCodes;
this.name = name;
this.naming = naming;
this.parameters = new Array();
this.examples = [];
this.docs = {};
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
export class Client {
constructor(name, docs) {
this.name = name;
this.docs = docs;
this.methods = new Array();
this.clientAccessors = new Array();
this.parameters = new Array();
}
}
export class ClientEndpoint {
constructor(parameter) {
this.parameter = parameter;
}
}
export class ClientAccessor {
constructor(name, subClient) {
this.name = name;
this.subClient = subClient;
}
}
export class Constructable {
constructor(options) {
this.kind = 'constructable';
this.options = options;
this.constructors = new Array();
}
}
export class ClientCredentialParameter extends method.Parameter {
constructor(name, type) {
super(name, type, true);
this.kind = 'credentialParam';
this.style = 'required';
}
}
export class ClientOptions {
constructor(name) {
this.kind = 'clientOptions';
this.name = name;
this.docs = {};
this.parameters = new Array();
}
}
export class Constructor {
constructor(name) {
this.name = name;
this.parameters = new Array();
}
}
export class LROMethod extends HttpMethodBase {
constructor(name, client, httpPath, httpMethod, statusCodes, naming) {
super(name, client, httpPath, httpMethod, statusCodes, naming);
this.kind = 'lroMethod';
}
}
export class LROPageableMethod extends HttpMethodBase {
constructor(name, client, httpPath, httpMethod, statusCodes, naming) {
super(name, client, httpPath, httpMethod, statusCodes, naming);
this.kind = 'lroPageableMethod';
}
}
export class SyncMethod extends HttpMethodBase {
constructor(name, client, httpPath, httpMethod, statusCodes, naming) {
super(name, client, httpPath, httpMethod, statusCodes, naming);
this.kind = 'method';
}
}
export class MethodNaming {
constructor(internalMethod, requestMethod, responseMethod) {
this.internalMethod = internalMethod;
this.requestMethod = requestMethod;
this.responseMethod = responseMethod;
}
}
export class NextPageMethod {
constructor(name, client, httpPath, httpMethod, statusCodes) {
if (statusCodes.length === 0) {
throw new CodeModelError('statusCodes cannot be empty');
}
this.kind = 'nextPageMethod';
this.apiVersions = new Array();
this.receiver = new method.Receiver('client', client, false);
this.httpMethod = httpMethod;
this.httpPath = httpPath;
this.httpStatusCodes = statusCodes;
this.name = name;
this.parameters = new Array();
}
}
export class PageableMethod extends HttpMethodBase {
constructor(name, client, httpPath, httpMethod, statusCodes, naming) {
super(name, client, httpPath, httpMethod, statusCodes, naming);
this.kind = 'pageableMethod';
}
}
export class SupplementalEndpoint {
constructor(path) {
this.path = path;
this.parameters = new Array();
}
}
export class TemplatedHost {
constructor(path) {
this.kind = 'templatedHost';
this.path = path;
}
}
//# sourceMappingURL=client.js.map