/// <summary>
 /// Initializes a new instance of RequirementsTemplateModel class.
 /// </summary>
 /// <param name="serviceClient">The service client.</param>
 /// <param name="sdkName">The name of the SDK.</param>
 /// <param name="implementationFileExtension">The files extension.</param>
 /// <param name="ns">The namespace of the SDK.</param>
 public RequirementsTemplateModel(ServiceClient serviceClient, string sdkName, string implementationFileExtension, string ns)
 {
     this.LoadFrom(serviceClient);
     this.ns = ns;
     this.sdkName = sdkName;
     this.implementationFileExtension = implementationFileExtension;
 }
 public AzureFluentModelTemplateModel(CompositeType source, ServiceClient serviceClient)
     : base(source, serviceClient)
 {
     _namer = new AzureJavaFluentCodeNamer(serviceClient.Namespace);
     PropertyModels = new List<PropertyModel>();
     Properties.ForEach(p => PropertyModels.Add(new FluentPropertyModel(p, serviceClient.Namespace, IsInnerModel)));
 }
 /// <summary>
 /// Initializes a new instance of the AzureServiceClientTemplateModel class.
 /// </summary>
 /// <param name="serviceClient">The service client instance.</param>
 public AzureServiceClientTemplateModel(ServiceClient serviceClient)
     : base(serviceClient)
 {
     MethodTemplateModels.Clear();
     Methods.Where(m => m.Group == null)
         .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
 }
        private static async Task TestGenerate(string apiVersion, string[] methodUrls, string expectedJsonString)
        {
            MemoryFileSystem fileSystem = new MemoryFileSystem();

            Settings settings = new Settings();
            settings.FileSystem = fileSystem;

            ServiceClient serviceClient = new ServiceClient();
            serviceClient.ApiVersion = apiVersion;
            foreach(string methodUrl in methodUrls)
            {
                serviceClient.Methods.Add(new Method()
                {
                    Url = methodUrl,
                    HttpMethod = HttpMethod.Put,
                });
            }
            await CreateGenerator(settings).Generate(serviceClient);

            Assert.Equal(2, fileSystem.VirtualStore.Count);

            string folderPath = fileSystem.VirtualStore.Keys.First();
            Assert.Equal("Folder", fileSystem.VirtualStore[folderPath].ToString());

            JObject expectedJSON = JObject.Parse(expectedJsonString);

            string fileContents = fileSystem.VirtualStore[fileSystem.VirtualStore.Keys.Skip(1).First()].ToString();
            JObject actualJson = JObject.Parse(fileContents);

            Assert.Equal(expectedJSON, actualJson);
        }
        public void NormalizeClientModelDoesNothing()
        {
            ServiceClient serviceClient = new ServiceClient();
            CreateGenerator().NormalizeClientModel(serviceClient);

            // Nothing happens
        }
 public AzureMethodGroupTemplateModel(ServiceClient serviceClient, string methodGroupName)
     : base(serviceClient, methodGroupName)
 {
     MethodTemplateModels.Clear();
     Methods.Where(m => m.Group == MethodGroupName)
         .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
 }
        public AzureMethodGroupTemplateModel(ServiceClient serviceClient, string methodGroupName)
            : base(serviceClient, methodGroupName)
        {
            // Clear base initialized MethodTemplateModels and re-populate with
            // AzureMethodTemplateModel
            MethodTemplateModels.Clear();

            var currentMethods = Methods.Where(m => m.Group == MethodGroupName && m.Extensions.ContainsKey(AzureExtensions.PageableExtension));
            var nextListMethods = new List<Method>();
            foreach (var method in currentMethods)
            {
                var pageableExtension = method.Extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer;
                var operationName = (string)pageableExtension["operationName"];
                if (operationName != null)
                {
                    var nextLinkMethod = Methods.FirstOrDefault(m =>
                        operationName.Equals(m.SerializedName, StringComparison.OrdinalIgnoreCase));
                    if (nextLinkMethod != null)
                    {
                        method.Extensions["nextLinkURL"] = nextLinkMethod.Url;
                        method.Extensions["nextLinkParameters"] = nextLinkMethod.LogicalParameters;
                        nextListMethods.Add(nextLinkMethod);
                    }
                }
            }
            Methods.RemoveAll(m => nextListMethods.Contains(m));
            Methods.Where(m => m.Group == methodGroupName)
                .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
        }
