Example #1
0
        public void ReturnOpenApiDocumentInCreateFilteredDocumentWhenValidArgumentsAreSpecified(string operationIds, string tags, string url)
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            // Act
            var predicate = OpenApiService.CreatePredicate(operationIds: operationIds, tags: tags, url: url, source: source)
                            .GetAwaiter().GetResult();

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

            // Assert
            Assert.NotNull(subsetOpenApiDocument);

            if (!string.IsNullOrEmpty(operationIds))
            {
                Assert.Single(subsetOpenApiDocument.Paths);
            }
            else if (!string.IsNullOrEmpty(tags))
            {
                Assert.Equal(2, subsetOpenApiDocument.Paths.Count);
            }
            else // url
            {
                Assert.Single(subsetOpenApiDocument.Paths);
            }
        }
Example #2
0
        public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidNumberOfArgumentsAreSpecified(string operationIds, string tags, string url)
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            // Act and Assert
            if (string.IsNullOrEmpty(operationIds) &&
                string.IsNullOrEmpty(tags) &&
                string.IsNullOrEmpty(url))
            {
                var message = Assert.Throws <InvalidOperationException>(() => OpenApiService.CreatePredicate(operationIds: operationIds, tags: tags, url: url, source: source)
                                                                        .GetAwaiter().GetResult()).Message;
                Assert.Equal("Either operationIds, tags or url need to be specified.", message);
            }
            else
            {
                var message = Assert.Throws <InvalidOperationException>(() => OpenApiService.CreatePredicate(operationIds: operationIds, tags: tags, url: url, source: source)
                                                                        .GetAwaiter().GetResult()).Message;

                if (url != null && (operationIds != null || tags != null))
                {
                    Assert.Equal("Cannot filter by url and either operationIds and tags at the same time.", message);
                }
                else if (operationIds != null && tags != null)
                {
                    Assert.Equal("Cannot filter by operationIds and tags at the same time.", message);
                }
            }
        }
Example #3
0
        public void FormatPathFunctionsOfStringDataTypesWithSingleQuotationMarks()
        {
            // Arrange
            string          operationId_1 = "reports.getTeamsUserActivityCounts";
            string          operationId_2 = "reports.getTeamsUserActivityUserDetail-a3f1";
            OpenApiDocument source        = _graphBetaSource;

            var predicate_1 = OpenApiService.CreatePredicate(operationIds: operationId_1, tags: null, url: null, source: source)
                              .GetAwaiter().GetResult();

            var predicate_2 = OpenApiService.CreatePredicate(operationIds: operationId_2, tags: null, url: null, source: source)
                              .GetAwaiter().GetResult();

            // Act
            var subsetOpenApiDocument_1 = OpenApiService.CreateFilteredDocument(source, Title, GraphVersion, predicate_1);
            var subsetOpenApiDocument_2 = OpenApiService.CreateFilteredDocument(source, Title, GraphVersion, predicate_2);

            // Assert
            Assert.Collection(subsetOpenApiDocument_1.Paths,
                              item =>
            {
                Assert.Equal("/reports/microsoft.graph.getTeamsUserActivityCounts(period='{period}')", item.Key);
            });
            Assert.Collection(subsetOpenApiDocument_2.Paths,
                              item =>
            {
                Assert.Equal("/reports/microsoft.graph.getTeamsUserActivityUserDetail(date={date})", item.Key);
            });
        }
Example #4
0
 public OpenApiController(ILogger <CsdlImageController> logger, ResourceStore resourceStore, IHttpClientFactory clientFactory, OpenApiService openApiService)
 {
     _logger         = logger;
     _resourceStore  = resourceStore;
     _client         = clientFactory.CreateClient("default");
     _openApiService = openApiService;
 }
