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;
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }