Beispiel #1
0
        public string GetDeserializationString(IModelType type, string valueReference = "result", string responseVariable = "parsedResponse")
        {
            TSBuilder builder = new TSBuilder();

            if (type is CompositeType)
            {
                builder.Line($"const resultMapper = Mappers.{type.Name};");
            }
            else
            {
                builder.Text($"const resultMapper = ");
                ClientModelExtensions.ConstructMapper(builder, type, responseVariable, null, isPageable: false, expandComposite: false, isXML: CodeModel?.ShouldGenerateXmlSerialization == true);
                builder.Line(";");
            }

            if (CodeModel.ShouldGenerateXmlSerialization && type is SequenceType st)
            {
                builder.Line("{2} = client.serializer.deserialize(resultMapper, typeof {0} === 'object' ? {0}['{1}'] : [], '{2}');", responseVariable, st.ElementType.XmlName, valueReference);
            }
            else
            {
                builder.Line("{1} = client.serializer.deserialize(resultMapper, {0}, '{1}');", responseVariable, valueReference);
            }
            return(builder.ToString());
        }
        public string GenerateParameterMappers()
        {
            TSBuilder builder = new TSBuilder();
            IEnumerable <ParameterTS> parameters = Methods
                                                   .SelectMany(m => m.LogicalParameters)
                                                   .Cast <ParameterTS>()
                                                   .Where(p => p.ModelTypeName != "RequestOptionsBase" && p.Location != ParameterLocation.Body)
                                                   .OrderBy(p => p.MapperName)
                                                   .Distinct(ParameterNameComparer.Instance);

            foreach (ParameterTS parameter in parameters)
            {
                string parameterInterfaceName =
                    parameter.Location == ParameterLocation.Path ? "msRest.OperationURLParameter" :
                    parameter.Location == ParameterLocation.Query ? "msRest.OperationQueryParameter" :
                    "msRest.OperationParameter";

                builder.Text("export ");
                builder.ConstObjectVariable(
                    parameter.MapperName,
                    parameterInterfaceName,
                    obj => ClientModelExtensions.ConstructParameterMapper(obj, parameter));
                builder.Line();
            }

            return(builder.ToString());
        }
Beispiel #3
0
        public string GenerateReadmeMdBrowserSampleCode(string emptyLine)
        {
            TSBuilder builder = new TSBuilder();

            builder.ConstQuotedStringVariable("subscriptionId", "<Subscription_Id>");
            builder.Text("const authManager = new msAuth.AuthManager(");
            builder.Object(tsObject =>
            {
                tsObject.QuotedStringProperty("clientId", "<client id for your Azure AD app>");
                tsObject.QuotedStringProperty("tenant", "<optional tenant for your organization>");
            });
            builder.Line(");");

            builder.Line($"authManager.finalizeLogin().then((res) => {{");
            builder.Indent(() =>
            {
                builder.If("!res.isLoggedIn", ifBlock =>
                {
                    ifBlock.LineComment("may cause redirects");
                    ifBlock.Line("authManager.login();");
                });

                builder.ConstVariable("client", $"new {BundleVarName}.{Name}(res.creds, subscriptionId)");
                builder.Line($"{GenerateSampleMethod(true)}.catch((err) => {{");
                builder.Indent(() =>
                {
                    builder.Line("console.log(\"An error occurred:\");");
                    builder.Line("console.error(err);");
                });
                builder.Line($"}});");
            });
            builder.Line($"}});");

            return(builder.ToString());
        }
        public override string ConstructModelMapper()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text($"export const {Name} = ");
            ClientModelExtensions.ConstructMapper(builder, this, SerializedName, null, isPageable: true, expandComposite: true, isXML: CodeModel?.ShouldGenerateXmlSerialization == true);
            builder.Line(";");
            return(builder.ToString());
        }
        public virtual void ConstructModelMapper(TSBuilder builder)
        {
            builder.Text($"export const {Name}: coreHttp.CompositeMapper = ");
            bool isHeaders = CodeModel.HeaderTypes.Contains(this) == true;
            bool isXML     = !isHeaders && CodeModel.ShouldGenerateXmlSerialization == true;

            ClientModelExtensions.ConstructMapper(builder, this, SerializedName, null, isPageable: false, expandComposite: true, isXML: isXML, isCaseSensitive: !isHeaders, xmlName: isXML ? XmlName : null);
            builder.Line(";");
        }
        public virtual string ConstructModelMapper()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text($"export const {Name} = ");
            bool isXML = CodeModel?.ShouldGenerateXmlSerialization == true;

            ClientModelExtensions.ConstructMapper(builder, this, SerializedName, null, isPageable: false, expandComposite: true, isXML: isXML, isCaseSensitive: CodeModel?.HeaderTypes.Contains(this) != true, xmlName: isXML ? XmlName : null);
            builder.Line(";");
            return(builder.ToString());
        }
Beispiel #7
0
        public string GenerateSendOperationRequest()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text("const operationArguments: msRest.OperationArguments = ");
            builder.FunctionCall("msRest.createOperationArguments", GenerateOperationArguments);
            builder.Line(";");
            builder.FunctionCall("operationRes = await client.sendOperationRequest", argumentList =>
            {
                argumentList.Text("httpRequest");
                argumentList.Text("operationArguments");
                argumentList.Object(GenerateOperationSpec);
            });
            return(builder.ToString());
        }
 public override void ConstructModelMapper(TSBuilder builder)
 {
     builder.Text($"export const {Name}: msRest.CompositeMapper = ");
     ClientModelExtensions.ConstructMapper(builder, this, SerializedName, null, isPageable: true, expandComposite: true, isXML: CodeModel?.ShouldGenerateXmlSerialization == true);
     builder.Line(";");
 }