Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<packageSources>
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="Microsoft and .NET" value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
4 changes: 4 additions & 0 deletions src/MyHealth.MobileApp/MyHealth.MobileApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
<HintPath>..\..\packages\RazorEngine.3.7.0\lib\net45\RazorEngine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Swashbuckle.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd1bb07a5ac7c7bc, processorArchitecture=MSIL">
<HintPath>..\..\packages\Swashbuckle.Core.5.2.2\lib\net40\Swashbuckle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20511.1437, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.205111437\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Private>True</Private>
Expand Down
72 changes: 71 additions & 1 deletion src/MyHealth.MobileApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@
using Owin;
using System.Web.Http;

[assembly: OwinStartup(typeof(MyHealth.MobileApp.Startup))]
//HTTP Description needed for Swagger
using System.Web.Http.Description;

//Needed for Swashbuckle Filters
using System.Globalization;
using System.Linq;

//Has the HttpConfiguration extension methods with .EnableSwagger and .EnableSwaggerUi
using Swashbuckle.Application;
using Swashbuckle.Swagger;
using Newtonsoft.Json.Serialization;

[assembly: OwinStartup(typeof(MyHealth.MobileApp.Startup))]
namespace MyHealth.MobileApp
{
public class Startup
Expand All @@ -13,11 +24,70 @@ public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();

config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

//See info about OWIN in https://github.com/domaindrivendev/Swashbuckle
//Manually enable the Swagger docs and, optionally, the swagger-ui by invoking the
//extension methods (in namespace Swashbuckle.Application) on an instance of HttpConfiguration in Startup.cs
config
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MyHealth.MobileApp");
// Set filter to eliminate duplicate operation ids from being generated
// when there are multiple operations with the same verb in the API.
c.OperationFilter<IncludeParameterNamesInOperationIdFilter>();

// Set another filter to eliminate duplciation operation ids from being generated
// when there are multiple Web API routes, like /tables and /api
c.OperationFilter<IncludeRouteNameInOperationIdFilter>();
}
)
.EnableSwaggerUi();

new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);

app.UseWebApi(config);
}
}

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

internal class IncludeRouteNameInOperationIdFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{

//Find current Route name
string routeTemplate = apiDescription.Route.RouteTemplate;
string BaseRouteName = routeTemplate.Substring(0, routeTemplate.IndexOf('/'));
string postfix = "_" + BaseRouteName + "_Route";

// Set the operation id to match the format "OperationThroughRouteName"
operation.operationId = string.Format(
"{0}_Through{1}",
operation.operationId,
postfix);

}
}

}
1 change: 1 addition & 0 deletions src/MyHealth.MobileApp/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net46" />
<package id="Owin" version="1.0" targetFramework="net46" />
<package id="RazorEngine" version="3.7.0" targetFramework="net46" />
<package id="Swashbuckle.Core" version="5.2.2" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.205111437" targetFramework="net46" />
<package id="System.Spatial" version="5.6.4" targetFramework="net46" />
</packages>