public EnumTemplateModel(EnumType source)
 {
     this.LoadFrom(source);
 }
Esempio n. 2
0
 private IType NormalizeEnumType(EnumType enumType)
 {
     for (int i = 0; i < enumType.Values.Count; i++)
     {
         enumType.Values[i].Name = GetEnumMemberName(enumType.Values[i].Name);
     }
     return enumType;
 }
 private IType NormalizeEnumType(EnumType enumType)
 {
     if (enumType.IsExpandable)
     {
         enumType.SerializedName = "string";
         enumType.Name = "string";
     }
     else
     {
         enumType.Name = GetTypeName(enumType.Name) + "?";
     }
     for (int i = 0; i < enumType.Values.Count; i++)
     {
         enumType.Values[i].Name = GetEnumMemberName(enumType.Values[i].Name);
     }
     return enumType;
 }
Esempio n. 4
0
        /// <summary>
        /// The visitor method for building service types. This is called when an instance of this class is
        /// visiting a _swaggerModeler to build a service type.
        /// </summary>
        /// <param name="serviceTypeName">name for the service type</param>
        /// <returns>built service type</returns>
        public virtual IType BuildServiceType(string serviceTypeName)
        {
            PrimaryType type = SwaggerObject.ToType();
            if (SwaggerObject.Enum != null && SwaggerObject.Enum.Any() && type == PrimaryType.String)
            {
                var enumType = new EnumType();
                SwaggerObject.Enum.ForEach(v => enumType.Values.Add(new EnumValue { Name = v, SerializedName = v }));
                if (SwaggerObject.Extensions.ContainsKey(CodeGenerator.EnumObject))
                {
                    var enumObject = SwaggerObject.Extensions[CodeGenerator.EnumObject] as Newtonsoft.Json.Linq.JContainer;
                    if (enumObject != null)
                    {
                        enumType.Name= enumObject["name"].ToString();
                        if (enumObject["modelAsString"] != null)
                        {
                            enumType.ModelAsString = bool.Parse(enumObject["modelAsString"].ToString());
                        }
                    }
                    enumType.SerializedName = enumType.Name;
                    if (string.IsNullOrEmpty(enumType.Name))
                    {
                        throw new InvalidOperationException(
                            string.Format(CultureInfo.InvariantCulture, 
                                "{0} extension needs to specify an enum name.", 
                                CodeGenerator.EnumObject));
                    }
                    var existingEnum =
                        Modeler.ServiceClient.EnumTypes.FirstOrDefault(
                            e => e.Name.Equals(enumType.Name, StringComparison.OrdinalIgnoreCase));
                    if (existingEnum != null)
                    {
                        if (!existingEnum.Equals(enumType))
                        {
                            throw new InvalidOperationException(
                                string.Format(CultureInfo.InvariantCulture,
                                    "Swagger document contains two or more {0} extensions with the same name '{1}' and different values.",
                                    CodeGenerator.EnumObject,
                                    enumType.Name));
                        }
                    }
                    else
                    {
                        Modeler.ServiceClient.EnumTypes.Add(enumType);
                    }
                }
                else
                {
                    enumType.ModelAsString = true;
                    enumType.Name = string.Empty;
                    enumType.SerializedName = string.Empty;
                }
                return enumType;
            }
            if (SwaggerObject.Type == DataType.Array)
            {
                string itemServiceTypeName;
                if (SwaggerObject.Items.Reference != null)
                {
                    itemServiceTypeName = SwaggerObject.Items.Reference.StripDefinitionPath();
                }
                else
                {
                    itemServiceTypeName = serviceTypeName + "Item";
                }

                var elementType =
                    SwaggerObject.Items.GetBuilder(Modeler).BuildServiceType(itemServiceTypeName);
                return new SequenceType
                {
                    ElementType = elementType
                };
            }
            if (SwaggerObject.AdditionalProperties != null)
            {
                string dictionaryValueServiceTypeName;
                if (SwaggerObject.AdditionalProperties.Reference != null)
                {
                    dictionaryValueServiceTypeName = SwaggerObject.AdditionalProperties.Reference.StripDefinitionPath();
                }
                else
                {
                    dictionaryValueServiceTypeName = serviceTypeName + "Value";
                }
                return new DictionaryType
                {
                    ValueType =
                        SwaggerObject.AdditionalProperties.GetBuilder(Modeler)
                            .BuildServiceType((dictionaryValueServiceTypeName))
                };
            }

            return type;
        }
Esempio n. 5
0
        /// <summary>
        /// Normalizes enum type.
        /// </summary>
        /// <param name="enumType">The enum type.</param>
        /// <returns>Normalized enum type.</returns>
        private IType NormalizeEnumType(EnumType enumType)
        {
            for (int i = 0; i < enumType.Values.Count; i++)
            {
                if (enumType.Values[i].Name != null)
                {
                    enumType.Values[i].Name = GetEnumMemberName(RubyRemoveInvalidCharacters(enumType.Values[i].Name));
                }
            }

            return enumType;
        }
 public AzureEnumTemplateModel(EnumType source)
     : base(source)
 {
 }
Esempio n. 7
0
 public EnumTypeModel(EnumType enumType, string package)
     : base()
 {
     this.LoadFrom(enumType);
     this._package = package.ToLower(CultureInfo.InvariantCulture);
 }
 private static IType NormalizeEnumType(EnumType enumType)
 {
     return enumType;
 }
Esempio n. 9
0
        private static JsonSchema ParseEnumType(EnumType enumType)
        {
            JsonSchema result = new JsonSchema();

            result.JsonType = "string";
            foreach (EnumValue enumValue in enumType.Values)
            {
                result.AddEnum(enumValue.Name);
            }

            return result;
        }
 public FluentEnumTypeModel(EnumType enumType, string package)
     : base(enumType, package)
 {
     this._package = package.ToLower(CultureInfo.InvariantCulture);
 }
 protected override EnumTypeModel NewEnumTypeModel(EnumType enumType)
 {
     return new FluentEnumTypeModel(enumType, _package);
 }
Esempio n. 12
0
 protected virtual EnumTypeModel NewEnumTypeModel(EnumType enumType)
 {
     return new EnumTypeModel(enumType, _package);
 }
 public void GetResourceTypesWithParameterReferenceWithParameterDefinitionWithEnumTypeWithMultipleValues()
 {
     const string provider = "Microsoft.Network";
     const string pathAfterProvider = "dnszones/{zoneName}/{recordType}/{relativeRecordSetName}";
     EnumType enumType = new EnumType();
     enumType.Values.Add(new EnumValue() { Name = "A" });
     enumType.Values.Add(new EnumValue() { Name = "AAAA" });
     enumType.Values.Add(new EnumValue() { Name = "CNAME" });
     enumType.Values.Add(new EnumValue() { Name = "MX" });
     List<Parameter> methodParameters = new List<Parameter>()
     {
         new Parameter()
         {
             Name = "recordType",
             Type = enumType
         }
     };
     Assert.Equal(
         new string[]
         {
             "Microsoft.Network/dnszones/A",
             "Microsoft.Network/dnszones/AAAA",
             "Microsoft.Network/dnszones/CNAME",
             "Microsoft.Network/dnszones/MX"
         },
         ResourceSchemaParser.GetResourceTypes(provider, pathAfterProvider, methodParameters));
 }