protected Task WriteModelsIndexFile <T>(Template <T> modelIndexTemplate) where T : CodeModelTS { CodeModelTS codeModel = modelIndexTemplate.Model; string filePath = GetSourceCodeFilePath(codeModel, "models", "index.ts"); return(Write(modelIndexTemplate, filePath)); }
public override void CreateModelTypeForOptionalClientProperties(CodeModelTS cm) { List <string> predefinedOptionalProperties = new List <string>() { "requestOptions", "filters", "noRetryPolicy", "apiVersion", "acceptLanguage", "longRunningOperationRetryTimeout", "generateClientRequestId", "rpRegistrationRetryTimeout" }; var optionalProperitesOnClient = cm.Properties.Where( p => (!p.IsRequired || p.IsRequired && !string.IsNullOrEmpty(p.DefaultValue)) && !p.IsConstant && !predefinedOptionalProperties.Contains(p.Name)); if (optionalProperitesOnClient.Count() > 0) { string modelTypeName = cm.Name + "Options"; var modelType = new CompositeTypeTS(modelTypeName); modelType.BaseModelType = New <CompositeType>(new { Name = "AzureServiceClientOptions", SerializedName = "AzureServiceClientOptions" }); // We could end up having a property that is required but has a default value based on the above condition. If so then make it optional. optionalProperitesOnClient.Where(p => p.IsRequired && !string.IsNullOrEmpty(p.DefaultValue)).ForEach(prop => prop.IsRequired = false); modelType.AddRange(optionalProperitesOnClient); var modelTypeFound = cm.ModelTypes.FirstOrDefault(m => m.Name.EqualsIgnoreCase(modelTypeName)); if (modelTypeFound != null) { cm.Remove(modelTypeFound); } cm.Add(modelType); cm.OptionalParameterTypeForClientConstructor = "Models." + modelTypeName; } }
protected Task WriteMethodGroupIndexFile(CodeModelTS codeModel) { string filePath = GetSourceCodeFilePath(codeModel, "operations", "index.ts"); return(Write(new MethodGroupIndexTemplate { Model = codeModel }, filePath)); }
public static CodeModelTS CodeModel(GeneratorSettingsTS settings = null) { CodeModelTS codeModel = DependencyInjection.New <CodeModelTS>(); codeModel.Settings = settings; return(codeModel); }
protected Task WriteSpecificationFile(CodeModelTS codeModel) { string filePath = GetSourceCodeFilePath(codeModel, "artifacts", "specifications.ts"); return(Write(new SpecificationTemplate { Model = codeModel }, filePath)); }
protected Task WriteMappersIndexFile(CodeModelTS codeModel) { string filePath = GetSourceCodeFilePath(codeModel, "models", "mappers.ts"); return(Write(new MapperIndexTemplate { Model = codeModel }, filePath)); }
protected Task WriteParameterMappersFile(CodeModelTS codeModel) { string filePath = GetSourceCodeFilePath(codeModel, "models", "parameters.ts"); return(Write(new ParameterTemplate { Model = codeModel }, filePath)); }
protected Task WriteMethodGroupFile(MethodGroupTS methodGroup) { CodeModelTS codeModel = methodGroup.CodeModelTS; string filePath = GetSourceCodeFilePath(codeModel, "operations", methodGroup.TypeName.ToCamelCase() + ".ts"); return(Write(new MethodGroupTemplate { Model = methodGroup }, filePath)); }
protected Task WriteAliasFile(CodeModelTS codeModel) { string filePath = GetSourceCodeFilePath(codeModel, "index.ts"); AliasIndexTemplate template = new AliasIndexTemplate { Model = codeModel }; return(Write(template, filePath)); }
protected Task WriteMethodGroupFile(MethodGroupTS methodGroup) { CodeModelTS codeModel = methodGroup.CodeModelTS; string typeName = methodGroup.TypeName.ToCamelCase(); string filePath = GetSourceCodeFilePath(codeModel, "handlers", methodGroup.HandlerInterfaceName + ".ts"); return(Write(new MethodGroupTemplate { Model = methodGroup }, filePath)); }
public void CreateSerializerExpressionWithNoMappersAndXML() { CodeModelTS codeModel = Models.CodeModel( modelTypes: new[] { Models.CompositeType(name: "FakeModelType") }); Assert.AreEqual("new coreHttp.Serializer(Mappers)", ClientModelExtensions.CreateSerializerExpression(codeModel)); }
protected void InitializeSettings(CodeModelTS codeModel) { GeneratorSettingsTS generatorSettings = Singleton <GeneratorSettingsTS> .Instance; codeModel.PackageName = Settings.Instance.PackageName; codeModel.PackageVersion = Settings.Instance.PackageVersion; codeModel.OutputFolder = generatorSettings.OutputFolder; codeModel.ModelEnumAsUnion = generatorSettings.ModelEnumAsUnion; codeModel.GenerateMetadata = generatorSettings.GenerateMetadata; }
/// <summary> /// Generate TypeScript client code /// </summary> /// <param name="serviceClient"></param> /// <returns></returns> public override async Task Generate(CodeModel codeModel) { CodeModelTS codeModelTS = (CodeModelTS)codeModel; if (codeModelTS.Settings.AzureArm == true) { await Generate(new AzureTemplateFactory(), (CodeModelTSa)codeModelTS); } else { await Generate(new VanillaTemplateFactory(), codeModelTS); } }
public static CodeModelTS CodeModel(GeneratorSettingsTS settings = null, IEnumerable <CompositeTypeTS> modelTypes = null) { CodeModelTS codeModel = DependencyInjection.New <CodeModelTS>(); codeModel.Settings = settings; if (modelTypes != null) { foreach (CompositeTypeTS modelType in modelTypes) { codeModel.Add(modelType); } } return(codeModel); }
public static MethodTS Method( HttpMethod httpMethod = HttpMethod.Get, string requestContentType = null, CodeModelTS codeModel = null, MethodGroupTS methodGroup = null, Response defaultResponse = null, IEnumerable <ParameterTS> parameters = null, string deprecatedMessage = null) { if (codeModel == null) { codeModel = CodeModel(); } MethodTS method = DependencyInjection.New <MethodTS>(); if (methodGroup == null) { methodGroup = MethodGroup(codeModel); } method.MethodGroup = methodGroup; codeModel.Add(method); method.HttpMethod = httpMethod; method.RequestContentType = requestContentType; method.DefaultResponse = defaultResponse; if (parameters != null) { foreach (ParameterTS parameter in parameters) { method.Add(parameter); } } method.DeprecationMessage = deprecatedMessage; return(method); }
public static MethodGroupTS MethodGroup(CodeModelTS codeModel = null, IEnumerable <MethodTS> methods = null) { if (codeModel == null) { codeModel = CodeModel(); } MethodGroupTS methodGroup = DependencyInjection.New <MethodGroupTS>(); codeModel.Add(methodGroup); if (methods != null) { foreach (MethodTS method in methods) { methodGroup.Add(method); } } return(methodGroup); }
public static string CreateSerializerExpression(this CodeModelTS codeModel) { TSBuilder builder = new TSBuilder(); builder.FunctionCall("new msRest.Serializer", arguments => { bool hasMappers = codeModel.HasMappers(); if (hasMappers) { arguments.Text("Mappers"); } if (codeModel.ShouldGenerateXmlSerialization == true) { if (!hasMappers) { arguments.Object(); } arguments.Boolean(true); } }); return(builder.ToString()); }
protected Task WriteRollupConfig(CodeModelTS codeModel) { return(Write(codeModel.GenerateRollupConfig(), "rollup.config.js")); }
protected Task WriteTsConfig(CodeModelTS codeModel) { return(Write(new TsConfig { Model = codeModel }, "tsconfig.json")); }
protected Task WriteLicenseFile(CodeModelTS codeModel) { return(Write(new LicenseTemplate { Model = codeModel }, "LICENSE.txt")); }
protected Task WriteReadmeMdFile(CodeModelTS codeModel) { return(Write(codeModel.GenerateReadmeMd(), "README.md")); }
protected Task WritePackageJsonFile(CodeModelTS codeModel) { return(Write(codeModel.GeneratePackageJson(), "package.json")); }
protected bool ShouldWriteReadmeMdFile(CodeModelTS codeModel) { return(codeModel.Settings.GenerateReadmeMd ?? codeModel.Settings.GenerateMetadata); }
public static bool ShouldWriteMethodGroupFiles(CodeModelTS codeModel) { return(codeModel.MethodGroupModels.Any()); }
protected Task WriteMappersIndexFile(CodeModelTS codeModel) { string filePath = GetSourceCodeFilePath(codeModel, "models", "mappers.ts"); return(Write(codeModel.GenerateMapperIndex(), filePath)); }
protected bool IsMultiapiLatest(CodeModelTS codeModel) { return(codeModel.Settings.MultiapiLatest); }
protected bool ShouldWriteMetadata(CodeModelTS codeModel) { return(codeModel.Settings.GenerateMetadata); }
protected string GetSourceCodeFilePath(CodeModelTS codeModel, params string[] pathSegments) { return(GetSourceCodeFilePath(codeModel.Settings, pathSegments)); }
protected bool ShouldWriteLicenseFile(CodeModelTS codeModel) { return(codeModel.Settings.GenerateLicenseTxt ?? codeModel.Settings.GenerateMetadata); }
protected bool ShouldWritePackageJsonFile(CodeModelTS codeModel) { return(codeModel.Settings.GeneratePackageJson ?? codeModel.Settings.GenerateMetadata); }