public async Task <IActionResult> Get([FromQuery] string graphVersion   = null,
                                              [FromQuery] string openApiVersion = null,
                                              [FromQuery] OpenApiStyle style    = OpenApiStyle.Plain,
                                              [FromQuery] string format         = null,
                                              [FromQuery] bool forceRefresh     = false)
        {
            try
            {
                OpenApiStyleOptions styleOptions = new OpenApiStyleOptions(style, openApiVersion, graphVersion, format);

                string graphUri = GetVersionUri(styleOptions.GraphVersion);

                if (graphUri == null)
                {
                    return(new BadRequestResult());
                }

                var graphOpenApi = await OpenApiService.GetGraphOpenApiDocumentAsync(graphUri, forceRefresh, styleOptions);

                WriteIndex(Request.Scheme + "://" + Request.Host.Value, styleOptions.GraphVersion, styleOptions.OpenApiVersion, styleOptions.OpenApiFormat,
                           graphOpenApi, Response.Body, styleOptions.Style);

                return(new EmptyResult());
            }
            catch
            {
                return(new BadRequestResult());
            }
        }
        public async Task <IActionResult> Get([FromQuery] string graphVersion   = null,
                                              [FromQuery] string openApiVersion = null,
                                              [FromQuery] OpenApiStyle style    = OpenApiStyle.Plain,
                                              [FromQuery] string format         = null,
                                              [FromQuery] bool forceRefresh     = false)
        {
            try
            {
                OpenApiStyleOptions styleOptions = new OpenApiStyleOptions(style, openApiVersion, graphVersion, format);

                string graphUri = GetVersionUri(styleOptions.GraphVersion);

                if (graphUri == null)
                {
                    throw new InvalidOperationException($"Unsupported {nameof(graphVersion)} provided: '{graphVersion}'");
                }

                var graphOpenApi = await OpenApiService.GetGraphOpenApiDocumentAsync(graphUri, forceRefresh);

                WriteIndex(Request.Scheme + "://" + Request.Host.Value, styleOptions.GraphVersion, styleOptions.OpenApiVersion, styleOptions.OpenApiFormat,
                           graphOpenApi, Response.Body, styleOptions.Style);

                return(new EmptyResult());
            }
            catch (InvalidOperationException ex)
            {
                return(new JsonResult(ex.Message)
                {
                    StatusCode = StatusCodes.Status400BadRequest
                });
            }
            catch (ArgumentException ex)
            {
                return(new JsonResult(ex.Message)
                {
                    StatusCode = StatusCodes.Status404NotFound
                });
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex.Message)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
        public async Task <IActionResult> Get(
            [FromQuery] string operationIds   = null,
            [FromQuery] string tags           = null,
            [FromQuery] string url            = null,
            [FromQuery] string openApiVersion = null,
            [FromQuery] string title          = "Partial Graph API",
            [FromQuery] OpenApiStyle style    = OpenApiStyle.Plain,
            [FromQuery] string format         = null,
            [FromQuery] string graphVersion   = null,
            [FromQuery] bool forceRefresh     = false)
        {
            try
            {
                OpenApiStyleOptions styleOptions = new OpenApiStyleOptions(style, openApiVersion, graphVersion, format);

                string graphUri = GetVersionUri(styleOptions.GraphVersion);

                if (graphUri == null)
                {
                    return(new BadRequestResult());
                }

                OpenApiDocument source = await OpenApiService.GetGraphOpenApiDocumentAsync(graphUri, forceRefresh, styleOptions);

                var predicate = await OpenApiService.CreatePredicate(operationIds, tags, url, source, forceRefresh);

                if (predicate == null)
                {
                    return(new BadRequestResult());
                }

                var subsetOpenApiDocument = OpenApiService.CreateFilteredDocument(source, title, styleOptions, predicate);

                subsetOpenApiDocument = OpenApiService.ApplyStyle(styleOptions, subsetOpenApiDocument);

                var stream = OpenApiService.SerializeOpenApiDocument(subsetOpenApiDocument, styleOptions);
                return(new FileStreamResult(stream, "application/json"));
            }
            catch
            {
                return(new BadRequestResult());
            }
        }
Exemple #4
0
        public async Task <IActionResult> Get([FromQuery] string graphVersion = "v1.0",
                                              [FromQuery] bool forceRefresh   = false)
        {
            try
            {
                string graphUri = GetVersionUri(graphVersion);

                if (graphUri == null)
                {
                    return(new BadRequestResult());
                }

                var graphOpenApi = await OpenApiService.GetGraphOpenApiDocumentAsync(graphUri, forceRefresh);

                WriteIndex(Request.Scheme + "://" + Request.Host.Value, graphVersion, graphOpenApi, Response.Body);

                return(new EmptyResult());
            }
            catch
            {
                return(new BadRequestResult());
            }
        }
        public async Task <IActionResult> Get(
            [FromQuery] string operationIds   = null,
            [FromQuery] string tags           = null,
            [FromQuery] string url            = null,
            [FromQuery] string openApiVersion = null,
            [FromQuery] string title          = "Partial Graph API",
            [FromQuery] OpenApiStyle style    = OpenApiStyle.Plain,
            [FromQuery] string format         = null,
            [FromQuery] string graphVersion   = null,
            [FromQuery] bool forceRefresh     = false)
        {
            try
            {
                OpenApiStyleOptions styleOptions = new OpenApiStyleOptions(style, openApiVersion, graphVersion, format);

                string graphUri = GetVersionUri(styleOptions.GraphVersion);

                if (graphUri == null)
                {
                    throw new InvalidOperationException($"Unsupported {nameof(graphVersion)} provided: '{graphVersion}'");
                }

                OpenApiDocument source = await OpenApiService.GetGraphOpenApiDocumentAsync(graphUri, forceRefresh);

                var predicate = await OpenApiService.CreatePredicate(operationIds, tags, url, source, forceRefresh);

                var subsetOpenApiDocument = OpenApiService.CreateFilteredDocument(source, title, styleOptions.GraphVersion, predicate);

                subsetOpenApiDocument = OpenApiService.ApplyStyle(styleOptions.Style, subsetOpenApiDocument);

                var stream = OpenApiService.SerializeOpenApiDocument(subsetOpenApiDocument, styleOptions);

                if (styleOptions.OpenApiFormat == "yaml")
                {
                    return(new FileStreamResult(stream, "text/yaml"));
                }
                else
                {
                    return(new FileStreamResult(stream, "application/json"));
                }
            }
            catch (InvalidOperationException ex)
            {
                return(new JsonResult(ex.Message)
                {
                    StatusCode = StatusCodes.Status400BadRequest
                });
            }
            catch (ArgumentException ex)
            {
                return(new JsonResult(ex.Message)
                {
                    StatusCode = StatusCodes.Status404NotFound
                });
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex.Message)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }