Esempio n. 1
0
        public async Task When_yaml_OpenAPI_spec_has_external_schema_refs_they_are_resolved(string relativePath, string docPath, string header)
        {
            var path = GetTestDirectory() + relativePath;

            //// Act
            OpenApiDocument doc = await OpenApiYamlDocument.FromFileAsync(path);

            IDictionary <string, OpenApiPathItem> docPaths = doc.Paths;
            OpenApiPathItem  pathItem  = docPaths[docPath];
            OpenApiOperation operation = pathItem["get"];
            IDictionary <string, OpenApiResponse> responses = operation.Responses;

            OpenApiResponse OK        = responses["200"].ActualResponse;
            OpenApiHeaders  OKheaders = OK.Headers;

            OpenApiResponse Unauthorized = responses["401"].ActualResponse;

            ////Assert

            // Header schema loaded correctly from headers.yaml
            Assert.True(OKheaders.ContainsKey(header));
            Assert.NotNull(OKheaders[header]);

            //Response data loaded correctly from responses.yaml
            string problemType = "application/problem+json";

            Assert.True(Unauthorized.Content.ContainsKey(problemType));
            Assert.NotNull(Unauthorized.Content[problemType]);
            Assert.NotNull(Unauthorized.Schema);
        }
        public static OpenApiHeaders GetApiHeaders(this ApiController controller)
        {
            var            header       = controller.Request.Headers;
            OpenApiHeaders headerdetail = new OpenApiHeaders();
            //获取Appid
            var appidobj = header.GetValues(AppId);

            if (appidobj != null && appidobj.Count() > 0)
            {
                headerdetail.AppId = appidobj.FirstOrDefault();
            }
            //获取TimeStamp

            var timestampobj = header.GetValues(TimeStamp);

            if (timestampobj != null)
            {
                DateTime time         = DateTime.MinValue;
                var      timestampstr = timestampobj.FirstOrDefault();
                bool     isok         = DateTime.TryParse(timestampstr, out time);
                if (isok)
                {
                    headerdetail.TimeStamp = time;
                }
            }
            //获取Session
            var sessionobj = header.GetValues(Session);

            if (sessionobj != null)
            {
                headerdetail.Session = sessionobj.FirstOrDefault();
            }
            //获取sign
            var signobj = header.GetValues(Sign);

            if (signobj != null)
            {
                headerdetail.Sign = signobj.FirstOrDefault();
            }
            return(headerdetail);
        }