コード例 #1
0
        public async Task <IEnumerable <EndpointClientDefinition> > GetEndpointDefinitions()
        {
            var definitions = new List <EndpointClientDefinition>();

            foreach (var type in resultViewProvider.GetResultViewTypes())
            {
                EndpointClientDefinition clientDef = new EndpointClientDefinition(type, await schemaBuilder.GetSchema(type));
                var customAttrs = type.GetTypeInfo().GetCustomAttributes();
                foreach (var link in customAttrs)
                {
                    var actionLink = link as HalActionLinkAttribute;
                    if (actionLink != null)
                    {
                        var doc = await endpointDocBuilder.GetDoc(actionLink.GroupName, actionLink.Method, actionLink.UriTemplate.Substring(1));

                        clientDef.AddLink(new EndpointClientLinkDefinition(actionLink.Rel, doc, actionLink.DocsOnly));
                    }
                    else
                    {
                        var declaredLink = link as DeclareHalLinkAttribute;
                        if (declaredLink != null)
                        {
                            EndpointDoc doc;
                            if (declaredLink.LinkedToControllerRel)
                            {
                                doc = await endpointDocBuilder.GetDoc(declaredLink.GroupName, declaredLink.Method, declaredLink.UriTemplate.Substring(1));
                            }
                            else
                            {
                                doc = new EndpointDoc();
                            }

                            //If the link is response only, send only the response
                            if (declaredLink.ResponseOnly)
                            {
                                var oldDoc = doc;
                                doc = new EndpointDoc();
                                doc.ResponseSchema = oldDoc.ResponseSchema;
                            }

                            clientDef.AddLink(new EndpointClientLinkDefinition(declaredLink.Rel, doc, false));
                        }
                    }
                }
                definitions.Add(clientDef);
            }
            return(definitions);
        }
コード例 #2
0
 public EndpointDoc Get(String groupName, String method, String relativePath)
 {
     try
     {
         return(descriptionProvider.GetDoc(groupName, method, relativePath, User));
     }
     catch (UnauthorizedAccessException)
     {
         throw new ErrorResultException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
コード例 #3
0
 public Task <EndpointDoc> Get(String groupName, String method, String relativePath, EndpointDocQuery docQuery)
 {
     try
     {
         return(descriptionProvider.GetDoc(groupName, method, relativePath, new EndpointDocBuilderOptions()
         {
             User = User,
             IncludeRequest = docQuery.IncludeRequest,
             IncludeResponse = docQuery.IncludeResponse
         }));
     }
     catch (UnauthorizedAccessException)
     {
         throw new ErrorResultException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
コード例 #4
0
        public async Task <EndpointDoc> Get(String version, String groupName, String method, String relativePath, EndpointDocQuery docQuery)
        {
            try
            {
                var doc = await descriptionProvider.GetDoc(groupName, method, relativePath, new EndpointDocBuilderOptions()
                {
                    User            = User,
                    IncludeRequest  = docQuery.IncludeRequest,
                    IncludeResponse = docQuery.IncludeResponse
                });

                if (doc.Cacheable && version != "nocache")
                {
                    httpContextAccessor.HttpContext.Response.Headers["Cache-Control"] = appConfig.CacheControlHeaderString;
                }

                return(doc);
            }
            catch (UnauthorizedAccessException)
            {
                throw new ErrorResultException("Unauthorized", HttpStatusCode.Unauthorized);
            }
        }