public AsyncApiMiddleware(RequestDelegate next, IOptions <AsyncApiOptions> options, IAsyncApiDocumentProvider asyncApiDocumentProvider, IAsyncApiDocumentSerializer asyncApiDocumentSerializer)
 {
     _next = next;
     _asyncApiDocumentProvider   = asyncApiDocumentProvider;
     _asyncApiDocumentSerializer = asyncApiDocumentSerializer;
     _options = options.Value;
 }
Beispiel #2
0
        private async Task RespondWithAsyncApiSchemaJson(HttpResponse response, AsyncApiSchema.v2.AsyncApiDocument asyncApiSchema, IAsyncApiDocumentSerializer asyncApiDocumentSerializer)
        {
            var asyncApiSchemaSerialized = asyncApiDocumentSerializer.Serialize(asyncApiSchema);

            response.StatusCode  = (int)HttpStatusCode.OK;
            response.ContentType = asyncApiDocumentSerializer.ContentType;

            await response.WriteAsync(asyncApiSchemaSerialized);
        }
Beispiel #3
0
        public async Task Invoke(HttpContext context, IAsyncApiDocumentProvider asyncApiDocumentProvider, IAsyncApiDocumentSerializer asyncApiDocumentSerializer)
        {
            if (!IsRequestingAsyncApiSchema(context.Request))
            {
                await _next(context);

                return;
            }

            var asyncApiSchema = asyncApiDocumentProvider.GetDocument();

            await RespondWithAsyncApiSchemaJson(context.Response, asyncApiSchema, asyncApiDocumentSerializer);
        }
Beispiel #4
0
        private async Task RespondWithAsyncApiHtml(HttpResponse response, AsyncApiDocument asyncApiSchema, IAsyncApiDocumentSerializer asyncApiDocumentSerializer)
        {
            var asyncApiHtml = await _memoryCache.GetOrCreateAsync(PlaygroundHtmlCacheKey, async _ =>
            {
                var asyncApiSchemaJson = asyncApiDocumentSerializer.Serialize(asyncApiSchema);

                var asyncApiHtmlResponse = await _client.PostAsync(GenerateApiPath, new StringContent(asyncApiSchemaJson));

                return(await asyncApiHtmlResponse.Content.ReadAsStringAsync());
            });

            response.StatusCode  = (int)HttpStatusCode.OK;
            response.ContentType = MediaTypeNames.Text.Html;

            await response.WriteAsync(asyncApiHtml);
        }
Beispiel #5
0
        public async Task Invoke(HttpContext context, IAsyncApiDocumentProvider asyncApiDocumentProvider, IAsyncApiDocumentSerializer asyncApiDocumentSerializer)
        {
            if (IsRequestingAsyncApiUi(context.Request))
            {
                var asyncApiSchema = asyncApiDocumentProvider.GetDocument();
                await RespondWithAsyncApiHtml(context.Response, asyncApiSchema, asyncApiDocumentSerializer);

                return;
            }

            await RespondWithProxiedResponse(context.Request, context.Response);
        }
        private static async Task RespondWithAsyncApiSchemaJson(HttpResponse response, AsyncApiSchema.v2.AsyncApiDocument asyncApiSchema, IAsyncApiDocumentSerializer asyncApiDocumentSerializer, AsyncApiOptions options)
        {
            var asyncApiSchemaJson = asyncApiDocumentSerializer.Serialize(asyncApiSchema, options);

            response.StatusCode  = (int)HttpStatusCode.OK;
            response.ContentType = asyncApiDocumentSerializer.ContentType;

            await response.WriteAsync(asyncApiSchemaJson);
        }