UNPKG

@autorest/go

Version:
236 lines 8.72 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as type from './type.js'; /** narrows style to a ClientSideDefault within the conditional block */ export function isClientSideDefault(style) { return style.defaultValue !== undefined; } /** narrows param to a FormBodyParameter within the conditional block */ export function isFormBodyParameter(param) { return param.kind === 'formBodyCollectionParam' || param.kind === 'formBodyScalarParam'; } /** narrows param to a HeaderParameter within the conditional block */ export function isHeaderParameter(param) { return param.kind === 'headerCollectionParam' || param.kind === 'headerMapParam' || param.kind === 'headerScalarParam'; } /** narrows type to a HeaderScalarType within the conditional block */ export function isHeaderScalarType(type) { switch (type.kind) { case 'constant': case 'encodedBytes': case 'literal': case 'scalar': case 'string': case 'time': return true; default: return false; } } /** narrows param to a PathParameter within the conditional block */ export function isPathParameter(param) { return param.kind === 'pathCollectionParam' || param.kind === 'pathScalarParam'; } /** narrows type to a PathScalarParameterType within the conditional block */ export function isPathScalarParameterType(type) { switch (type.kind) { case 'constant': case 'encodedBytes': case 'literal': case 'scalar': case 'string': case 'time': return true; default: return false; } } /** narrows param to a QueryParameter within the conditional block */ export function isQueryParameter(param) { return param.kind === 'queryCollectionParam' || param.kind === 'queryScalarParam'; } /** narrows type to a QueryScalarParameterType within the conditional block */ export function isQueryScalarParameterType(type) { switch (type.kind) { case 'constant': case 'encodedBytes': case 'literal': case 'scalar': case 'string': case 'time': return true; default: return false; } } /** returns true if the param is required */ export function isRequiredParameter(param) { // parameters with a client-side default value are always optional if (isClientSideDefault(param.style)) { return false; } return param.style === 'required'; } /** narrows type to a URIParameterType within the conditional block */ export function isURIParameterType(type) { switch (type.kind) { case 'constant': case 'scalar': case 'string': return true; default: return false; } } /** returns true if the param is a literal */ export function isLiteralParameter(param) { if (isClientSideDefault(param.style)) { return false; } return param.style === 'literal'; } class ParameterBase { constructor(name, type, style, byValue, location) { this.name = name; this.type = type; this.style = style; this.byValue = byValue; this.location = location; this.docs = {}; } } /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// export class BodyParameter extends ParameterBase { constructor(name, bodyFormat, contentType, type, style, byValue) { super(name, type, style, byValue, 'method'); this.kind = 'bodyParam'; this.bodyFormat = bodyFormat; this.contentType = contentType; } } export class ClientSideDefault { constructor(defaultValue) { this.defaultValue = defaultValue; } } export class FormBodyCollectionParameter extends ParameterBase { constructor(name, formDataName, type, collectionFormat, style, byValue) { super(name, type, style, byValue, 'method'); this.kind = 'formBodyCollectionParam'; this.formDataName = formDataName; this.collectionFormat = collectionFormat; } } export class FormBodyScalarParameter extends ParameterBase { constructor(name, formDataName, type, style, byValue) { super(name, type, style, byValue, 'method'); this.kind = 'formBodyScalarParam'; this.formDataName = formDataName; } } export class HeaderCollectionParameter extends ParameterBase { constructor(name, headerName, type, collectionFormat, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'headerCollectionParam'; this.headerName = headerName; this.collectionFormat = collectionFormat; } } export class HeaderMapParameter extends ParameterBase { constructor(name, headerName, type, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'headerMapParam'; this.headerName = headerName; } } export class HeaderScalarParameter extends ParameterBase { constructor(name, headerName, type, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'headerScalarParam'; this.headerName = headerName; } } export class MultipartFormBodyParameter extends ParameterBase { constructor(name, type, style, byValue) { super(name, type, style, byValue, 'method'); this.kind = 'multipartFormBodyParam'; } } export class Parameter extends ParameterBase { constructor(name, type, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'parameter'; } } export class ParameterGroup { constructor(name, groupName, required, location) { this.kind = 'paramGroup'; this.groupName = groupName; this.location = location; this.name = name; // params is required but must be populated post construction this.params = new Array(); this.required = required; this.docs = {}; } } export class PartialBodyParameter extends ParameterBase { constructor(name, serializedName, format, type, style, byValue) { super(name, type, style, byValue, 'method'); this.kind = 'partialBodyParam'; this.format = format; this.serializedName = serializedName; } } export class PathCollectionParameter extends ParameterBase { constructor(name, pathSegment, isEncoded, type, collectionFormat, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'pathCollectionParam'; this.pathSegment = pathSegment; this.isEncoded = isEncoded; this.collectionFormat = collectionFormat; } } export class PathScalarParameter extends ParameterBase { constructor(name, pathSegment, isEncoded, type, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'pathScalarParam'; this.pathSegment = pathSegment; this.isEncoded = isEncoded; } } export class QueryCollectionParameter extends ParameterBase { constructor(name, queryParam, isEncoded, type, collectionFormat, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'queryCollectionParam'; this.queryParameter = queryParam; this.isEncoded = isEncoded; this.collectionFormat = collectionFormat; } } export class QueryScalarParameter extends ParameterBase { constructor(name, queryParam, isEncoded, type, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'queryScalarParam'; this.queryParameter = queryParam; this.isEncoded = isEncoded; } } export class ResumeTokenParameter extends ParameterBase { constructor() { super('ResumeToken', new type.String(), 'optional', true, 'method'); this.kind = 'resumeTokenParam'; this.docs.summary = 'Resumes the long-running operation from the provided token.'; } } export class URIParameter extends ParameterBase { constructor(name, uriPathSegment, type, style, byValue, location) { super(name, type, style, byValue, location); this.kind = 'uriParam'; this.uriPathSegment = uriPathSegment; } } //# sourceMappingURL=param.js.map