From a31b2c4e75c09dac729c12e0d58d979da9f267f1 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Thu, 21 Apr 2016 20:54:35 -0400 Subject: [PATCH] update things? --- global.json | 6 -- .../App_Start/SwaggerConfig.cs | 83 ++++++++----------- .../ProgrammerExcuses.Api.csproj | 24 +++--- src/ProgrammerExcuses.Api/Web.config | 2 +- src/ProgrammerExcuses.Api/packages.config | 10 +-- 5 files changed, 54 insertions(+), 71 deletions(-) delete mode 100644 global.json diff --git a/global.json b/global.json deleted file mode 100644 index 5ba986f..0000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-rc1-update1" - } -} diff --git a/src/ProgrammerExcuses.Api/App_Start/SwaggerConfig.cs b/src/ProgrammerExcuses.Api/App_Start/SwaggerConfig.cs index 0693fd8..940dace 100644 --- a/src/ProgrammerExcuses.Api/App_Start/SwaggerConfig.cs +++ b/src/ProgrammerExcuses.Api/App_Start/SwaggerConfig.cs @@ -1,11 +1,7 @@ -using System.Globalization; -using System.Linq; using System.Web.Http; -using System.Web.Http.Description; -using Swashbuckle.Application; -using Swashbuckle.Swagger; using WebActivatorEx; using ProgrammerExcuses.Api; +using Swashbuckle.Application; [assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")] @@ -17,7 +13,7 @@ namespace ProgrammerExcuses.Api { var thisAssembly = typeof(SwaggerConfig).Assembly; - GlobalConfiguration.Configuration + GlobalConfiguration.Configuration .EnableSwagger(c => { // By default, the service root url is inferred from the request used to access the docs. @@ -95,6 +91,13 @@ namespace ProgrammerExcuses.Api // //c.OrderActionGroupsBy(new DescendingAlphabeticComparer()); + // If you annotate Controllers and API Types with + // Xml comments (http://msdn.microsoft.com/en-us/library/b2s063f7(v=vs.110).aspx), you can incorporate + // those comments into the generated docs and UI. You can enable this by providing the path to one or + // more Xml comment files. + // + //c.IncludeXmlComments(GetXmlCommentsPath()); + // Swashbuckle makes a best attempt at generating Swagger compliant JSON schemas for the various types // exposed in your API. However, there may be occasions when more control of the output is needed. // This is supported through the "MapType" and "SchemaFilter" options: @@ -107,16 +110,12 @@ namespace ProgrammerExcuses.Api // complex Schema, use a Schema filter. // //c.MapType(() => new Schema { type = "integer", format = "int32" }); - // + // If you want to post-modify "complex" Schemas once they've been generated, across the board or for a // specific type, you can wire up one or more Schema filters. // //c.SchemaFilter(); - // Set this flag to omit schema property descriptions for any type properties decorated with the - // Obsolete attribute - //c.IgnoreObsoleteProperties(); - // In a Swagger 2.0 document, complex types are typically declared globally and referenced by unique // Schema Id. By default, Swashbuckle does NOT use the full type name in Schema Ids. In most cases, this // works well because it prevents the "implementation detail" of type namespaces from leaking into your @@ -125,6 +124,15 @@ namespace ProgrammerExcuses.Api // //c.UseFullTypeNameInSchemaIds(); + // Alternatively, you can provide your own custom strategy for inferring SchemaId's for + // describing "complex" types in your API. + // + //c.SchemaId(t => t.FullName.Contains('`') ? t.FullName.Substring(0, t.FullName.IndexOf('`')) : t.FullName); + + // Set this flag to omit schema property descriptions for any type properties decorated with the + // Obsolete attribute + //c.IgnoreObsoleteProperties(); + // In accordance with the built in JsonSerializer, Swashbuckle will, by default, describe enums as integers. // You can change the serializer behavior by configuring the StringToEnumConverter globally or for a given // enum type. Swashbuckle will honor this change out-of-the-box. However, if you use a different @@ -144,11 +152,6 @@ namespace ProgrammerExcuses.Api // to execute the operation // //c.OperationFilter(); - // - // Set filter to eliminate duplicate operation ids from being generated - // when there are multiple operations with the same verb in the API. - // - c.OperationFilter(); // Post-modify the entire Swagger document by wiring up one or more Document filters. // This gives full control to modify the final SwaggerDocument. You should have a good understanding of @@ -157,25 +160,20 @@ namespace ProgrammerExcuses.Api // //c.DocumentFilter(); - // If you annonate Controllers and API Types with - // Xml comments (http://msdn.microsoft.com/en-us/library/b2s063f7(v=vs.110).aspx), you can incorporate - // those comments into the generated docs and UI. You can enable this by providing the path to one or - // more Xml comment files. - // - //c.IncludeXmlComments(GetXmlCommentsPath()); - // In contrast to WebApi, Swagger 2.0 does not include the query string component when mapping a URL // to an action. As a result, Swashbuckle will raise an exception if it encounters multiple actions // with the same path (sans query string) and HTTP method. You can workaround this by providing a // custom strategy to pick a winner or merge the descriptions for the purposes of the Swagger docs // //c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); - // ***** Uncomment the following to enable the swagger UI ***** - /* - }) - .EnableSwaggerUi(c => - { - */ + + // Wrap the default SwaggerGenerator with additional behavior (e.g. caching) or provide an + // alternative implementation for ISwaggerProvider with the CustomProvider option. + // + //c.CustomProvider((defaultProvider) => new CachingSwaggerProvider(defaultProvider)); + }) + .EnableSwaggerUi(c => + { // Use the "InjectStylesheet" option to enrich the UI with one or more additional CSS stylesheets. // The file must be included in your project as an "Embedded Resource", and then the resource's // "Logical Name" is passed to the method as shown below. @@ -194,6 +192,12 @@ namespace ProgrammerExcuses.Api // //c.BooleanValues(new[] { "0", "1" }); + // By default, swagger-ui will validate specs against swagger.io's online validator and display the result + // in a badge at the bottom of the page. Use these options to set a different validator URL or to disable the + // feature entirely. + //c.SetValidatorUrl("http://localhost/validator"); + //c.DisableValidator(); + // Use this option to control how the Operation listing is displayed. // It can be set to "None" (default), "List" (shows operations for each resource), // or "Full" (fully expanded: shows operations and their details). @@ -222,23 +226,4 @@ namespace ProgrammerExcuses.Api }); } } - - internal class IncludeParameterNamesInOperationIdFilter : IOperationFilter - { - public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) - { - if(operation.parameters != null) - { - // Select the capitalized parameter names - var parameters = operation.parameters.Select( - p => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(p.name)); - - // Set the operation id to match the format "OperationByParam1AndParam2" - operation.operationId = string.Format( - "{0}By{1}", - operation.operationId, - string.Join("And", parameters)); - } - } - } -} \ No newline at end of file +} diff --git a/src/ProgrammerExcuses.Api/ProgrammerExcuses.Api.csproj b/src/ProgrammerExcuses.Api/ProgrammerExcuses.Api.csproj index 29c7d0c..e0e537f 100644 --- a/src/ProgrammerExcuses.Api/ProgrammerExcuses.Api.csproj +++ b/src/ProgrammerExcuses.Api/ProgrammerExcuses.Api.csproj @@ -47,11 +47,17 @@ True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - ..\packages\Swashbuckle.Core.5.0.0\lib\net40\Swashbuckle.Core.dll + + ..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + True - - ..\packages\System.IdentityModel.Tokens.Jwt.4.0.0\lib\net45\System.IdentityModel.Tokens.Jwt.dll + + ..\..\packages\Swashbuckle.Core.5.3.2\lib\net40\Swashbuckle.Core.dll + True + + + ..\..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + True @@ -70,17 +76,15 @@ + + ..\..\packages\WebActivatorEx.2.1.0\lib\net40\WebActivatorEx.dll + True + - - ..\packages\WebActivatorEx.2.0.6\lib\net40\WebActivatorEx.dll - - - ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll diff --git a/src/ProgrammerExcuses.Api/Web.config b/src/ProgrammerExcuses.Api/Web.config index 9b973f7..041d829 100644 --- a/src/ProgrammerExcuses.Api/Web.config +++ b/src/ProgrammerExcuses.Api/Web.config @@ -22,7 +22,7 @@ - + diff --git a/src/ProgrammerExcuses.Api/packages.config b/src/ProgrammerExcuses.Api/packages.config index 40cdbc8..12a7cd7 100644 --- a/src/ProgrammerExcuses.Api/packages.config +++ b/src/ProgrammerExcuses.Api/packages.config @@ -6,9 +6,9 @@ - - - - - + + + + + \ No newline at end of file