Skip to content

Commit b997dd1

Browse files
authored
Merge pull request #3306 from jimschubert/aspnet5_.NET_Core_1.0
[aspnet5] update to asp.net core 1.0
2 parents b97cedb + 4d5905c commit b997dd1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1118
-314
lines changed

Diff for: bin/all-petstore.sh

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fi
2020
cd $APP_DIR
2121
./bin/akka-scala-petstore.sh
2222
./bin/android-petstore.sh
23+
./bin/aspnet5-petstore-server.sh
2324
./bin/clojure-petstore.sh
2425
./bin/csharp-petstore.sh
2526
./bin/dynamic-html.sh

Diff for: modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNet5ServerCodegen.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,22 @@ public void processOpts() {
8484
apiPackage = packageName + ".Controllers";
8585
modelPackage = packageName + ".Models";
8686

87+
supportingFiles.add(new SupportingFile("NuGet.Config", "", "NuGet.Config"));
8788
supportingFiles.add(new SupportingFile("global.json", "", "global.json"));
88-
supportingFiles.add(new SupportingFile("build.mustache", "", "build.sh"));
89+
supportingFiles.add(new SupportingFile("build.sh.mustache", "", "build.sh"));
90+
supportingFiles.add(new SupportingFile("build.bat.mustache", "", "build.bat"));
91+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
92+
supportingFiles.add(new SupportingFile("Solution.mustache", "", this.packageName + ".sln"));
8993
supportingFiles.add(new SupportingFile("Dockerfile.mustache", this.sourceFolder, "Dockerfile"));
9094
supportingFiles.add(new SupportingFile("gitignore", this.sourceFolder, ".gitignore"));
9195
supportingFiles.add(new SupportingFile("appsettings.json", this.sourceFolder, "appsettings.json"));
9296

93-
supportingFiles.add(new SupportingFile("project.mustache", this.sourceFolder, "project.json"));
97+
supportingFiles.add(new SupportingFile("project.json.mustache", this.sourceFolder, "project.json"));
9498
supportingFiles.add(new SupportingFile("Startup.mustache", this.sourceFolder, "Startup.cs"));
99+
supportingFiles.add(new SupportingFile("Program.mustache", this.sourceFolder, "Program.cs"));
100+
supportingFiles.add(new SupportingFile("web.config", this.sourceFolder, "web.config"));
101+
102+
supportingFiles.add(new SupportingFile("Project.xproj.mustache", this.sourceFolder, this.packageName + ".xproj"));
95103

96104
supportingFiles.add(new SupportingFile("Properties" + File.separator + "launchSettings.json", this.sourceFolder + File.separator + "Properties", "launchSettings.json"));
97105

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
FROM microsoft/aspnet:1.0.0-rc1-final
1+
FROM microsoft/dotnet:latest
2+
3+
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1
24

35
RUN mkdir -p /app/{{packageName}}
46
COPY . /app/{{packageName}}
57
WORKDIR /app/{{packageName}}
6-
RUN ["dnu", "restore"]
7-
RUN ["dnu", "pack", "--out", "artifacts"]
88

99
EXPOSE 5000/tcp
10-
ENTRYPOINT ["dnx", "-p", "project.json", "web"]
10+
11+
RUN ["dotnet", "restore"]
12+
ENTRYPOINT ["dotnet", "run", "-p", "project.json", "web"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
7+
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
8+
</packageSources>
9+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Builder;
8+
9+
namespace {{packageName}}
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
var host = new WebHostBuilder()
16+
.UseKestrel(options =>
17+
{
18+
// options.ThreadCount = 4;
19+
// options.UseHttps("cert.pfx", "certpassword");
20+
options.NoDelay = true;
21+
options.UseConnectionLogging();
22+
})
23+
.UseUrls("http://+:5000" /*, "https://+:5001" */)
24+
.UseContentRoot(Directory.GetCurrentDirectory())
25+
.UseIISIntegration()
26+
.UseStartup<Startup>()
27+
.Build();
28+
29+
host.Run();
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>{{projectGuid}}</ProjectGuid>
10+
<RootNamespace>Sample</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:50352/",
7+
"sslPort": 0
8+
}
9+
},
210
"profiles": {
311
"IIS Express": {
412
"commandName": "IISExpress",
513
"launchBrowser": true,
6-
"launchUrl": "swagger/ui",
14+
"launchUrl": "swagger/ui/index.html",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"web": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"launchUrl": "http://localhost:5000/swagger/ui/index.html",
723
"environmentVariables": {
8-
"ASPNET_ENV": "Development"
24+
"ASPNETCORE_ENVIRONMENT": "Development"
925
}
1026
}
1127
}
12-
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# {{packageName}} - ASP.NET Core 1.0 Server
2+
3+
{{#appDescription}}
4+
{{{appDescription}}}
5+
{{/appDescription}}
6+
7+
## Run
8+
9+
Linux/OS X:
10+
11+
```
12+
sh build.sh
13+
```
14+
15+
Windows:
16+
17+
```
18+
build.bat
19+
```
20+
21+
## Run in Docker
22+
23+
```
24+
cd src/{{packageName}}
25+
docker build -t {{packageName}} .
26+
docker run -p 5000:5000 {{packageName}}
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+

2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815BE834-0656-4C12-84A4-43F2BA4B8BDE}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AFF6BF88-8A7D-4736-AF81-31BCE86B19BD}"
9+
ProjectSection(SolutionItems) = preProject
10+
global.json = global.json
11+
EndProjectSection
12+
EndProject
13+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "{{packageName}}", "src\{{packageName}}\{{packageName}}.xproj", "{{packageGuid}}"
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{3B5990B3-40F1-4148-89B5-84AC71432557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{3B5990B3-40F1-4148-89B5-84AC71432557}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{3B5990B3-40F1-4148-89B5-84AC71432557}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{3B5990B3-40F1-4148-89B5-84AC71432557}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(NestedProjects) = preSolution
30+
{{packageGuid}} = {815BE834-0656-4C12-84A4-43F2BA4B8BDE}
31+
EndGlobalSection
32+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,81 @@
1+
{{>partial_header}}
12
using System;
3+
using System.Collections.Generic;
24
using System.IO;
35
using System.Linq;
4-
using Microsoft.AspNet.Builder;
5-
using Microsoft.AspNet.Hosting;
6+
using System.Threading.Tasks;
7+
using System.Xml.XPath;
8+
using Microsoft.AspNetCore.Builder;
9+
using Microsoft.AspNetCore.Hosting;
610
using Microsoft.Extensions.Configuration;
711
using Microsoft.Extensions.DependencyInjection;
812
using Microsoft.Extensions.Logging;
9-
using Microsoft.Extensions.PlatformAbstractions;
1013
using Newtonsoft.Json.Serialization;
11-
using Swashbuckle.SwaggerGen;
12-
using Swashbuckle.SwaggerGen.XmlComments;
14+
using Swashbuckle.Swagger.Model;
15+
using Swashbuckle.SwaggerGen.Annotations;
1316

1417
namespace {{packageName}}
1518
{
1619
public class Startup
1720
{
1821
private readonly IHostingEnvironment _hostingEnv;
19-
private readonly IApplicationEnvironment _appEnv;
2022
21-
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
23+
public IConfigurationRoot Configuration { get; }
24+
25+
public Startup(IHostingEnvironment env)
2226
{
2327
_hostingEnv = env;
24-
_appEnv = appEnv;
2528
26-
// Set up configuration sources.
2729
var builder = new ConfigurationBuilder()
28-
.AddJsonFile("appsettings.json")
30+
.SetBasePath(env.ContentRootPath)
31+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
32+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
2933
.AddEnvironmentVariables();
3034
Configuration = builder.Build();
3135
}
32-
33-
public IConfigurationRoot Configuration { get; set; }
34-
36+
37+
3538
// This method gets called by the runtime. Use this method to add services to the container.
3639
public void ConfigureServices(IServiceCollection services)
3740
{
38-
string xmlComments = string.Format(@"{0}{4}artifacts{4}{1}{4}{2}{3}{4}{{packageName}}.xml",
39-
GetSolutionBasePath(),
40-
_appEnv.Configuration,
41-
_appEnv.RuntimeFramework.Identifier.ToLower(),
42-
_appEnv.RuntimeFramework.Version.ToString().Replace(".", string.Empty),
43-
Path.DirectorySeparatorChar);
44-
4541
// Add framework services.
4642
services.AddMvc()
4743
.AddJsonOptions(
4844
opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
49-
50-
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
51-
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
52-
// services.AddWebApiConventions();
53-
45+
5446
services.AddSwaggerGen();
55-
services.ConfigureSwaggerDocument(options =>
47+
48+
services.ConfigureSwaggerGen(options =>
5649
{
5750
options.SingleApiVersion(new Info
5851
{
5952
Version = "v1",
6053
Title = "{{packageName}}",
61-
Description = "{{packageName}} (ASP.NET 5 Web API 2.x)"
54+
Description = "{{packageName}} (ASP.NET Core 1.0)"
6255
});
63-
64-
options.OperationFilter(new ApplyXmlActionCommentsFixed(xmlComments));
65-
});
6656

67-
services.ConfigureSwaggerSchema(options => {
68-
options.DescribeAllEnumsAsStrings = true;
69-
options.ModelFilter(new ApplyXmlTypeCommentsFixed(xmlComments));
57+
options.DescribeAllEnumsAsStrings();
58+
59+
var comments = new XPathDocument($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml");
60+
options.OperationFilter<XmlCommentsOperationFilter>(comments);
61+
options.ModelFilter<XmlCommentsModelFilter>(comments);
7062
});
63+
7164
}
7265

7366
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
7467
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
7568
{
76-
loggerFactory.MinimumLevel = LogLevel.Information;
7769
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
7870
loggerFactory.AddDebug();
7971
80-
app.UseIISPlatformHandler();
81-
72+
app.UseMvc();
73+
8274
app.UseDefaultFiles();
8375
app.UseStaticFiles();
8476
85-
app.UseMvc();
86-
87-
app.UseSwaggerGen();
77+
app.UseSwagger();
8878
app.UseSwaggerUi();
8979
}
90-
91-
// Taken from https://github.com/domaindrivendev/Ahoy/blob/master/test/WebSites/Basic/Startup.cs
92-
private string GetSolutionBasePath()
93-
{
94-
var dir = Directory.CreateDirectory(_appEnv.ApplicationBasePath);
95-
while (dir.Parent != null)
96-
{
97-
if (dir.GetDirectories("artifacts").Any())
98-
return dir.FullName;
99-
100-
dir = dir.Parent;
101-
}
102-
throw new InvalidOperationException("Failed to detect solution base path - artifacts not found. Did you run dnu pack --out artifacts?");
103-
}
104-
105-
// Entry point for the application.
106-
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
107-
}
108-
109-
110-
// using Swashbuckle.SwaggerGen.XmlComments;
111-
public class ApplyXmlTypeCommentsFixed : ApplyXmlTypeComments
112-
{
113-
public ApplyXmlTypeCommentsFixed() : base("")
114-
{
115-
throw new NotImplementedException();
116-
}
117-
118-
public ApplyXmlTypeCommentsFixed(string filePath): base(filePath)
119-
{
120-
121-
}
122-
}
123-
124-
public class ApplyXmlActionCommentsFixed : ApplyXmlActionComments
125-
{
126-
public ApplyXmlActionCommentsFixed() : base("")
127-
{
128-
throw new NotImplementedException();
129-
}
130-
131-
public ApplyXmlActionCommentsFixed(string filePath): base(filePath)
132-
{
133-
134-
}
13580
}
136-
}
81+
}

Diff for: modules/swagger-codegen/src/main/resources/aspnet5/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Logging": {
33
"IncludeScopes": false,
44
"LogLevel": {
5-
"Default": "Verbose",
5+
"Default": "Information",
66
"System": "Information",
77
"Microsoft": "Information"
88
}

0 commit comments

Comments
 (0)