public override CodeModelJv TransformCodeModel(CodeModel cm)
        {
            var codeModel = cm as CodeModelJva;

            // we're guaranteed to be in our language-specific context here.
            Settings.Instance.AddCredentials = true;

            // This extension from general extensions must be run prior to Azure specific extensions.
            AzureExtensions.ProcessParameterizedHost(codeModel);
            AzureExtensions.ProcessClientRequestIdExtension(codeModel);
            AzureExtensions.UpdateHeadMethods(codeModel);
            AzureExtensions.ProcessGlobalParameters(codeModel);
            AzureExtensions.FlattenModels(codeModel);
            AzureExtensions.FlattenMethodParameters(codeModel);
            ParameterGroupExtensionHelper.AddParameterGroups(codeModel);
            AddLongRunningOperations(codeModel);
            AzureExtensions.AddAzureProperties(codeModel);
            AzureExtensions.SetDefaultResponses(codeModel);

            // set Parent on responses (required for pageable)
            foreach (MethodJva method in codeModel.Methods)
            {
                foreach (ResponseJva response in method.Responses.Values)
                {
                    response.Parent = method;
                }
                (method.DefaultResponse as ResponseJva).Parent = method;
                method.ReturnTypeJva.Parent = method;
            }
            AzureExtensions.AddPageableMethod(codeModel);

            // pluralize method groups
            foreach (var mg in codeModel.Operations)
            {
                mg.Name.OnGet += name => name.IsNullOrEmpty() || name.EndsWith("s", StringComparison.OrdinalIgnoreCase) ? $"{name}" : $"{name}s";
            }

            NormalizePaginatedMethods(codeModel, codeModel.pageClasses);

            // determine inner models
            NormalizeTopLevelTypes(codeModel);

            // param order (PATH first)
            foreach (MethodJva method in codeModel.Methods)
            {
                var ps = method.Parameters.ToList();
                method.ClearParameters();
                foreach (var p in ps.Where(x => x.Location == ParameterLocation.Path))
                {
                    method.Add(p);
                }
                foreach (var p in ps.Where(x => x.Location != ParameterLocation.Path))
                {
                    method.Add(p);
                }
            }

            return(codeModel);
        }
Exemple #2
0
 /// <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.UpdateHeadMethods(serviceClient);
     AzureExtensions.ParseODataExtension(serviceClient);
     AzureExtensions.AddPageableMethod(serviceClient, CodeNamer);
     AzureExtensions.AddLongRunningOperations(serviceClient);
     AzureExtensions.AddAzureProperties(serviceClient);
     AzureExtensions.SetDefaultResponses(serviceClient);
     CorrectFilterParameters(serviceClient);
     base.NormalizeClientModel(serviceClient);
 }
Exemple #3
0
        /// <summary>
        /// Normalizes client model by updating names and types to be language specific.
        /// </summary>
        /// <param name="serviceClient"></param>
        public override void NormalizeClientModel(ServiceClient serviceClient)
        {
            // Don't add pagable/longrunning method since we already handle ourself.
            Settings.AddCredentials = true;
            AzureExtensions.UpdateHeadMethods(serviceClient);
            AzureExtensions.ParseODataExtension(serviceClient);
            AzureExtensions.FlattenResourceProperties(serviceClient);
            AzureExtensions.AddAzureProperties(serviceClient);
            AzureExtensions.SetDefaultResponses(serviceClient);
            AzureExtensions.AddParameterGroups(serviceClient);

            base.NormalizeClientModel(serviceClient);
            NormalizeApiVersion(serviceClient);
            NormalizePaginatedMethods(serviceClient);
        }