Example #5
0
        public void FormatPathFunctionsOfStringDataTypesWithSingleQuotationMarks()
        {
            // Arrange
            string              operationId_1 = "reports.getTeamsUserActivityCounts";
            string              operationId_2 = "reports.getTeamsUserActivityUserDetail-a3f1";
            string              graphVersion  = "beta";
            OpenApiDocument     source        = _source;
            OpenApiStyleOptions styleOptions  = new OpenApiStyleOptions(OpenApiStyle.PowerShell, graphVersion: graphVersion);
            var predicate_1 = OpenApiService.CreatePredicate(operationId_1, null, null, source, false).GetAwaiter().GetResult();
            var predicate_2 = OpenApiService.CreatePredicate(operationId_2, null, null, source, false).GetAwaiter().GetResult();

            // Act
            var subsetOpenApiDocument_1 = OpenApiService.CreateFilteredDocument(source, Title, styleOptions, predicate_1);
            var subsetOpenApiDocument_2 = OpenApiService.CreateFilteredDocument(source, Title, styleOptions, predicate_2);

            // Assert
            Assert.Collection(subsetOpenApiDocument_1.Paths,
                              item =>
            {
                Assert.Equal("/reports/microsoft.graph.getTeamsUserActivityCounts(period='{period}')", item.Key);
            });
            Assert.Collection(subsetOpenApiDocument_2.Paths,
                              item =>
            {
                Assert.Equal("/reports/microsoft.graph.getTeamsUserActivityUserDetail(date={date})", item.Key);
            });
        }
Example #6
0
        public async Task <IActionResult> Get(
            [FromQuery] string operationIds   = null,
            [FromQuery] string tags           = null,
            [FromQuery] string openApiVersion = "2",
            [FromQuery] string title          = "Partial Graph API",
            [FromQuery] OpenApiStyle style    = OpenApiStyle.Plain,
            [FromQuery] string format         = "yaml",
            [FromQuery] string graphVersion   = "v1.0",
            [FromQuery] bool forceRefresh     = false)
        {
            var predicate = OpenApiService.CreatePredicate(operationIds, tags);

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

            OpenApiDocument source = await OpenApiService.GetGraphOpenApiDocument(graphVersion, forceRefresh);

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

            subsetOpenApiDocument = OpenApiService.ApplyStyle(style, subsetOpenApiDocument);

            var stream = OpenApiService.SerializeOpenApiDocument(subsetOpenApiDocument, openApiVersion, format);

            return(new FileStreamResult(stream, "application/json"));
        }
        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 UriSpaceDataController(ILogger <UmlDiagramController> logger, VocabService vocabService, IHttpClientFactory clientFactory, OpenApiService openApiService)
 {
     _logger             = logger;
     this.vocabService   = vocabService;
     this.clientFactory  = clientFactory;
     this.openApiService = openApiService;
 }
Example #9
0
        public async Task <IActionResult> Get(string graphVersion = "v1.0", bool forceRefresh = false)
        {
            var graphOpenApi = await OpenApiService.GetGraphOpenApiDocument(graphVersion, forceRefresh);

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

            return(new EmptyResult());
        }
        public void GetOpenApiDocument_WithInvalidDataForDocumentName_ThrowsException(string documentName)
        {
            var sut = new OpenApiService(_swaggerProvider);

            Action action = () => sut.GetOpenApiDocument(documentName);

            action.Should().Throw <ArgumentException>().And.ParamName.Should().Be("documentName");
        }
        public void GetOpenApiDocument_WithNullForDocumentName_ThrowsException()
        {
            var sut = new OpenApiService(_swaggerProvider);

            Action action = () => sut.GetOpenApiDocument(null);

            action.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("documentName");
        }
Example #12
0
        public void ThrowsArgumentExceptionInCreatePredicateWhenNonExistentUrlArgumentIsSpecified()
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            // Act and Assert
            var message = Assert.Throws <ArgumentException>(() => OpenApiService.CreatePredicate(operationIds: null, tags: null, url: "/foo", source: source)
                                                            .GetAwaiter().GetResult()).Message;

            Assert.Equal("The url supplied could not be found.", message);
        }
        public async Task <IActionResult> Post(
            [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 = OpenApiService.ConvertCsdlToOpenApi(styleOptions, Request.Body);

                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);
                if (styleOptions.OpenApiFormat == "yaml")
                {
                    return(new FileStreamResult(stream, "application/yaml"));
                }
                else
                {
                    return(new FileStreamResult(stream, "application/json"));
                }
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(new ProblemDetails()
                {
                    Detail = ex.Message
                }));
            }
        }
Example #14
0
        public void ReturnValueInCreatePredicateWhenValidArgumentsAreSpecified(string operationIds, string tags, string url)
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            // Act
            var predicate = OpenApiService.CreatePredicate(operationIds: operationIds, tags: tags, url: url, source: source)
                            .GetAwaiter().GetResult();

            // Assert
            Assert.NotNull(predicate);
        }
