UNPKG

@autorest/powershell

Version:
129 lines 7.52 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.CallbackParameter = exports.OperationBodyParameter = exports.OperationParameter = void 0; const codemodel_v3_1 = require("@azure-tools/codemodel-v3"); const codegen_csharp_1 = require("@azure-tools/codegen-csharp"); const codegen_csharp_2 = require("@azure-tools/codegen-csharp"); /** represents a method parameter for an http operation (header/cookie/query/path) */ class OperationParameter extends codegen_csharp_2.Parameter { constructor(parent, param, state, objectInitializer) { var _a, _b; const typeDeclaration = state.project.modelsNamespace.NewResolveTypeDeclaration(param.schema, !!param.required, state); super(((_a = param.language.csharp) === null || _a === void 0 ? void 0 : _a.name) || '', typeDeclaration); this.param = param; this.typeDeclaration = typeDeclaration; this.apply(objectInitializer); this.description = ((_b = param.language.csharp) === null || _b === void 0 ? void 0 : _b.description) || ''; } /** emits an expression to deserialize a property from a member inside a container */ deserializeFromContainerMember(mediaType, container, serializedName) { // return this.assign(this.typeDeclaration.deserializeFromContainerMember(mediaType, container, serializedName, this)) return this.typeDeclaration.deserializeFromContainerMember(mediaType, container, serializedName, this); } /** emits an expression to deserialze a container as the value itself. */ deserializeFromNode(mediaType, node) { return this.typeDeclaration.deserializeFromNode(mediaType, node, this); } /** emits an expression serialize this to the value required by the container */ serializeToNode(mediaType, serializedName, mode) { return this.typeDeclaration.serializeToNode(mediaType, this, serializedName, mode); } /** emits an expression serialize this to a HttpContent */ serializeToContent(mediaType, mode) { return this.typeDeclaration.serializeToContent(mediaType, this, mode); } /** emits the code required to serialize this into a container */ serializeToContainerMember(mediaType, container, serializedName, mode) { return this.typeDeclaration.serializeToContainerMember(mediaType, this, container, serializedName, mode); } validatePresenceStatement(eventListener) { return this.typeDeclaration.validatePresence(eventListener, this); } validationStatement(eventListener) { return this.typeDeclaration.validateValue(eventListener, this); } } exports.OperationParameter = OperationParameter; /** represents a method parameter for an http operation (body) */ class OperationBodyParameter extends codegen_csharp_2.Parameter { /** emits an expression to deserialize a property from a member inside a container */ deserializeFromContainerMember(mediaType, container, serializedName) { // return this.assign(this.typeDeclaration.deserializeFromContainerMember(mediaType, container, serializedName, this)); return this.typeDeclaration.deserializeFromContainerMember(mediaType, container, serializedName, this); } /** emits an expression to deserialze a container as the value itself. */ deserializeFromNode(mediaType, node) { // return this.assign(this.typeDeclaration.deserializeFromNode(mediaType, node, this)); return this.typeDeclaration.deserializeFromNode(mediaType, node, this); } /** emits an expression serialize this to the value required by the container */ serializeToNode(mediaType, serializedName, mode) { return this.typeDeclaration.serializeToNode(mediaType, this, serializedName, mode); } /** emits an expression serialize this to a HttpContent */ serializeToContent(mediaType, mode) { return this.typeDeclaration.serializeToContent(mediaType, this, mode); } /** emits the code required to serialize this into a container */ serializeToContainerMember(mediaType, container, serializedName, mode) { return this.typeDeclaration.serializeToContainerMember(mediaType, this, container, serializedName, mode); } validatePresenceStatement(eventListener) { return this.typeDeclaration.validatePresence(eventListener, this); } validationStatement(eventListener) { return this.typeDeclaration.validateValue(eventListener, this); } constructor(parent, name, description, schema, required, state, objectInitializer) { var _a; const typeDeclaration = state.project.modelsNamespace.NewResolveTypeDeclaration(schema, required, state.path('schema')); super(name, typeDeclaration); this.typeDeclaration = typeDeclaration; this.mediaType = codemodel_v3_1.KnownMediaType.Json; this.contentType = codemodel_v3_1.KnownMediaType.Json; this.apply(objectInitializer); this.description = description || ((_a = schema.language.csharp) === null || _a === void 0 ? void 0 : _a.description) || ''; } get jsonSerializationStatement() { // get the body serialization from the typeDeclaration. return '/* body parameter */'; // (<TypeDeclaration>this.type).jsonserialize(this.name); } get jsonDeserializationStatement() { return '/* body parameter */'; // (<TypeDeclaration>this.type).jsonDeserializationImplementation(this.name); } } exports.OperationBodyParameter = OperationBodyParameter; class CallbackParameter extends codegen_csharp_2.Parameter { constructor(name, responseType, headerType, state, objectInitializer) { // regular pipeline style. (callback happens after the pipline is called) if (responseType) { if (headerType) { // both super(name, codegen_csharp_1.System.Func(codegen_csharp_1.System.Net.Http.HttpResponseMessage, codegen_csharp_1.System.Threading.Tasks.Task(responseType), codegen_csharp_1.System.Threading.Tasks.Task(headerType), codegen_csharp_1.System.Threading.Tasks.Task())); } else { // just response super(name, codegen_csharp_1.System.Func(codegen_csharp_1.System.Net.Http.HttpResponseMessage, codegen_csharp_1.System.Threading.Tasks.Task(responseType), codegen_csharp_1.System.Threading.Tasks.Task())); } } else { if (headerType) { // just headers super(name, codegen_csharp_1.System.Func(codegen_csharp_1.System.Net.Http.HttpResponseMessage, codegen_csharp_1.System.Threading.Tasks.Task(headerType), codegen_csharp_1.System.Threading.Tasks.Task())); } else { // no content? super(name, codegen_csharp_1.System.Func(codegen_csharp_1.System.Net.Http.HttpResponseMessage, codegen_csharp_1.System.Threading.Tasks.Task())); } } this.responseType = responseType; this.headerType = headerType; this.apply(objectInitializer); } } exports.CallbackParameter = CallbackParameter; //# sourceMappingURL=parameter.js.map