/// <summary> /// Initializes a new instance of <see cref="ApplicationModel"/>. /// </summary> public ApplicationModel() { ApiExplorer = new ApiExplorerModel(); Controllers = new List <ControllerModel>(); Filters = new List <IFilterMetadata>(); Properties = new Dictionary <object, object?>(); }
/// <summary> /// Initializes a new instance of <see cref="ControllerModel"/>. /// </summary> /// <param name="other">The other controller model.</param> public ControllerModel(ControllerModel other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } ControllerName = other.ControllerName; ControllerType = other.ControllerType; // Still part of the same application Application = other.Application; // These are just metadata, safe to create new collections Attributes = new List <object>(other.Attributes); Filters = new List <IFilterMetadata>(other.Filters); RouteValues = new Dictionary <string, string?>(other.RouteValues, StringComparer.OrdinalIgnoreCase); Properties = new Dictionary <object, object?>(other.Properties); // Make a deep copy of other 'model' types. Actions = new List <ActionModel>(other.Actions.Select(a => new ActionModel(a) { Controller = this })); ApiExplorer = new ApiExplorerModel(other.ApiExplorer); ControllerProperties = new List <PropertyModel>(other.ControllerProperties.Select(p => new PropertyModel(p) { Controller = this })); Selectors = new List <SelectorModel>(other.Selectors.Select(s => new SelectorModel(s))); }
/// <summary> /// Copy constructor for <see cref="ActionModel"/>. /// </summary> /// <param name="other">The <see cref="ActionModel"/> to copy.</param> public ActionModel(ActionModel other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } ActionMethod = other.ActionMethod; ActionName = other.ActionName; RouteParameterTransformer = other.RouteParameterTransformer; // Not making a deep copy of the controller, this action still belongs to the same controller. Controller = other.Controller; // These are just metadata, safe to create new collections Attributes = new List <object>(other.Attributes); Filters = new List <IFilterMetadata>(other.Filters); Properties = new Dictionary <object, object?>(other.Properties); RouteValues = new Dictionary <string, string?>(other.RouteValues, StringComparer.OrdinalIgnoreCase); // Make a deep copy of other 'model' types. ApiExplorer = new ApiExplorerModel(other.ApiExplorer); Parameters = new List <ParameterModel>(other.Parameters.Select(p => new ParameterModel(p) { Action = this })); Selectors = new List <SelectorModel>(other.Selectors.Select(s => new SelectorModel(s))); }
/// <summary> /// Initializes a new instance of <see cref="ControllerModel"/>. /// </summary> /// <param name="controllerType">The type of the controller.</param> /// <param name="attributes">The attributes.</param> public ControllerModel( TypeInfo controllerType, IReadOnlyList <object> attributes) { if (controllerType == null) { throw new ArgumentNullException(nameof(controllerType)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } ControllerType = controllerType; Actions = new List <ActionModel>(); ApiExplorer = new ApiExplorerModel(); Attributes = new List <object>(attributes); ControllerProperties = new List <PropertyModel>(); Filters = new List <IFilterMetadata>(); Properties = new Dictionary <object, object?>(); RouteValues = new Dictionary <string, string?>(StringComparer.OrdinalIgnoreCase); Selectors = new List <SelectorModel>(); }
public ApiExplorerModelValues(ApiExplorerModel inner) { if (inner != null) { IsVisible = inner.IsVisible; GroupName = inner.GroupName; } }
/// <summary> /// Creates a new <see cref="ApiExplorerModel"/> with properties copied from <paramref name="other"/>. /// </summary> /// <param name="other">The <see cref="ApiExplorerModel"/> to copy.</param> public ApiExplorerModel(ApiExplorerModel other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } GroupName = other.GroupName; IsVisible = other.IsVisible; }
public void Apply(ApplicationModel application) { for (var i = 0; i < application.Controllers.Count; i++) { var controller = application.Controllers[i]; if (!controller.ControllerType.IsODataController()) { continue; } if (controller.ApiExplorer == null) { var model = new ApiExplorerModel(); var attribute = controller.Attributes.OfType <ApiExplorerSettingsAttribute>().FirstOrDefault(); if (attribute != null) { model.GroupName = attribute.GroupName; model.IsVisible = !attribute.IgnoreApi; } controller.ApiExplorer = new ODataApiExplorerModel(model); } else if (!(controller.ApiExplorer is ODataApiExplorerModel)) { controller.ApiExplorer = new ODataApiExplorerModel(controller.ApiExplorer); } for (var j = 0; j < controller.Actions.Count; j++) { var action = controller.Actions[j]; if (action.ApiExplorer == null) { action.ApiExplorer = controller.ApiExplorer; } else if (!(action.ApiExplorer is ODataApiExplorerModel)) { action.ApiExplorer = new ODataApiExplorerModel(action.ApiExplorer); } action.SetProperty(action.ApiExplorer); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // ApiDescriptionGroupCollectionProvider provider = new ApiDescriptionGroupCollectionProvider(null, null); // DefaultApiDescriptionProvider provider = new DefaultApiDescriptionProvider(null, null, null, null, null); // ActionModel action = new ActionModel(null); // ControllerModel m = new ControllerModel(null); ApiExplorerModel apiModel = new ApiExplorerModel(); apiModel.IsVisible = true; ApiExplorerModel another = new ApiExplorerModel(apiModel); IEdmModel model = EdmModelBuilder.GetEdmModel(); app.UseRouting(); app.UseAuthorization(); app.UseODataBatching(); app.UseEndpoints(endpoints => { endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count(); endpoints.MapODataRoute("nullPrefix", null, model); endpoints.MapODataRoute("odataPrefix", "odata", model); endpoints.MapODataRoute("myPrefix", "my/{data}", model); endpoints.MapODataRoute("msPrefix", "ms", model, new DefaultODataBatchHandler()); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("v1/swagger.json", "Test API (V1)"); }); }
/// <summary> /// Initializes a new instance of <see cref="ActionModel"/>. /// </summary> /// <param name="actionMethod">The action <see cref="MethodInfo"/>.</param> /// <param name="attributes">The attributes associated with the action.</param> public ActionModel( MethodInfo actionMethod, IReadOnlyList <object> attributes) { if (actionMethod == null) { throw new ArgumentNullException(nameof(actionMethod)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } ActionMethod = actionMethod; ApiExplorer = new ApiExplorerModel(); Attributes = new List <object>(attributes); Filters = new List <IFilterMetadata>(); Parameters = new List <ParameterModel>(); RouteValues = new Dictionary <string, string?>(StringComparer.OrdinalIgnoreCase); Properties = new Dictionary <object, object?>(); Selectors = new List <SelectorModel>(); }
public void Apply(ControllerModel controller) { if (controller.ApiExplorer == null) { var model = new ApiExplorerModel(); var attribute = controller.Attributes.OfType <ApiExplorerSettingsAttribute>().FirstOrDefault(); if (attribute != null) { model.GroupName = attribute.GroupName; model.IsVisible = !attribute.IgnoreApi; } controller.ApiExplorer = new ODataApiExplorerModel(model); } else if (controller.ApiExplorer is not ODataApiExplorerModel) { controller.ApiExplorer = new ODataApiExplorerModel(controller.ApiExplorer); } for (var j = 0; j < controller.Actions.Count; j++) { var action = controller.Actions[j]; if (action.ApiExplorer == null) { action.ApiExplorer = controller.ApiExplorer; } else if (action.ApiExplorer is not ODataApiExplorerModel) { action.ApiExplorer = new ODataApiExplorerModel(action.ApiExplorer); } action.SetProperty(action.ApiExplorer); } }
/// <summary> /// Creates a new <see cref="ApiExplorerModel"/> with properties copied from <paramref name="other"/>. /// </summary> /// <param name="other">The <see cref="ApiExplorerModel"/> to copy.</param> public ApiExplorerModel([NotNull] ApiExplorerModel other) { GroupName = other.GroupName; IsVisible = other.IsVisible; }