Example #1
0
        public async Task openapi___generates_v2_v3_for_json_and_yaml_for_lists()
        {
            var table = new ApiRoutingTable();

            table.AddRoute(new DeepSleepRouteRegistration(
                               template: "/test/list",
                               httpMethods: new[] { "GET" },
                               controller: typeof(ListController),
                               endpoint: nameof(ListController.List),
                               config: new DeepSleepRequestConfiguration()));

            table.AddRoute(new DeepSleepRouteRegistration(
                               template: "/test/list1",
                               httpMethods: new[] { "GET" },
                               controller: typeof(ListController),
                               endpoint: nameof(ListController.List1),
                               config: new DeepSleepRequestConfiguration()));

            table.AddRoute(new DeepSleepRouteRegistration(
                               template: "/test/list2",
                               httpMethods: new[] { "GET" },
                               controller: typeof(ListController),
                               endpoint: nameof(ListController.List2),
                               config: new DeepSleepRequestConfiguration()));

            table.AddRoute(new DeepSleepRouteRegistration(
                               template: "/test/list/container",
                               httpMethods: new[] { "GET" },
                               controller: typeof(ListController),
                               endpoint: nameof(ListController.ListContainer),
                               config: new DeepSleepRequestConfiguration()));

            var configuration = new DeepSleepOasConfiguration
            {
                Info = new OpenApiInfo
                {
                    Description = "Test",
                    Title       = "Test"
                },
                PrefixNamesWithNamespace = false
            };

            var mockServiceProvider = new Mock <IServiceProvider>();

            mockServiceProvider.Setup(m => m.GetService(It.Is <Type>(t => t == typeof(IDeepSleepOasConfiguration)))).Returns(configuration);
            mockServiceProvider.Setup(m => m.GetService(It.Is <Type>(t => t == typeof(IApiRoutingTable)))).Returns(table);

            var generator = new DeepSleepOasGenerator(mockServiceProvider.Object);
            var document  = await generator.Generate().ConfigureAwait(false);

            var resultsJsonV2 = document.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
            var resultsJsonV3 = document.Serialize(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json);
            var resultsYamlV2 = document.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml);
            var resultsYamlV3 = document.Serialize(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml);
        }
Example #2
0
        /// <summary>Documents the v3.</summary>
        /// <param name="format">The format.</param>
        /// <returns></returns>
        internal async Task <OpenApiDocument> DocV3(string format = "json")
        {
            var context = this.contextResolver.GetContext();

            if (string.Compare(format, "yaml", true) == 0)
            {
                context.Configuration.ReadWriteConfiguration.AcceptHeaderOverride = "application/yaml";
            }

            context.TryAddItem("openapi_version", "3");

            var generator = new DeepSleepOasGenerator(context.RequestServices, OpenApiSpecVersion.OpenApi3_0);

            var document = await generator.Generate().ConfigureAwait(false);

            return(document);
        }