Skip to content

Commit 3ce881c

Browse files
LiverpoolOwenMarkPieszak
authored andcommitted
Swagger changes (TrilonIO#187)
* Added Swagger * Remove old API docs
1 parent 0b7aa25 commit 3ce881c

File tree

8 files changed

+91
-109
lines changed

8 files changed

+91
-109
lines changed

Asp2017.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.1" />
1414
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
15+
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0-rc3" />
1516
</ItemGroup>
1617
<ItemGroup>
1718
<!-- Files not to show in IDE -->

Startup.cs

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,81 +13,105 @@
1313

1414
using Microsoft.AspNetCore.NodeServices;
1515
using AspCoreServer.Data;
16+
using Swashbuckle.AspNetCore.Swagger;
1617

1718
namespace AspCoreServer
1819
{
19-
public class Startup
20+
public class Startup
21+
{
22+
23+
public static void Main(string[] args)
24+
{
25+
var host = new WebHostBuilder()
26+
.UseKestrel()
27+
.UseContentRoot(Directory.GetCurrentDirectory())
28+
.UseIISIntegration()
29+
.UseStartup<Startup>()
30+
.Build();
31+
32+
host.Run();
33+
}
34+
public Startup(IHostingEnvironment env)
35+
{
36+
var builder = new ConfigurationBuilder()
37+
.SetBasePath(env.ContentRootPath)
38+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
39+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
40+
.AddEnvironmentVariables();
41+
Configuration = builder.Build();
42+
}
43+
44+
public IConfigurationRoot Configuration { get; }
45+
46+
// This method gets called by the runtime. Use this method to add services to the container.
47+
public void ConfigureServices(IServiceCollection services)
48+
{
49+
// Add framework services.
50+
services.AddMvc();
51+
services.AddNodeServices();
52+
53+
var connectionStringBuilder = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder { DataSource = "spa.db" };
54+
var connectionString = connectionStringBuilder.ToString();
55+
56+
services.AddDbContext<SpaDbContext>(options =>
57+
options.UseSqlite(connectionString));
58+
59+
// Register the Swagger generator, defining one or more Swagger documents
60+
services.AddSwaggerGen(c =>
61+
{
62+
c.SwaggerDoc("v1", new Info { Title = "Angular 4.0 Universal & ASP.NET Core advanced starter-kit web API", Version = "v1" });
63+
});
64+
}
65+
66+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
67+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SpaDbContext context)
2068
{
69+
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
70+
loggerFactory.AddDebug();
71+
72+
if (env.IsDevelopment())
73+
{
74+
app.UseDeveloperExceptionPage();
75+
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
76+
HotModuleReplacement = true
77+
});
2178

22-
public static void Main(string[] args)
79+
DbInitializer.Initialize(context);
80+
81+
app.UseSwagger();
82+
83+
// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
84+
app.UseSwaggerUI(c =>
2385
{
24-
var host = new WebHostBuilder()
25-
.UseKestrel()
26-
.UseContentRoot(Directory.GetCurrentDirectory())
27-
.UseIISIntegration()
28-
.UseStartup<Startup>()
29-
.Build();
30-
31-
host.Run();
32-
}
33-
public Startup(IHostingEnvironment env)
86+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
87+
});
88+
89+
app.MapWhen(x => !x.Request.Path.Value.StartsWith("/swagger"), builder =>
3490
{
35-
var builder = new ConfigurationBuilder()
36-
.SetBasePath(env.ContentRootPath)
37-
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
38-
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
39-
.AddEnvironmentVariables();
40-
Configuration = builder.Build();
41-
}
42-
43-
public IConfigurationRoot Configuration { get; }
44-
45-
// This method gets called by the runtime. Use this method to add services to the container.
46-
public void ConfigureServices(IServiceCollection services)
91+
builder.UseMvc(routes =>
92+
{
93+
routes.MapSpaFallbackRoute(
94+
name: "spa-fallback",
95+
defaults: new { controller = "Home", action = "Index" });
96+
});
97+
});
98+
}
99+
else
100+
{
101+
app.UseMvc(routes =>
47102
{
48-
// Add framework services.
49-
services.AddMvc();
50-
services.AddNodeServices();
103+
routes.MapRoute(
104+
name: "default",
105+
template: "{controller=Home}/{action=Index}/{id?}");
51106

52-
var connectionStringBuilder = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder { DataSource = "spa.db" };
53-
var connectionString = connectionStringBuilder.ToString();
107+
routes.MapSpaFallbackRoute(
108+
name: "spa-fallback",
109+
defaults: new { controller = "Home", action = "Index" });
110+
});
111+
app.UseExceptionHandler("/Home/Error");
112+
}
54113

55-
services.AddDbContext<SpaDbContext>(options =>
56-
options.UseSqlite(connectionString));
57-
}
58-
59-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
60-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SpaDbContext context)
61-
{
62-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
63-
loggerFactory.AddDebug();
64-
65-
if (env.IsDevelopment())
66-
{
67-
app.UseDeveloperExceptionPage();
68-
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
69-
HotModuleReplacement = true
70-
});
71-
72-
DbInitializer.Initialize(context);
73-
}
74-
else
75-
{
76-
app.UseExceptionHandler("/Home/Error");
77-
}
78-
79-
app.UseStaticFiles();
80-
81-
app.UseMvc(routes =>
82-
{
83-
routes.MapRoute(
84-
name: "default",
85-
template: "{controller=Home}/{action=Index}/{id?}");
86-
87-
routes.MapSpaFallbackRoute(
88-
name: "spa-fallback",
89-
defaults: new { controller = "Home", action = "Index" });
90-
});
91-
}
114+
app.UseStaticFiles();
92115
}
116+
}
93117
}

docs/RESTAPI-ENTITY.MD

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/all.jpeg

-41.6 KB
Binary file not shown.

docs/delete.jpeg

-33.9 KB
Binary file not shown.

docs/details.jpeg

-31.2 KB
Binary file not shown.

docs/insert.jpeg

-39.7 KB
Binary file not shown.

docs/update.jpeg

-38.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)