示例#1
0
        public EnumTemplateModel(EnumType source)
        {
            this.LoadFrom(source);

            // Assume members have unique names
            HasUniqueNames = true;

            if (string.IsNullOrEmpty(Documentation))
            {
                Documentation = string.Format("{0} enumerates the values for {1}.", Name, Name.ToPhrase());
            }
        }
        private static JsonSchema ParseEnumType(Property property, EnumType enumType)
        {
            JsonSchema result = new JsonSchema()
            {
                JsonType = "string"
            };

            foreach (EnumValue enumValue in enumType.Values)
            {
                result.AddEnum(enumValue.Name);
            }

            if (property != null)
            {
                result.Description = RemovePossibleValuesFromDescription(property.Documentation);
            }

            return result;
        }
 public AzureFluentEnumTemplateModel(EnumType source)
     : base(source)
 {
 }
示例#4
0
        /// <summary>
        /// Normalizes enum type.
        /// </summary>
        /// <param name="enumType">The enum type.</param>
        /// <returns>Normalized enum type.</returns>
        private IType NormalizeEnumType(EnumType enumType)
        {
            if (!String.IsNullOrWhiteSpace(enumType.Name))
            {
                enumType.Name = PascalCase(RemoveInvalidCharacters(enumType.Name));
            }
            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;
        }
示例#5
0
 private static IType NormalizeEnumType(EnumType enumType)
 {
     return enumType;
 }
示例#6
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();
            Debug.Assert(type != null);

            if (type.Type == KnownPrimaryType.Object && "file".Equals(SwaggerObject.Format, StringComparison.OrdinalIgnoreCase))
            {
                type = new PrimaryType(KnownPrimaryType.Stream);
            }
            type.Format = SwaggerObject.Format;
            if (SwaggerObject.Enum != null && type.Type == KnownPrimaryType.String && !(IsSwaggerObjectConstant(SwaggerObject)))
            {
                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;
        }
示例#7
0
        private IType NormalizeEnumType(EnumType enumType)
        {
            // Enumerated types normalize to the same object
            _normalizedTypes[enumType] = enumType;

            // gosdk: Default unnamed Enumerated types to "string"
            if (String.IsNullOrEmpty(enumType.Name) || enumType.Values.Any(v => v == null || string.IsNullOrEmpty(v.Name)))
            {
                enumType.Name = "string";
                enumType.SerializedName = "string";
            }
            else
            {
                enumType.SerializedName = enumType.Name;
                enumType.Name = GetTypeName(enumType.Name);

                foreach (var value in enumType.Values)
                {
                    value.SerializedName = value.Name;
                    value.Name = GetEnumMemberName(value.Name);
                }
            }

            return enumType;
        }
示例#8
0
        private IType NormalizeEnumType(EnumType enumType)
        {
            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;
        }
示例#9
0
 protected virtual EnumTypeModel NewEnumTypeModel(EnumType enumType)
 {
     return new EnumTypeModel(enumType, _package);
 }
示例#10
0
 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);
 }
示例#12
0
 public EnumTemplateModel(EnumType source)
 {
     this.LoadFrom(source);
 }
示例#13
0
 public EnumTypeModel(EnumType enumType, string package)
     : base()
 {
     this.LoadFrom(enumType);
     this._package = package.ToLower(CultureInfo.InvariantCulture);
 }