Beispiel #8
0
        /// <summary>
        /// Normalizes client model using Azure-specific extensions.
        /// </summary>
        /// <param name="serviceClient">Service client</param>
        /// <param name="settings">AutoRest settings</param>
        /// <param name="codeNamer">AutoRest settings</param>
        /// <returns></returns>
        public static void NormalizeAzureClientModel(ServiceClient serviceClient, Settings settings, CodeNamer codeNamer)
        {
            if (serviceClient == null)
            {
                throw new ArgumentNullException("serviceClient");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (codeNamer == null)
            {
                throw new ArgumentNullException("codeNamer");
            }

            settings.AddCredentials = true;

            // This extension from general extensions must be run prior to Azure specific extensions.
            ProcessParameterizedHost(serviceClient, settings);
            
            ProcessClientRequestIdExtension(serviceClient);
            UpdateHeadMethods(serviceClient);
            ParseODataExtension(serviceClient);
            ProcessGlobalParameters(serviceClient);
            FlattenModels(serviceClient);
            FlattenMethodParameters(serviceClient, settings);
            ParameterGroupExtensionHelper.AddParameterGroups(serviceClient);
            AddLongRunningOperations(serviceClient);
            AddAzureProperties(serviceClient);
            SetDefaultResponses(serviceClient);
            AddPageableMethod(serviceClient, codeNamer);
        }
Beispiel #9
0
        /// <summary>
        /// Generates Go code for service client.
        /// </summary>
        /// <param name="serviceClient"></param>
        /// <returns></returns>
        public override async Task Generate(ServiceClient serviceClient)
        {
            string packageName = GoCodeNamer.PackageNameFromNamespace(Settings.Namespace);
            
            // Service client
            var serviceClientTemplate = new ServiceClientTemplate
            {
                Model = new ServiceClientTemplateModel(serviceClient, packageName),
            };
            await Write(serviceClientTemplate, GoCodeNamer.FormatFileName("client"));

            foreach (var methodGroupName in serviceClient.MethodGroups)
            {
                var groupedMethodTemplate = new MethodGroupTemplate
                {
                    Model = new MethodGroupTemplateModel(serviceClient, packageName, methodGroupName),
                };
                await Write(groupedMethodTemplate, GoCodeNamer.FormatFileName(methodGroupName.ToLowerInvariant()));
            }

            // Models
            var modelsTemplate = new ModelsTemplate
            {
                Model = new ModelsTemplateModel(serviceClient, packageName),
            };
            await Write(modelsTemplate, GoCodeNamer.FormatFileName("models"));

            // Version
            var versionTemplate = new VersionTemplate
            {
                Model = new VersionTemplateModel(serviceClient, packageName),
            };
            await Write(versionTemplate, GoCodeNamer.FormatFileName("version"));
        }
 public override async Task Generate(ServiceClient serviceClient)
 {
     var viewModel = new SampleViewModel();
     var model = new SampleModel();
     model.Model = viewModel;
     await Write(model, Path.Combine(Settings.ModelsName, "Pet.cs"));
 }
        public VersionTemplateModel(ServiceClient serviceClient, string packageName, string[] version)
        {
            this.LoadFrom(serviceClient);

            PackageName = packageName;
            Version = version;
        }
        public ServiceClientTemplateModel(ServiceClient serviceClient, string packageName, string methodGroupName = null)
        {
            this.LoadFrom(serviceClient);

            MethodGroupName = methodGroupName == null
                                ? string.Empty
                                : methodGroupName;
            PackageName = packageName == null
                            ? string.Empty
                            : packageName;

            BaseClient = "ManagementClient";
            ClientName = string.IsNullOrEmpty(MethodGroupName)
                            ? BaseClient
                            : MethodGroupName.IsNamePlural(PackageName)
                                             ? MethodGroupName + "Client"
                                             : (MethodGroupName + "Client").TrimPackageName(PackageName);
            MethodScope = new MethodScopeProvider();
            MethodTemplateModels = new List<MethodTemplateModel>();

            Methods.Where(m => m.BelongsToGroup(MethodGroupName, PackageName))
                    .OrderBy(m => m.Name)
                    .ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, ClientName, PackageName, new MethodScopeProvider())));

            Documentation = string.Format("Package {0} implements the Azure ARM {1} service API version {2}.\n\n{3}", PackageName, ServiceName, ApiVersion,
                                    !string.IsNullOrEmpty(Documentation) ? Documentation.UnwrapAnchorTags() : "");
            ClientDocumentation = string.Format("{0} is the base client for {1}.", ClientName, ServiceName);
        }
 public MethodTemplateModel(Method source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ParameterTemplateModels = new List<ParameterTemplateModel>();
     source.Parameters.ForEach(p => ParameterTemplateModels.Add(new ParameterTemplateModel(p)));
     ServiceClient = serviceClient;
     if (source.Group != null)
     {
         OperationName = source.Group.ToPascalCase();
     }
     else
     {
         OperationName = serviceClient.Name;
     }
     AddCustomHeader = true;
     string formatter;
     foreach (var parameter in LocalParameters)
     {
         if (string.IsNullOrWhiteSpace(parameter.DefaultValue))
         {
             parameter.DefaultValue = PythonConstants.None;
         }
     }
     foreach (Match m in Regex.Matches(Url, @"\{[\w]+:[\w]+\}"))
     {
         formatter = m.Value.Split(':').First() + '}';
         Url = Url.Replace(m.Value, formatter);
     }
 }
        public void NameCollisionTestWithoutNamespace()
        {
            var serviceClient = new ServiceClient();
            serviceClient.Name = "azure always rocks!";

            var customObjectType = new CompositeType();
            customObjectType.Name = "azure always rocks!";

            var baseType = new CompositeType();
            baseType.Name = "azure always rocks!";

            serviceClient.Methods.Add(new Method
            {
                Name = "azure always rocks!",
                Group = "azure always rocks!",
                ReturnType = new Response(customObjectType, null)
            });

            serviceClient.ModelTypes.Add(customObjectType);
            serviceClient.ModelTypes.Add(baseType);

            var framework = new CSharpCodeNamer();
            framework.ResolveNameCollisions(serviceClient, null, null);

            Assert.Equal("azure always rocks!Client", serviceClient.Name);
            Assert.Equal("azure always rocks!Operations", serviceClient.MethodGroups.First());
            Assert.Equal("azure always rocks!", serviceClient.Methods[0].Name);
            Assert.Equal("azure always rocks!", serviceClient.ModelTypes.First(m => m.Name == "azure always rocks!").Name);
        }
 public AzureServiceClientTemplateModel(ServiceClient serviceClient, bool internalConstructors)
     : base(serviceClient, internalConstructors)
 {
     // TODO: Initialized in the base constructor. Why Clear it?
     MethodTemplateModels.Clear();
     Methods.Where(m => m.Group == null)
         .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient, SyncMethodsGenerationMode.None)));
 }