Example #15
0
        public void ThrowsArgumentExceptionInCreateFilteredDocumentWhenNonExistentOperationIdsAndTagsAreSupplied(string operationIds, string tags)
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            var predicate = OpenApiService.CreatePredicate(operationIds: operationIds, tags: tags, url: null, source: source)
                            .GetAwaiter().GetResult();

            // Act & Assert
            var message = Assert.Throws <ArgumentException>(() => OpenApiService.CreateFilteredDocument(source, Title, GraphVersion, predicate)).Message;

            Assert.Equal("No paths found for the supplied parameters.", message);
        }
Example #16
0
        /// <summary>
        /// Creates an OpenAPI document from a CSDL document.
        /// </summary>
        /// <param name="graphDocPath">The file path of the CSDL document location.</param>
        /// <param name="styleOptions">Optional parameter that defines the style
        /// options to be used in formatting the OpenAPI document.</param>
        /// <returns>Instance of an OpenApiDocument</returns>
        private static OpenApiDocument CreateOpenApiDocument(string graphDocPath)
        {
            if (string.IsNullOrEmpty(graphDocPath))
            {
                return(null);
            }

            using StreamReader streamReader = new StreamReader(graphDocPath);
            Stream csdl = streamReader.BaseStream;

            OpenApiDocument document = OpenApiService.ConvertCsdlToOpenApi(csdl);

            return(document);
        }
        public void GetOpenApiDocument_PassesOnDocumentName()
        {
            var documentName    = "myDocumentName";
            var openApiDocument = new OpenApiDocument();

            A.CallTo(() => _swaggerProvider.GetSwagger(documentName, null, null)).Returns(openApiDocument);

            var sut = new OpenApiService(_swaggerProvider);

            var document = sut.GetOpenApiDocument(documentName);

            A.CallTo(() => _swaggerProvider.GetSwagger(documentName, null, null)).MustHaveHappenedOnceExactly();
            document.Should().NotBeNull();
        }
        public void GetOpenApiDocument_ForHostAndBasePath_PassesOnCorrectHostAndBasePath(string host, string basePath, string expectedHost, string expectedBasePath)
        {
            const string documentName    = "myDocumentName";
            var          openApiDocument = new OpenApiDocument();

            A.CallTo(() => _swaggerProvider.GetSwagger(documentName, A <string> ._, A <string> ._)).Returns(openApiDocument);

            var sut = new OpenApiService(_swaggerProvider);

            var document = sut.GetOpenApiDocument(documentName, host, basePath);

            document.Should().NotBeNull();
            A.CallTo(() => _swaggerProvider.GetSwagger(documentName, expectedHost, expectedBasePath)).MustHaveHappenedOnceExactly();
        }
Example #19
0
        public void ThrowsArgumentExceptionInApplyStyleWhenNoPathsAreReturned()
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            var predicate = OpenApiService.CreatePredicate(operationIds: null, tags: null, url: "/", source: source)
                            .GetAwaiter().GetResult();     // root path will be non-existent in a PowerShell styled doc.

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

            // Act & Assert
            var message = Assert.Throws <ArgumentException>(() => OpenApiService.ApplyStyle(OpenApiStyle.PowerShell, subsetOpenApiDocument)).Message;

            Assert.Equal("No paths found for the supplied parameters.", message);
        }
        public void ThrowsExceptionWhenUrlsInCollectionAreMissingFromSourceDocument()
        {
            // Arrange
            var filePath  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\postmanCollection_ver1.json");
            var fileInput = new FileInfo(filePath);
            var stream    = fileInput.OpenRead();

            // Act
            var requestUrls = OpenApiService.ParseJsonCollectionFile(stream, _logger);

            // Assert
            var message = Assert.Throws <ArgumentException>(() =>
                                                            OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: _openApiDocumentMock)).Message;

            Assert.Equal("The urls in the Postman collection supplied could not be found.", message);
        }
