/// <summary> /// /// </summary> /// <param name="httpContext"></param> /// <param name="pathBase"></param> /// <returns></returns> public async Task InvokeAsync(HttpContext httpContext, string pathBase) { var request = httpContext.Request; if ("GET".Equals(request.HttpMethod, StringComparison.OrdinalIgnoreCase)) { var routeValues = new RouteValueDictionary(); var templateMatcher = new TemplateMatcher(TemplateParser.Parse($"{pathBase}/schema.json"), routeValues); if (templateMatcher.TryMatch(request.Path, routeValues)) { var schema = JsonQLSchema.Generate(options.ResourceTypes); var content = JsonSerializer.Serialize(new { Title = options?.SchemaTitle, Description = options?.SchemaDescription, ServerUrl = options?.SchemaServerUrl, schema.ResourceInfos, schema.ResourceTypes, schema.ResourceMethods, }); var response = httpContext.Response; response.Clear(); response.StatusCode = 200; response.ContentType = "application/json"; response.Write(content); response.End(); } } await Task.FromResult(0); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="next"></param> /// <returns></returns> public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var schema = JsonQLSchema.Generate(jsonQLTesterOptions.ResourceTypes); var content = JsonSerializer.Serialize(new { Title = jsonQLTesterOptions?.SchemaTitle, Description = jsonQLTesterOptions?.SchemaDescription, ServerUrl = jsonQLTesterOptions?.SchemaServerUrl, schema.ResourceInfos, schema.ResourceTypes, schema.ResourceMethods, }); var response = context.Response; response.Clear(); response.StatusCode = 200; response.ContentType = "application/json"; await response.WriteAsync(content); }