Beispiel #16
0
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClientModel"></param>
 public override void NormalizeClientModel(ServiceClient serviceClientModel)
 {
     // Add the current package name as a reserved keyword
     _namingFramework.ReserveNamespace(Settings.Namespace);
     _namingFramework.NormalizeClientModel(serviceClientModel);
     _namingFramework.ResolveNameCollisions(serviceClientModel, Settings.Namespace,
         Settings.Namespace + ".Models");
 }
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClient"></param>
 public override void NormalizeClientModel(ServiceClient serviceClient)
 {
     PopulateAdditionalProperties(serviceClient);
     SwaggerExtensions.NormalizeClientModel(serviceClient, Settings);
     _namer.NormalizeClientModel(serviceClient);
     _namer.ResolveNameCollisions(serviceClient, Settings.Namespace,
         Settings.Namespace + "." + Settings.ModelsName);
 }
 public ExtensionsTemplateModel(ServiceClient serviceClient, string operationName, SyncMethodsGenerationMode syncWrappers)
 {
     this.LoadFrom(serviceClient);
     MethodTemplateModels = new List<MethodTemplateModel>();
     ExtensionName = operationName ?? this.Name;
     this.Methods.Where(m => m.Group == operationName)
         .ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient, syncWrappers)));
 }
 /// <summary>
 /// Normalizes client model using generic extensions.
 /// </summary>
 /// <param name="serviceClient">Service client</param>
 /// <param name="settings">AutoRest settings</param>
 /// <returns></returns>
 public static void NormalizeClientModel(ServiceClient serviceClient, Settings settings)
 {
     ProcessGlobalParameters(serviceClient);
     FlattenModels(serviceClient);
     FlattenMethodParameters(serviceClient, settings);
     ParameterGroupExtensionHelper.AddParameterGroups(serviceClient);
     ProcessParameterizedHost(serviceClient, settings);
 }
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClient"></param>
 public override void NormalizeClientModel(ServiceClient serviceClient)
 {
     SwaggerExtensions.NormalizeClientModel(serviceClient, Settings);
     PopulateAdditionalProperties(serviceClient);
     Namer.NormalizeClientModel(serviceClient);
     Namer.ResolveNameCollisions(serviceClient, Settings.Namespace,
         Settings.Namespace + ".Models");
     Namer.NormalizeOdataFilterParameter(serviceClient);
 }
 public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ServiceClient = serviceClient;
     if (source.BaseModelType != null)
     {
         _parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
     }
 }
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClient">The service client.</param>
 public override void NormalizeClientModel(ServiceClient serviceClient)
 {
     Settings.AddCredentials = true;
     AzureExtensions.NormalizeAzureClientModel(serviceClient, Settings, CodeNamer);
     CorrectFilterParameters(serviceClient);
     base.NormalizeClientModel(serviceClient);
     AddRubyPageableMethod(serviceClient);
     ApplyPagination(serviceClient);
 }
 /// <summary>
 /// Initializes a new instance of ServiceClientTemplateModel class.
 /// </summary>
 /// <param name="serviceClient"></param>
 public ServiceClientTemplateModel(ServiceClient serviceClient)
 {
     this.LoadFrom(serviceClient);
     HasModelTypes = serviceClient.HasModelTypes();
     MethodTemplateModels = new List<MethodTemplateModel>();
     Methods.Where(m => m.Group == null)
         .ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient)));
     this.IsCustomBaseUri = serviceClient.Extensions.ContainsKey(SwaggerExtensions.ParameterizedHostExtension);
 }
 public AzureMethodGroupTemplateModel(ServiceClient serviceClient, string methodGroupName)
     : base(serviceClient, methodGroupName)
 {
     // Clear base initialized MethodTemplateModels and re-populate with
     // AzureMethodTemplateModel
     MethodTemplateModels.Clear();
     Methods.Where(m => m.Group == methodGroupName)
         .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
 }
 public ServiceClientTemplateModel(ServiceClient serviceClient, bool internalConstructors)
 {
     this.LoadFrom(serviceClient);
     MethodTemplateModels = new List<MethodTemplateModel>();
     Methods.Where(m => m.Group == null)
         .ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient, SyncMethodsGenerationMode.None)));
     ConstructorVisibility = internalConstructors ? "internal" : "public";
     this.IsCustomBaseUri = serviceClient.Extensions.ContainsKey(SwaggerExtensions.ParameterizedHostExtension);
 }
 public PackageInfoTemplateModel(ServiceClient serviceClient, string clientName, string subPackage = null)
 {
     this.LoadFrom(serviceClient);
     this.Title = clientName;
     if (serviceClient != null)
     {
         this.Description = serviceClient.Documentation;
     }
     this.SubPackage = subPackage;
 }
        public MethodGroupTemplateModel(ServiceClient serviceClient, string packageName, string methodGroupName)
            : base(serviceClient, packageName, methodGroupName)
        {
            this.LoadFrom(serviceClient);

            Documentation = string.Format("{0} is the {1} ", ClientName,
                                    string.IsNullOrEmpty(Documentation)
                                        ? string.Format("client for the {0} methods of the {1} service.", MethodGroupName, ServiceName)
                                        : Documentation.ToSentence());
        }
        private static void NormalizeApiVersion(ServiceClient serviceClient)
        {
            serviceClient.Properties.Where(
                p => p.SerializedName.Equals(AzureExtensions.ApiVersion, StringComparison.OrdinalIgnoreCase))
                .ForEach(p => p.DefaultValue = p.DefaultValue.Replace("\"", "'"));

            serviceClient.Properties.Where(
                p => p.SerializedName.Equals(AzureExtensions.AcceptLanguage, StringComparison.OrdinalIgnoreCase))
                .ForEach(p => p.DefaultValue = p.DefaultValue.Replace("\"", "'"));
        }
 public AzureServiceClientTemplateModel(ServiceClient serviceClient)
     : base(serviceClient)
 {
     Properties.Remove(Properties.Find(p => p.Type.Name == "ServiceClientCredentials"));
     MethodTemplateModels.Clear();
     Methods.Where(m => m.Group == null)
         .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
     ModelTemplateModels.Clear();
     ModelTypes.ForEach(m => ModelTemplateModels.Add(new AzureModelTemplateModel(m, serviceClient)));
 }
 public AzureMethodGroupTemplateModel(ServiceClient serviceClient, string methodGroupName)
     : base(serviceClient, methodGroupName)
 {
     MethodGroupType = MethodGroupName + "Operations";
     // Clear base initialized MethodTemplateModels and re-populate with
     // AzureMethodTemplateModel
     MethodTemplateModels.Clear();
     Methods.Where(m => m.Group == methodGroupName)
         .ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient, SyncMethodsGenerationMode.None)));
 }