Example #1
0
        public static void Register(JsonSerializerSettings jsonSerializerSettings)
        {
            if (Api.DocsSettings.Enabled == true)
            {
                //var docsDescription = AppDomain.CurrentDomain.BaseDirectory + "/Docs/DOCS-DESCRIPTION.md";
                //
                //if (File.Exists(docsDescription))
                //{
                //    string readme = File.ReadAllText(docsDescription);
                //}

                var version = (string.IsNullOrWhiteSpace(Api.ApiSettings.Version))
                    ? "v1"
                    : Api.ApiSettings.Version;

                var contact = new Contact()
                {
                    EmailAddress = Api.DocsSettings.AuthorEmail,
                    Name         = Api.DocsSettings.AuthorName,
                    Url          = Api.ApiSettings.AppUrl
                };

                SwaggerConfig.ResourceListingPath    = BaseModule.GetModulePath();
                SwaggerConfig.JsonSerializerSettings = jsonSerializerSettings;
                SwaggerMetadataProvider.SetInfo(Api.DocsSettings.Title, version, Api.DocsSettings.Description, contact, Api.DocsSettings.TermsOfService);
                SwaggerAnnotationsConfig.ShowOnlyAnnotatedRoutes = true;
                SwaggerTypeMapping.AddTypeMapping(typeof(Guid), typeof(string));
            }
        }
        public void ShouldAdd_AndGet_TypeMappings()
        {
            SwaggerTypeMapping.ResetMappedTypes();

            Assert.False(SwaggerTypeMapping.IsMappedType(typeof(long)));

            SwaggerTypeMapping.AddTypeMapping(typeof(long), typeof(double));

            Assert.True(SwaggerTypeMapping.IsMappedType(typeof(long)));
            Assert.Equal(typeof(double), SwaggerTypeMapping.GetMappedType(typeof(long)));
        }
Example #3
0
        public StatisticsMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
            : base(modelCatalog, tagCatalog)
        {
            SwaggerTypeMapping.AddTypeMapping(typeof(DateTime), typeof(DateTime));

            RouteDescriber.AddBaseTag(new Tag
            {
                Description = "Operations for getting projection statistics",
                Name        = "Statistics"
            });

            RouteDescriber.DescribeRoute <IEnumerable <ProjectorSummary> >("GetAll", "",
                                                                           "Returns a list of all known projectors and a summary of their status", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            });

            RouteDescriber
            .DescribeRoute <ProjectorDetails>("GetSpecific", "", "Returns the details of a specific projector", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            })
            .Parameter(p => p.Name("id").In(ParameterIn.Path).Description("Identifies the projector"));


            RouteDescriber
            .DescribeRoute <ProjectorEventCollection>("GetEvents", "", "Returns the events logged for a specific projector", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            })
            .Parameter(p => p.Name("id").In(ParameterIn.Path).Description("Identifies the projector"));;

            RouteDescriber
            .DescribeRoute <string>("GetEta", "", "Returns the ETA for a specific projector to reach a certain checkpoint", new[]
            {
                new HttpResponseMetadata {
                    Code = 200, Message = "OK"
                }
            })
            .Parameter(p => p.Name("id").In(ParameterIn.Path).Description("Identifies the projector"))
            .Parameter(p => p.Name("targetCheckpoint").In(ParameterIn.Path).Description("The target checkpoint for which to calculate the ETA"));

            RouteDescriber.AddAdditionalModels(
                typeof(ProjectorEvent), typeof(ProjectorProperty), typeof(ProjectorSummary));
        }
        public void ShouldAdd_AndGet_NestedTypeMappings()
        {
            SwaggerTypeMapping.ResetMappedTypes();

            Assert.False(SwaggerTypeMapping.IsMappedType(typeof(OriginalType)));

            SwaggerTypeMapping.AddTypeMapping(typeof(AnotherOriginalType), typeof(OriginalType));
            SwaggerTypeMapping.AddTypeMapping(typeof(OriginalType), typeof(MappedType));

            Assert.True(SwaggerTypeMapping.IsMappedType(typeof(AnotherOriginalType)));
            Assert.True(SwaggerTypeMapping.IsMappedType(typeof(OriginalType)));

            Assert.Equal(typeof(MappedType), SwaggerTypeMapping.GetMappedType(typeof(AnotherOriginalType)));
        }
Example #5
0
        private static void InitSwagger(IAppConfiguration config)
        {
            SwaggerMetadataProvider.SetInfo(
                config["SvcMetaTitle"],
                config["SvcMetaVer"],
                $"[ Base URL: {config["HostUrl"]} ]",
                new Contact {
                EmailAddress = config["SvcMetaContact"]
            });

            SwaggerConfig.ResourceListingPath = config["SwaggerResourceListingPath"];

            SwaggerTypeMapping.AddTypeMapping(typeof(DateTime), typeof(string));
            SwaggerTypeMapping.AddTypeMapping(typeof(DateTime?), typeof(string));
            SwaggerTypeMapping.AddTypeMapping(typeof(TimeSpan), typeof(string));
            SwaggerTypeMapping.AddTypeMapping(typeof(TimeSpan?), typeof(string));
            SwaggerTypeMapping.AddTypeMapping(typeof(Guid), typeof(string));
        }