-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Update the Asp.Net core server generator to support Asp.net Core 2.1 #1008
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c9faaa0
Update the .net core sdk to v2.1 and update the asp.net packages used.
SeanFarrow 903c73c
Upgrade the SwashBuckle Asp.Net Core package to v3.0.0.
SeanFarrow 232f4fb
Update the AppSettings json file and add a file used in development.
SeanFarrow 25ae050
Update the program template to use the web host builder class.
SeanFarrow ecf95f7
Update the startup class to use the Asp.Net 2.1 paradigms.
SeanFarrow dbf5aef
Update the launch settings json file.
SeanFarrow 0c6ec44
Update the controller template to derive from the ControllerBase clas…
SeanFarrow cbeeed1
Add the SwashBuckle annotations package.
SeanFarrow 49bb05d
Add the SwashBuckle.AspNetCore.Annotations namespace to the controlle…
SeanFarrow fdf631c
Update the Startup template to add comments to the Configuration prop…
SeanFarrow 1387843
Update the startup class so we don't need to inject the hosting envir…
SeanFarrow 5002042
Update the program class to have hte recommended CreateWebHostBuilder…
SeanFarrow 5f9aa8c
Update the asp.net core pet store sample server.
SeanFarrow a5daacd
add back aspnetcore 2.0 template via option
wing328 0545281
remove web.config for aspnet core 2.1
wing328 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Dockerfile.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM microsoft/aspnetcore-build:2.0 AS build-env | ||
WORKDIR /app | ||
|
||
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 | ||
|
||
# copy csproj and restore as distinct layers | ||
COPY *.csproj ./ | ||
RUN dotnet restore | ||
|
||
# copy everything else and build | ||
COPY . ./ | ||
RUN dotnet publish -c Release -o out | ||
|
||
# build runtime image | ||
FROM microsoft/aspnetcore:2.0 | ||
WORKDIR /app | ||
COPY --from=build-env /app/out . | ||
ENTRYPOINT ["dotnet", "{{packageName}}.dll"] |
50 changes: 50 additions & 0 deletions
50
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Filters/BasePathFilter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using Swashbuckle.AspNetCore.Swagger; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace {{packageName}}.Filters | ||
{ | ||
/// <summary> | ||
/// BasePath Document Filter sets BasePath property of Swagger and removes it from the individual URL paths | ||
/// </summary> | ||
public class BasePathFilter : IDocumentFilter | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="basePath">BasePath to remove from Operations</param> | ||
public BasePathFilter(string basePath) | ||
{ | ||
BasePath = basePath; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the BasePath of the Swagger Doc | ||
/// </summary> | ||
/// <returns>The BasePath of the Swagger Doc</returns> | ||
public string BasePath { get; } | ||
|
||
/// <summary> | ||
/// Apply the filter | ||
/// </summary> | ||
/// <param name="swaggerDoc">SwaggerDocument</param> | ||
/// <param name="context">FilterContext</param> | ||
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context) | ||
{ | ||
swaggerDoc.BasePath = BasePath; | ||
|
||
var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList(); | ||
|
||
foreach (var path in pathsToModify) | ||
{ | ||
if (path.Key.StartsWith(BasePath)) | ||
{ | ||
string newKey = Regex.Replace(path.Key, $"^{BasePath}", string.Empty); | ||
swaggerDoc.Paths.Remove(path.Key); | ||
swaggerDoc.Paths.Add(newKey, path.Value); | ||
} | ||
} | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...tor/src/main/resources/aspnetcore/2.1/Filters/GeneratePathParamsValidationFilter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Mvc.Controllers; | ||
using Swashbuckle.AspNetCore.Swagger; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace {{packageName}}.Filters | ||
{ | ||
/// <summary> | ||
/// Path Parameter Validation Rules Filter | ||
/// </summary> | ||
public class GeneratePathParamsValidationFilter : IOperationFilter | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="operation">Operation</param> | ||
/// <param name="context">OperationFilterContext</param> | ||
public void Apply(Operation operation, OperationFilterContext context) | ||
{ | ||
var pars = context.ApiDescription.ParameterDescriptions; | ||
|
||
foreach (var par in pars) | ||
{ | ||
var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name); | ||
|
||
var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes; | ||
|
||
if (attributes != null && attributes.Count() > 0 && swaggerParam != null) | ||
{ | ||
// Required - [Required] | ||
var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute)); | ||
if (requiredAttr != null) | ||
{ | ||
swaggerParam.Required = true; | ||
} | ||
|
||
// Regex Pattern [RegularExpression] | ||
var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute)); | ||
if (regexAttr != null) | ||
{ | ||
string regex = (string)regexAttr.ConstructorArguments[0].Value; | ||
if (swaggerParam is NonBodyParameter) | ||
{ | ||
((NonBodyParameter)swaggerParam).Pattern = regex; | ||
} | ||
} | ||
|
||
// String Length [StringLength] | ||
int? minLenght = null, maxLength = null; | ||
var stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute)); | ||
if (stringLengthAttr != null) | ||
{ | ||
if (stringLengthAttr.NamedArguments.Count == 1) | ||
{ | ||
minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value; | ||
} | ||
maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value; | ||
} | ||
|
||
var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute)); | ||
if (minLengthAttr != null) | ||
{ | ||
minLenght = (int)minLengthAttr.ConstructorArguments[0].Value; | ||
} | ||
|
||
var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute)); | ||
if (maxLengthAttr != null) | ||
{ | ||
maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value; | ||
} | ||
|
||
if (swaggerParam is NonBodyParameter) | ||
{ | ||
((NonBodyParameter)swaggerParam).MinLength = minLenght; | ||
((NonBodyParameter)swaggerParam).MaxLength = maxLength; | ||
} | ||
|
||
// Range [Range] | ||
var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute)); | ||
if (rangeAttr != null) | ||
{ | ||
int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value; | ||
int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value; | ||
|
||
if (swaggerParam is NonBodyParameter) | ||
{ | ||
((NonBodyParameter)swaggerParam).Minimum = rangeMin; | ||
((NonBodyParameter)swaggerParam).Maximum = rangeMax; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Program.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore; | ||
|
||
namespace {{packageName}} | ||
{ | ||
/// <summary> | ||
/// Program | ||
/// </summary> | ||
public class Program | ||
{ | ||
/// <summary> | ||
/// Main | ||
/// </summary> | ||
/// <param name="args"></param> | ||
public static void Main(string[] args) | ||
{ | ||
CreateWebHostBuilder(args).Build().Run(); | ||
} | ||
|
||
/// <summary> | ||
/// Create the web host builder. | ||
/// </summary> | ||
/// <param name="args"></param> | ||
/// <returns>IWebHostBuilder</returns> | ||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.UseUrls("http://0.0.0.0:{{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}8080{{/serverPort}}/"); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Project.csproj.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<Description>{{packageName}}</Description> | ||
<Copyright>{{packageName}}</Copyright> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
<AssemblyName>{{packageName}}</AssemblyName> | ||
<PackageId>{{packageName}}</PackageId> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
{{#useSwashbuckle}} | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0"/> | ||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" /> | ||
{{/useSwashbuckle}} | ||
</ItemGroup> | ||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" /> | ||
</ItemGroup> | ||
</Project> |
30 changes: 30 additions & 0 deletions
30
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:61788", | ||
"sslPort": 44301 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"WebApplication1": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeanFarrow do we need to update the line 1 and 15 to use
microsoft/aspnetcore-build:2.1
instead?