Example #21
0
        public void RemoveRootPathFromOpenApiDocumentInApplyStyleForPowerShellOpenApiStyle()
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;

            // Act
            var predicate = OpenApiService.CreatePredicate(operationIds: "*", tags: null, url: null, source: source)
                            .GetAwaiter().GetResult();     // fetch all paths/operations

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

            subsetOpenApiDocument = OpenApiService.ApplyStyle(OpenApiStyle.PowerShell, subsetOpenApiDocument);

            // Assert
            Assert.False(subsetOpenApiDocument.Paths.ContainsKey("/")); // root path
        }
        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 void ReturnFilteredOpenApiDocumentBasedOnPostmanCollection()
        {
            // Arrange
            var filePath  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\postmanCollection_ver2.json");
            var fileInput = new FileInfo(filePath);
            var stream    = fileInput.OpenRead();

            // Act
            var requestUrls           = OpenApiService.ParseJsonCollectionFile(stream, _logger);
            var predicate             = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: _openApiDocumentMock);
            var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(_openApiDocumentMock, predicate);

            // Assert
            Assert.NotNull(subsetOpenApiDocument);
            Assert.NotEmpty(subsetOpenApiDocument.Paths);
            Assert.Equal(3, subsetOpenApiDocument.Paths.Count);
        }
        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());
            }
        }
Example #25
0
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.RootComponents.Add <App>("#app");

            builder.Services.AddScoped(sp => new HttpClient {
                BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
            });

            OpenClient liveClientFactory() => new(ApiInfo.LiveHost, ApiInfo.Port, TimeSpan.FromSeconds(10), useWebSocket : true);
            OpenClient demoClientFactory() => new(ApiInfo.DemoHost, ApiInfo.Port, TimeSpan.FromSeconds(10), useWebSocket : true);

            var apiService = new OpenApiService(liveClientFactory, demoClientFactory);

            builder.Services.AddSingleton <IOpenApiService>(apiService);
            builder.Services.AddSingleton <ITradingAccountsService>(new TradingAccountsService(apiService));

            await builder.Build().RunAsync();
        }
Example #26
0
        public void EscapePoundCharacterFromNetworkInterfaceSchemaDescription()
        {
            // Arrange
            OpenApiDocument source = _graphBetaSource;
            var             expectedDescription = "Description of the NIC (e.g. Ethernet adapter, Wireless LAN adapter Local Area Connection <#/>, etc.).";

            // Act
            var predicate = OpenApiService.CreatePredicate(operationIds: null, tags: null, url: "/security/hostSecurityProfiles", source: source)
                            .GetAwaiter().GetResult();

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

            subsetOpenApiDocument = OpenApiService.ApplyStyle(OpenApiStyle.PowerShell, subsetOpenApiDocument);

            var parentSchema      = subsetOpenApiDocument.Components.Schemas["microsoft.graph.networkInterface"];
            var descriptionSchema = parentSchema.Properties["description"];

            // Assert
            Assert.Equal(expectedDescription, descriptionSchema.Description);
        }
Example #27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            OpenClient liveClientFactory() => new(ApiInfo.LiveHost, ApiInfo.Port, TimeSpan.FromSeconds(10));
            OpenClient demoClientFactory() => new(ApiInfo.DemoHost, ApiInfo.Port, TimeSpan.FromSeconds(10));

            services.AddSingleton(_apiCredentials);

            var apiService = new OpenApiService(liveClientFactory, demoClientFactory);

            services.AddSingleton <IOpenApiService>(apiService);
            services.AddSingleton <ITradingAccountsService>(new TradingAccountsService(apiService));

            services.AddHostedService <ConnectApiHostedService>();

            services.AddSignalR(hubOptions => hubOptions.EnableDetailedErrors = true).AddJsonProtocol(options =>
            {
                options.PayloadSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
            });
        }
        public void GetOpenApiDocument_ReturnsCorrectDocument()
        {
            const string documentName    = "myDocumentName";
            var          openApiDocument = new OpenApiDocument
            {
                Info = new OpenApiInfo
                {
                    Description = "Test document",
                    Version     = "v1",
                    Title       = "Test"
                }
            };

            A.CallTo(() => _swaggerProvider.GetSwagger(documentName, null, null)).Returns(openApiDocument);

            var sut = new OpenApiService(_swaggerProvider);

            var document = sut.GetOpenApiDocument(documentName);

            document.Should().BeEquivalentTo(openApiDocument);
        }
Example #29
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> Post(
            [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 = OpenApiService.ConvertCsdlToOpenApi(Request.Body);

                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
                });
            }
        }