diff --git a/samples/Nancy.Swagger.Annotations.Demo/Bootstrapper.cs b/samples/Nancy.Swagger.Annotations.Demo/Bootstrapper.cs index e1f7990..470a4cc 100644 --- a/samples/Nancy.Swagger.Annotations.Demo/Bootstrapper.cs +++ b/samples/Nancy.Swagger.Annotations.Demo/Bootstrapper.cs @@ -49,6 +49,8 @@ protected override void ConfigureConventions(NancyConventions nancyConventions) protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Origin", "*")); + pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Headers", "*")); + pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Methods", "*")); } } } \ No newline at end of file diff --git a/samples/Nancy.Swagger.Annotations.Demo/Modules/ServiceDetailsModule.cs b/samples/Nancy.Swagger.Annotations.Demo/Modules/ServiceDetailsModule.cs index ef5b979..a69b5e2 100644 --- a/samples/Nancy.Swagger.Annotations.Demo/Modules/ServiceDetailsModule.cs +++ b/samples/Nancy.Swagger.Annotations.Demo/Modules/ServiceDetailsModule.cs @@ -42,7 +42,7 @@ public ServiceDetailsModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalo Get("/customers/{name}", parameters => GetServiceCustomer(parameters.name), null, "GetCustomer"); - Post("/customer/{service}", parameters => PostServiceCustomer(parameters.service, this.Bind()), null, "PostNewCustomer"); + Post("/customer/{serviceGuid:guid}", parameters => PostServiceCustomer(parameters.serviceGuid, this.Bind()), null, "PostNewCustomer"); Post("/customer/{name}/file", parameters => PostCustomerReview(parameters.name, null), null, "PostCustomerReview"); @@ -144,14 +144,13 @@ private ServiceCustomer GetServiceCustomer([RouteParam(ParameterIn.Path, Default } [Route("PostNewCustomer")] - [Route(HttpMethod.Post, "/customer/{service}")] [Route(Summary = "Post Service Customer")] [SwaggerResponse(HttpStatusCode.OK, Message = "OK", Model = typeof(ServiceCustomer))] [Route(Produces = new[] { "application/json" })] [Route(Consumes = new[] { "application/json", "application/xml" })] [Route(Tags = new[] { ServiceTagName })] private ServiceCustomer PostServiceCustomer( - [RouteParam(ParameterIn.Path, DefaultValue = "my-service")] string service, + [RouteParam(ParameterIn.Path, Description = "The GUID that identifies the service")] string serviceGuid, [RouteParam(ParameterIn.Body)] ServiceCustomer customer) { return customer; diff --git a/samples/Nancy.Swagger.Autofac.Demo/AutofacBootstrapper.cs b/samples/Nancy.Swagger.Autofac.Demo/AutofacBootstrapper.cs index eaea03d..b6710dd 100644 --- a/samples/Nancy.Swagger.Autofac.Demo/AutofacBootstrapper.cs +++ b/samples/Nancy.Swagger.Autofac.Demo/AutofacBootstrapper.cs @@ -28,6 +28,8 @@ protected override void ConfigureApplicationContainer(ILifetimeScope container) SwaggerAnnotationsConfig.ShowOnlyAnnotatedRoutes = true; this.ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Origin", "*")); + this.ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Headers", "*")); + this.ApplicationPipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Methods", "*")); } } } diff --git a/samples/Nancy.Swagger.Demo/Bootstrapper.cs b/samples/Nancy.Swagger.Demo/Bootstrapper.cs index e023518..59666c7 100644 --- a/samples/Nancy.Swagger.Demo/Bootstrapper.cs +++ b/samples/Nancy.Swagger.Demo/Bootstrapper.cs @@ -38,6 +38,8 @@ protected override void ConfigureConventions(NancyConventions nancyConventions) protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Origin", "*")); + pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Headers", "*")); + pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Methods", "*")); } } } \ No newline at end of file diff --git a/src/Nancy.Swagger/Services/SwaggerRouteData.cs b/src/Nancy.Swagger/Services/SwaggerRouteData.cs index becaaee..5641089 100644 --- a/src/Nancy.Swagger/Services/SwaggerRouteData.cs +++ b/src/Nancy.Swagger/Services/SwaggerRouteData.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Swagger.ObjectModel; +using System.Text.RegularExpressions; namespace Nancy.Swagger.Services { @@ -8,7 +9,7 @@ public class SwaggerRouteData { public SwaggerRouteData(string path, PathItem pathItem) { - Path = path; + Path = RemovePathParameterTypes(path); PathItem = pathItem; Types = new Dictionary(); } @@ -30,5 +31,16 @@ public SwaggerRouteData Combine(SwaggerRouteData data) } return combined; } + + /// + /// Removes parameter types from Nancy routes - Swagger doesn't expect them. + /// Examples: "/service/customers/{name:guid}" becomes "/service/customers/{name}" + /// + /// + /// + private string RemovePathParameterTypes(string path) + { + return Regex.Replace(path, @":\w+}", "}"); + } } } \ No newline at end of file