Ejemplo n.º 1
0
 /// <summary>
 /// Execute this template against the specified model
 /// </summary>
 /// <param name="model"></param>
 /// <param name="m"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public virtual string ExecuteTemplate(OkapiInfo api, OkapiMethodInfo method, OkapiModelInfo model, OkapiEnumInfo enumDataType)
 {
     Buffer.Clear();
     SwaggerModel = api;
     MethodModel  = method;
     ClassModel   = model;
     EnumModel    = enumDataType;
     Execute();
     return(Buffer.ToString());
 }
Ejemplo n.º 2
0
        private static void ExtractEnum(List <OkapiEnumInfo> enums, SwaggerProperty prop)
        {
            // Determine enum value comments and description, if any
            string xEnumDescription = null;
            Dictionary <string, string> xEnumValueComments = null;

            if (prop != null && prop.Extended != null)
            {
                xEnumDescription = prop.Extended["x-enum-description"] as string;
                JObject j = prop.Extended["x-enum-value-comments"] as JObject;
                if (j != null)
                {
                    xEnumValueComments = j.ToObject <Dictionary <string, string> >();
                }
            }

            // Load up the enum
            var enumType = (from e in enums where e.EnumDataType == prop.EnumDataType select e).FirstOrDefault();

            if (enumType == null)
            {
                enumType = new OkapiEnumInfo()
                {
                    EnumDataType = prop.EnumDataType,
                    Comment      = xEnumDescription,
                    Items        = new List <OkapiEnumValue>()
                };
                enums.Add(enumType);
            }

            // Add values if they are known
            if (prop.enumValues != null)
            {
                foreach (var s in prop.enumValues)
                {
                    if (!enumType.Items.Any(i => i.Value == s))
                    {
                        // Figure out the comment for the enum, if one is available
                        string comment = null;
                        if (xEnumValueComments != null)
                        {
                            xEnumValueComments.TryGetValue(s, out comment);
                        }
                        enumType.Items.Add(new OkapiEnumValue()
                        {
                            Value = s, Comment = comment
                        });
                    }
                }
            }
        }