コード例 #1
0
        public void ShouldBeAbleToSetRequired()
        {
            // Act
            builder.Required(true);

            // Assert
            builder.Data.Required.ShouldBeTrue();
        }
コード例 #2
0
        public SwaggerModelData GetModelData()
        {
            return(SwaggerModelData.ForType <T>(with => {
                System.Attribute[] attrs = System.Attribute.GetCustomAttributes(this.GetType());
                foreach (System.Attribute attr in attrs)
                {
                    if (attr is ModelDoc)
                    {
                        ModelDoc attr_doc = (ModelDoc)attr;
                        with.Description(attr_doc.Description);
                        var member_info = this.GetType().GetProperties();

                        List <Tuple <PropertyDoc, string> > prop_doc_list = new List <Tuple <PropertyDoc, string> >();
                        for (int i = 0; i < member_info.Length; i++)
                        {
                            PropertyDoc attr_prop = (PropertyDoc)System.Attribute.GetCustomAttribute(member_info[i], typeof(PropertyDoc));
                            if (attr_prop != null && attr_prop is PropertyDoc)
                            {
                                var tup = new Tuple <PropertyDoc, string>(attr_prop, member_info[i].Name);
                                prop_doc_list.Add(tup);
                            }
                        }

                        // put PropertyDoc in order
                        List <Tuple <PropertyDoc, string> > ordered_list = prop_doc_list.OrderBy(p => p.Item1.Index).ToList();
                        foreach (Tuple <PropertyDoc, string> attr_prop_tup in ordered_list)
                        {
                            PropertyDoc attr_prop = attr_prop_tup.Item1;
                            string attr_prop_name = attr_prop_tup.Item2;

                            var propertyData = with.Data.Properties.First(d => d.Name == attr_prop_name);
                            var swaggerData = new SwaggerModelPropertyDataBuilder <Object>(propertyData);
                            swaggerData.Description(attr_prop.Description);
                            if (attr_prop.RequiredHasValue)
                            {
                                swaggerData.Required(attr_prop.Required);
                            }
                            if (attr_prop.MinimumHasValue)
                            {
                                swaggerData.Minimum(attr_prop.Minimum);
                            }
                            if (attr_prop.MaximumHasValue)
                            {
                                swaggerData.Maximum(attr_prop.Maximum);
                            }
                            if (attr_prop.EnumValuesHasValue)
                            {
                                swaggerData.Enum(attr_prop.EnumValues);
                            }
                        }
                    }
                }
            }));
        }
コード例 #3
0
        public void ShouldBeAbleToSetRequired()
        {
            builder.Required(true);

            builder.Data.Required.ShouldBeTrue();
        }