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 void ExportOrderedMapperModels(TSBuilder builder, IEnumerable <CompositeTypeTS> orderedMapperModels, string emptyLine) { foreach (CompositeTypeTS mapperModel in OrderedMapperTemplateModels) { builder.Line(emptyLine); mapperModel.ConstructModelMapper(builder); } }
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()); }
public string GenerateResponseTypes(string emptyLine) { TSBuilder builder = new TSBuilder(); foreach (MethodTS method in MethodsWithCustomResponseType) { builder.Line(emptyLine); method.GenerateResponseType(builder); } return(builder.ToString()); }
public string GenerateMappers() { TSBuilder builder = new TSBuilder(); builder.Comment(AutoRest.Core.Settings.Instance.Header); builder.Line(); builder.Line("export {"); builder.Indent(() => { List <string> exportedValues = new List <string>(); if (!string.IsNullOrWhiteSpace(CodeModelTS.PolymorphicDictionary)) { exportedValues.Add("discriminators"); } exportedValues.AddRange(OperationModelNames.OrderBy(mapperName => mapperName.ToLowerInvariant())); builder.Line(string.Join(",\n", exportedValues)); }); builder.Line("} from \"../models/mappers\";"); return(builder.ToString()); }
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 virtual string GenerateMapperIndex(string emptyLine) { TSBuilder builder = new TSBuilder(); CompositeTypeTS[] orderedMapperTemplateModels = OrderedMapperTemplateModels.ToArray(); ImportMsRestForMappers(builder, orderedMapperTemplateModels); builder.Line(emptyLine); ExportOrderedMapperModels(builder, orderedMapperTemplateModels, emptyLine); ExportPolymorphicDictionary(builder, emptyLine); return(builder.ToString()); }
public string GenerateReadmeMdNodeSampleCode(string emptyLine) { TSBuilder builder = new TSBuilder(); GenerateNodeSampleImports(builder); builder.ConstVariable("subscriptionId", "process.env[\"AZURE_SUBSCRIPTION_ID\"]"); builder.Line(emptyLine); builder.Line($"msRestNodeAuth.interactiveLogin().then((creds) => {{"); builder.Indent(() => { builder.ConstVariable("client", $"new {Name}(creds, subscriptionId)"); builder.Line(GenerateSampleMethod(false)); }); builder.Line($"}}).catch((err) => {{"); builder.Indent(() => { builder.Line("console.error(err);"); }); builder.Line($"}});"); return(builder.ToString()); }
public void Property(string propertyName, string propertyType, bool optional = false, bool isReadonly = false, bool isNullable = false) { builder.Line($"{(isReadonly ? "readonly " : "")}{propertyName}{(optional ? "?" : "")}: {propertyType}{(isNullable ? " | null" : "")};"); }
public virtual string Generate() { TSBuilder builder = new TSBuilder(); if (ImmediatePolymorphicSubtypes.Any()) { builder.DocumentationComment($"Contains the possible cases for {Name}."); List <string> unionTypeValues = new List <string>() { Name }; unionTypeValues.AddRange(ImmediatePolymorphicSubtypes.Select(m => m.UnionTypeName)); builder.ExportUnionType($"{Name}Union", unionTypeValues); builder.Line(); } builder.DocumentationComment(comment => { string description = Documentation; if (string.IsNullOrEmpty(description)) { description = $"An interface representing {Name}."; } comment.Description(description); comment.Summary(Summary); }); string baseTypeName = null; if (BaseModelType != null && !BaseIsPolymorphic) { baseTypeName = BaseModelType.Name; if (baseTypeName == "RequestOptionsBase") { // baseTypeName = $"coreHttp.{baseTypeName}"; baseTypeName = null; } } builder.ExportInterface(Name, baseTypeName, tsInterface => { ISet <string> addedPropertyNames = new HashSet <string>(); foreach (Property property in InterfaceProperties) { string propertyName = property.Name; if (!addedPropertyNames.Contains(propertyName)) { addedPropertyNames.Add(propertyName); string propertyDescription = $"{property.Summary.EnsureEndsWith(".")} {property.Documentation}".Trim(); if (!property.DefaultValue.IsNullOrEmpty()) { propertyDescription = $"{propertyDescription.EnsureEndsWith(".")} Default value: {property.DefaultValue}.".Trim(); } tsInterface.DocumentationComment(propertyDescription); string propertyType = property.IsPolymorphicDiscriminator ? $"\"{SerializedName}\"" : property.ModelType.TSType(true); bool isReadonly = property.IsReadOnly; bool isOptional = !property.IsRequired && (!(CodeModel?.HeaderTypes.Contains(this) == true) || CodeModelTS.Settings.OptionalResponseHeaders); bool isNullable = property.IsXNullable ?? false; tsInterface.Property(property.Name, propertyType, optional: isOptional, isReadonly: isReadonly, isNullable: isNullable); } } if (AdditionalProperties != null) { tsInterface.DocumentationComment(AdditionalPropertiesDocumentation()); tsInterface.Property("[property: string]", AdditionalPropertiesTSType()); } }); 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(";"); }
public void Value(string value) { builder.Line($"{value},"); }