Exemple #4
0
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClient"></param>
 public override void NormalizeClientModel(ServiceClient serviceClient)
 {
     Settings.AddCredentials = true;
     AzureExtensions.UpdateHeadMethods(serviceClient);
     AzureExtensions.ParseODataExtension(serviceClient);
     AzureExtensions.FlattenResourceProperties(serviceClient);
     AzureExtensions.AddPageableMethod(serviceClient, _namer);
     AzureExtensions.AddAzureProperties(serviceClient);
     AzureExtensions.SetDefaultResponses(serviceClient);
     AzureExtensions.AddParameterGroups(serviceClient);
     _namer.NormalizeClientModel(serviceClient);
     _namer.ResolveNameCollisions(serviceClient, Settings.Namespace,
                                  Settings.Namespace + ".Models");
     _namer.NormalizePaginatedMethods(serviceClient, pageClasses);
     ExtendAllResourcesToBaseResource(serviceClient);
 }
        /// <summary>
        /// Creates azure specific properties.
        /// </summary>
        /// <param name="codeModelient"></param>
        private static void AddAzureProperties(CodeModel codeModel)
        {
            var acceptLanguage = codeModel.Properties
                                 .FirstOrDefault(p => AzureExtensions.AcceptLanguage.EqualsIgnoreCase(p.SerializedName));

            AzureExtensions.AddAzureProperties(codeModel);
            codeModel.Remove(codeModel.Properties.FirstOrDefault(p => p.Name == "long_running_operation_retry_timeout"));
            codeModel.Remove(codeModel.Properties.FirstOrDefault(p => p.Name == "generate_client_request_id"));
            codeModel.Remove(codeModel.Properties.FirstOrDefault(p => p.Name == "accept_language"));

            if (acceptLanguage != null) // && acceptLanguage.DefaultValue != "en-US"
            {
                acceptLanguage.IsReadOnly = true;
                acceptLanguage.IsRequired = false;
                acceptLanguage.ModelType  = New <PrimaryType>(KnownPrimaryType.String);
                codeModel.Add(acceptLanguage);
            }
        }
Exemple #6
0
        /// <summary>
        /// Normalizes client model by updating names and types to be language specific.
        /// </summary>
        /// <param name="serviceClient"></param>
        public override void NormalizeClientModel(ServiceClient serviceClient)
        {
            Settings.AddCredentials = true;

            // This extension from general extensions must be run prior to Azure specific extensions.
            AzureExtensions.ProcessParameterizedHost(serviceClient, Settings);
            AzureExtensions.ProcessClientRequestIdExtension(serviceClient);
            AzureExtensions.UpdateHeadMethods(serviceClient);
            AzureExtensions.FlattenModels(serviceClient);
            AzureExtensions.FlattenMethodParameters(serviceClient, Settings);
            ParameterGroupExtensionHelper.AddParameterGroups(serviceClient);
            AzureExtensions.AddLongRunningOperations(serviceClient);
            AzureExtensions.AddAzureProperties(serviceClient);
            AzureExtensions.SetDefaultResponses(serviceClient);
            AzureExtensions.AddPageableMethod(serviceClient, _namer);
            _namer.NormalizeClientModel(serviceClient);
            _namer.ResolveNameCollisions(serviceClient, Settings.Namespace,
                                         Settings.Namespace + ".Models");
            _namer.NormalizePaginatedMethods(serviceClient, pageClasses);
        }
        public override CodeModelPya TransformCodeModel(CodeModel cm)
        {
            var codeModel = (CodeModelPya)cm;

            TransformPagingMethods(codeModel);
            // Don't add pagable/longrunning method since we already handle ourself.
            Settings.Instance.AddCredentials = true;

            AzureExtensions.ProcessClientRequestIdExtension(codeModel);
            AzureExtensions.UpdateHeadMethods(codeModel);
            AzureExtensions.ParseODataExtension(codeModel);
            SwaggerExtensions.FlattenModels(codeModel);
            ParameterGroupExtensionHelper.AddParameterGroups(codeModel);
            AzureExtensions.AddAzureProperties(codeModel);
            AzureExtensions.SetDefaultResponses(codeModel);
            CorrectFilterParameters(codeModel);

            Base.TransformCodeModel(codeModel);

            NormalizePaginatedMethods(codeModel);

            return(codeModel);
        }