/// <summary> /// Get the resource description of the api for swagger documentation /// </summary> /// <remarks>It is very convenient to have this information available for generating clients. This is the entry point for the swagger UI /// </remarks> /// <returns>JSON document representing structure of API</returns> public HttpResponseMessage Get() { //var formatter = RequestContext.Configuration.Formatters.JsonFormatter; //formatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var docProvider = (XmlCommentDocumentationProvider)GlobalConfiguration.Configuration.Services.GetDocumentationProvider(); ResourceListing r = SwaggerGen.CreateResourceListing(ControllerContext); List <string> uniqueControllers = new List <string>(); foreach (var api in GlobalConfiguration.Configuration.Services.GetApiExplorer().ApiDescriptions) { if (!CustomAttributeHelper.HasIgnoreAttribute(api.ActionDescriptor.ControllerDescriptor) && ResourcesConfiguration.IsResourceMapped(api.ActionDescriptor.ControllerDescriptor)) { string controllerName = api.ActionDescriptor.ControllerDescriptor.ControllerName; if (uniqueControllers.Contains(controllerName) || controllerName.ToUpper().Equals(SwaggerGen.SWAGGER.ToUpper())) { continue; } uniqueControllers.Add(controllerName); ResourceApi rApi = SwaggerGen.CreateResourceApi(api); var queryIndex = rApi.path.IndexOf("?"); if (queryIndex > -1) { rApi.path = rApi.path.Substring(0, queryIndex); } r.AddApi(rApi); // Model foreach (var param in api.ParameterDescriptions) { r.Models.AddRange(SwaggerGen.CreateResourceModel(param, docProvider)); } } } HttpResponseMessage resp = new HttpResponseMessage(); resp.Content = new ObjectContent <ResourceListing>(r, ControllerContext.Configuration.Formatters.JsonFormatter); return(resp); }
public static void PostStart() { var config = GlobalConfiguration.Configuration; config.Filters.Add(new SwaggerActionFilter()); try { config.Services.Replace(typeof(IDocumentationProvider), new XmlCommentDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/Swagger.Net.WebApi.XML"))); } catch (FileNotFoundException) { throw new Exception("Please enable \"XML documentation file\" in project properties with default (bin\\Swagger.Net.WebApi.XML) value or edit value in App_Start\\SwaggerNet.cs"); } ResourcesConfiguration.Initialize(typeof(SwaggerNet).Assembly); }
public virtual IList <ResourceApiOperationParameterErrorResponse> GetErrorResponses(ApiDescription apiDescription) { var result = new List <ResourceApiOperationParameterErrorResponse>(); var memberNode = GetMemberNode(apiDescription.ActionDescriptor); if (memberNode != null) { var navigator = memberNode.Select("exception"); foreach (XPathNavigator n in navigator) { var errorResponse = new ResourceApiOperationParameterErrorResponse(); errorResponse.Code = n.GetAttribute("code", ""); errorResponse.Reason = n.GetAttribute("message", ""); if (String.IsNullOrEmpty(errorResponse.Reason)) { errorResponse.Reason = n.GetAttribute("reason", ""); } if (String.IsNullOrEmpty(errorResponse.Reason)) { errorResponse.Reason = n.InnerXml; } XPathNavigator attNavigator = n.Clone(); attNavigator.MoveToFirstAttribute(); while (attNavigator.MoveToNextAttribute()) { errorResponse.ExtraAttributes.Add(attNavigator.Name, attNavigator.Value); } if (ResourcesConfiguration.IsErrorMessageMapped(apiDescription, errorResponse)) { result.Add(errorResponse); } } } return(result); }
/** * Prepares for content building. This method is executed * before Build(). */ public virtual void PreBuild() { ResourcesConfiguration resourceConfig = ProjectConfig.Get <ResourcesConfiguration>(); var nvResources = resourceConfig.CopyNonVersioned; if (nvResources.Count > 0) { Log.LogInformation("Copying non-versioned resources"); foreach (var file in nvResources) { CopyResource(file, file); } } // Notify modules that the configuration is now available. foreach (RkModule module in _modules) { module.AcceptConfiguration(ProjectConfig); } }
private ResourceListing GetDocs(HttpActionContext actionContext) { CollectApiDescriptions(); var resourceListing = SwaggerGen.CreateResourceListing(actionContext); var apis = GetApiDescriptionsByController(actionContext.ControllerContext.ControllerDescriptor.ControllerName); foreach (var api in apis) { if (ResourcesConfiguration.IsOperationMapped(api)) { var resourceApi = SwaggerGen.CreateResourceApi(api); resourceListing.AddApi(resourceApi); ResourceApiOperation resourceApiOperation = null; if (!CustomAttributeHelper.HasIgnoreAttribute(api.ActionDescriptor)) { resourceApiOperation = SwaggerGen.CreateResourceApiOperation(api, DocProvider); resourceApi.operations.Add(resourceApiOperation); } var reflectedActionDescriptor = api.ActionDescriptor as ReflectedHttpActionDescriptor; resourceListing.Models.AddRange(SwaggerGen.CreateResourceModel(reflectedActionDescriptor.MethodInfo.ReturnType, DocProvider)); foreach (var param in api.ParameterDescriptions) { if (resourceApiOperation != null) { ResourceApiOperationParameter parameter = SwaggerGen.CreateResourceApiOperationParameter(api, param, DocProvider); resourceApiOperation.parameters.Add(parameter); } resourceListing.Models.AddRange(SwaggerGen.CreateResourceModel(param, DocProvider)); } } } return(resourceListing); }
public static void AddDirectDapper(this IServiceCollection services, Action <DirectDapperInitOptions> optionAction) { services.AddSingleton <IResourceManager, ResourceManager>(); services.AddSingleton <ISqlFileProvider, SqlFileProvider>(); services.AddTransient <ISqlQueryFactory, DefaultSqlQueryFactory>(); services.AddTransient <IDirectDapperQueryProvider, DirectDapperQueryProvider>(); services.AddSingleton <IQueryHelper, DefaultQueryHelper>(); var resourceConfiguration = new ResourcesConfiguration(); var options = new DirectDapperInitOptions(resourceConfiguration); optionAction?.Invoke(options); foreach (var initAction in options.InitActions) { initAction?.Invoke(services); } var sources = options.Sources; services.AddSingleton <IResourcesConfiguration, ResourcesConfiguration>((s) => resourceConfiguration); }
public DirectDapperInitOptions(ResourcesConfiguration configuration) { this.initActions = new List <Action <IServiceCollection> >(); this.configuration = configuration; }
public ContentBuilder(ResourcesConfiguration resourcesConfiguration) { _resourcesConfiguration = resourcesConfiguration; }