Skip to content

chore(sample): Improve WebApiSample, adding SwaggerUI, fix invalid cast from JObject #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using WebApiSample.Workflows;
using WorkflowCore.Interface;
using WorkflowCore.Models;

Expand All @@ -22,9 +23,9 @@ public EventsController(IWorkflowController workflowService)
}

[HttpPost("{eventName}/{eventKey}")]
public async Task<IActionResult> Post(string eventName, string eventKey, [FromBody]object eventData)
public async Task<IActionResult> Post(string eventName, string eventKey, [FromBody]MyDataClass eventData)
{
await _workflowService.PublishEvent(eventName, eventKey, eventData);
await _workflowService.PublishEvent(eventName, eventKey, eventData.Value1);
return Ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApiSample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand All @@ -29,7 +29,7 @@
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values"
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger"
}
}
}
18 changes: 18 additions & 0 deletions src/samples/WebApiSample/WebApiSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Nest;
using Swashbuckle.AspNetCore.Swagger;
using WebApiSample.Workflows;
using WorkflowCore.Interface;

Expand All @@ -27,6 +28,13 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});

services.AddWorkflow(cfg =>
{
cfg.UseMongoDB(@"mongodb://mongo:27017", "workflow");
Expand All @@ -41,6 +49,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseDeveloperExceptionPage();
}

// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();

// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});

app.UseMvc();

var host = app.ApplicationServices.GetService<IWorkflowHost>();
Expand Down
3 changes: 2 additions & 1 deletion src/samples/WebApiSample/WebApiSample/WebApiSample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
Expand All @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="WorkflowCore" Version="1.8.0" />
<PackageReference Include="WorkflowCore.Persistence.MongoDB" Version="1.7.0" />
<PackageReference Include="WorkflowCore.Providers.Elasticsearch" Version="1.8.0" />
Expand Down