//[AsymmetricJson] public Resource Execute(ResourceRequest request) { var baseUrl = _urlRegistry.UrlFor(request); var absoluteBaseUrl = _currentHttpRequest.ToFullUrl(baseUrl); var apis = createSwaggerAPIs(request, baseUrl); //models support should go onto another branch. //var typeSet = new HashSet<Type>(); //actions.Each(a => // { // if(a.HasInput) typeSet.Add(a.InputType()); // if (a.HasOutput) typeSet.Add(a.OutputType()); // }); return new Resource { basePath = absoluteBaseUrl, resourcePath = "/" + request.GroupKey, //SWAGGER HACK - this assumes that the resource path will always be relative to the basePath. apiVersion = Assembly.GetExecutingAssembly().GetVersion(), swaggerVersion = "1.0", apis = apis, //models = typeSet.ToArray() }; }
private API[] createSwaggerAPIs(ResourceRequest request, string baseUrl) { var actions = _connegActionActionFinder.ActionsForGroup(request.GroupKey).ToArray(); var apis = actions.Select(a => { //UGH we need to make relative URLs for swagger to be happy. var pattern = a.ParentChain().Route.Pattern; var resourceUrl = baseUrl.UrlRelativeTo(pattern); var description = a.InputType().GetAttribute<DescriptionAttribute>(d => d.Description); return new API { path = resourceUrl, description = description, operations = _actionCallMapper.GetSwaggerOperations(a).ToArray() }; }).ToArray(); return apis; }