public void Apply(Swashbuckle.Application.SwaggerDocsConfig c)
		{
			c.ApiKey(Key)
				.Name(Name)
				.Description(Description)
				.In(In);
			c.DocumentFilter(() => this);
			c.OperationFilter(() => this);
		}
        /// <summary>
        /// Filter and add Security JWT definition to all accion with has "AuthorizaAttribute"
        /// </summary>
        /// <param name="operation">Operation</param>
        /// <param name="schemaRegistry">Schema</param>
        /// <param name="apiDescription">Description for the api</param>
        public void Apply(Swashbuckle.Swagger.Operation operation, Swashbuckle.Swagger.SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
        {
            if (
                apiDescription.ActionDescriptor.GetFilters().OfType<AuthorizeAttribute>().Any() ||
                apiDescription.ActionDescriptor.ControllerDescriptor.GetFilters().OfType<AuthorizeAttribute>().Any()
                )
            {
                if (operation.security == null)
                    operation.security = new List<IDictionary<string, IEnumerable<string>>>();

                var oAuthRequirements = new Dictionary<string, IEnumerable<string>>();
                oAuthRequirements.Add(_securityDefinitionNameSchema, new List<string>());

                operation.security.Add(oAuthRequirements);

            }
        }
Beispiel #3
0
        public Pangolier(Unit9 owner, MultiSleeper abilitySleeper, Sleeper orbwalkSleeper, ControllableUnitMenu menu)
            : base(owner, abilitySleeper, orbwalkSleeper, menu)
        {
            this.ComboAbilities = new Dictionary <AbilityId, Func <ActiveAbility, UsableAbility> >
            {
                { AbilityId.pangolier_swashbuckle, x => this.swashbuckle = new Swashbuckle(x) },
                { AbilityId.pangolier_shield_crash, x => this.crash = new ShieldCrash(x) },
                { AbilityId.pangolier_gyroshell, x => this.thunder = new RollingThunder(x) },

                { AbilityId.item_diffusal_blade, x => this.diffusal = new DebuffAbility(x) },
                { AbilityId.item_abyssal_blade, x => this.abyssal = new DisableAbility(x) },
                { AbilityId.item_mjollnir, x => this.mjollnir = new ShieldAbility(x) },
                { AbilityId.item_blink, x => this.blink = new BlinkDaggerPangolier(x) },
            };

            this.MoveComboAbilities.Add(AbilityId.pangolier_swashbuckle, x => this.moveSwashbuckle = new SwashbuckleBlink(x));

            Player.OnExecuteOrder += this.OnExecuteOrder;
        }
        public void Apply(Swashbuckle.Swagger.Operation operation, Swashbuckle.Swagger.SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
        {
            #region Add Documentation Nodes
            string TModel = null;

            Type BlueprintController = apiDescription.ActionDescriptor.ControllerDescriptor.ControllerType.BaseType;
            if (BlueprintController.IsGenericType)
            {
                Type modelType = BlueprintController.GetGenericArguments()[0];
                TModel = modelType.Name;

                //Remove all Auto DB generated Properties
                CleanModel(schemaRegistry, modelType);
            }

            if (apiDescription.HttpMethod == System.Net.Http.HttpMethod.Get)
            {
                operation.summary = String.Format(Gale.REST.Resources.SwasbuckleExtension_Blueprint_GET, TModel);
                operation.description = String.Format(Gale.REST.Resources.SwasbuckleExtension_Blueprint_GET_ImplementationNotes, Gale.REST.Resources.GALE_DOCS_SITE);

                #region OData Parameter's
                operation.parameters = new List<Swashbuckle.Swagger.Parameter>();
                operation.parameters.Add(new Swashbuckle.Swagger.Parameter()
                {
                    name = "$select",
                    description = "Fields selector (comma separated)",
                    @in= "query",
                    required = false,
                    type = "string"
                });

                operation.parameters.Add(new Swashbuckle.Swagger.Parameter()
                {
                    name = "$filter",
                    description = "collection of filter's (comma separated): {field} {operator} {value}",
                    @in = "query",
                    required = false,
                    type = "string"
                });

                operation.parameters.Add(new Swashbuckle.Swagger.Parameter()
                {
                    name = "$orderBy",
                    description = "Order by clause: {field} (asc|desc)",
                    @in = "query",
                    required = false,
                    type = "string"
                });

                operation.parameters.Add(new Swashbuckle.Swagger.Parameter()
                {
                    name = "$limit",
                    description = "Limit the number of records returned",
                    @in = "query",
                    required = false,
                    type = "number"
                });

                operation.parameters.Add(new Swashbuckle.Swagger.Parameter()
                {
                    name = "$offset",
                    description = "Skip records before returning anything",
                    @in = "query",
                    required = false,
                    type = "number"
                });
                #endregion
            }
            else if (apiDescription.HttpMethod == System.Net.Http.HttpMethod.Post)
            {
                operation.summary = String.Format(Gale.REST.Resources.SwasbuckleExtension_Blueprint_POST, TModel); ;
                operation.description = String.Format(Gale.REST.Resources.SwasbuckleExtension_Blueprint_POST_ImplementationNotes, TModel);
            }
            else if (apiDescription.HttpMethod == System.Net.Http.HttpMethod.Put)
            {
                operation.summary = String.Format(Gale.REST.Resources.SwasbuckleExtension_Blueprint_PUT, TModel); ;
            }
            else if (apiDescription.HttpMethod == System.Net.Http.HttpMethod.Delete)
            {
                operation.summary = String.Format(Gale.REST.Resources.SwasbuckleExtension_Blueprint_DELETE, TModel); ;
            }
            #endregion
        }
        /// <summary>
        /// Remove 
        /// </summary>
        /// <param name="schemaRegistry"></param>
        private void CleanModel(Swashbuckle.Swagger.SchemaRegistry schemaRegistry, Type TModel)
        {
            if (schemaRegistry.Definitions.Any((definition) => definition.Key == TModel.Name))
            {
                //Remove All Auto-Generated DB Properties
                var swaggerDefinition = schemaRegistry.Definitions[TModel.Name];
                var fieldProperties = TModel.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(System.Data.Linq.Mapping.ColumnAttribute))).ToList();
                foreach (System.Reflection.PropertyInfo property in fieldProperties)
                {
                    var attr = property.TryGetAttribute<System.Data.Linq.Mapping.ColumnAttribute>();

                    //Only if Auto DB Generated Key
                    if (attr.IsDbGenerated)
                    {
                        if (swaggerDefinition.properties.Any((prop) => prop.Key == property.Name))
                        {
                            swaggerDefinition.properties.Remove(property.Name);
                        }
                    }

                }
            }
        }