Skip to content

Commit

Permalink
(Hopefully) fixed Swagger file generation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Duco committed Jul 17, 2018
1 parent a4c9a35 commit ac6a917
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/HttPlaceholder.SwaggerGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ static async Task Main(string[] args)
var startup = new Startup();
var testServer = new TestServer(
new WebHostBuilder()
.UseStartup<Startup>());
.ConfigureServices(services => Startup.ConfigureServicesStatic(services))
.Configure(appBuilder => Startup.ConfigureStatic(appBuilder, null, false)));
var client = testServer.CreateClient();

// Retrieve the Swagger URL.
Expand Down
43 changes: 28 additions & 15 deletions src/HttPlaceholder/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ namespace HttPlaceholder
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
ConfigureServicesStatic(services);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
ConfigureStatic(app, env, true);
}

public static void ConfigureStatic(IApplicationBuilder app, IHostingEnvironment env, bool preloadStubs)
{
app.UseMiddleware<StubHandlingMiddleware>();
app.UseMvc();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "HttPlaceholder API V1");
});

if (preloadStubs)
{
// Check if the stubs can be loaded.
var stubContainer = app.ApplicationServices.GetService<IStubContainer>();
Task.Run(() => stubContainer.GetStubsAsync()).Wait();
}
}

public static void ConfigureServicesStatic(IServiceCollection services)
{
services.AddMvc(options =>
{
Expand All @@ -34,20 +62,5 @@ public void ConfigureServices(IServiceCollection services)
DependencyRegistration.RegisterDependencies(services);
Services.DependencyRegistration.RegisterDependencies(services);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMiddleware<StubHandlingMiddleware>();
app.UseMvc();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "HttPlaceholder API V1");
});

// Check if the stubs can be loaded.
var stubContainer = app.ApplicationServices.GetService<IStubContainer>();
Task.Run(() => stubContainer.GetStubsAsync()).Wait();
}
}
}

0 comments on commit ac6a917

Please sign in to comment.