Skip to content
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

Add ASP.NET Core 5.0 support #8717

Merged
merged 4 commits into from
Feb 17, 2021
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
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ install:
- ps: Install-Module Pester -Force -Scope CurrentUser
build_script:
- dotnet --info
# build C# aspnetcore 5.0 server
- dotnet build samples\server\petstore\aspnetcore-5.0\Org.OpenAPITools.sln
# build C# aspnetcore 3.1 server
- dotnet build samples\server\petstore\aspnetcore-3.1\Org.OpenAPITools.sln
# build C# aspnetcore 3.0 server
Expand Down
7 changes: 7 additions & 0 deletions bin/configs/aspnetcore-5.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-5.0
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "5.0"
2 changes: 1 addition & 1 deletion docs/generators/aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|aspnetCoreVersion|ASP.NET Core version: 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)| |3.1|
|aspnetCoreVersion|ASP.NET Core version: 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)| |3.1|
|buildTarget|Target to build an application or library| |program|
|classModifier|Class Modifier for controller classes: Empty string or abstract.| ||
|compatibilityVersion|ASP.Net Core CompatibilityVersion| |Version_2_2|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
public static final String GENERATE_BODY = "generateBody";
public static final String BUILD_TARGET = "buildTarget";
public static final String MODEL_CLASS_MODIFIER = "modelClassModifier";
public static final String TARGET_FRAMEWORK= "targetFramework";

public static final String PROJECT_SDK = "projectSdk";
public static final String SDK_WEB = "Microsoft.NET.Sdk.Web";
Expand All @@ -68,7 +69,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
protected int serverPort = 8080;
protected String serverHost = "0.0.0.0";
protected CliOption swashbuckleVersion = new CliOption(SWASHBUCKLE_VERSION, "Swashbuckle version: 3.0.0, 4.0.0, 5.0.0");
protected CliOption aspnetCoreVersion = new CliOption(ASPNET_CORE_VERSION, "ASP.NET Core version: 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)");
protected CliOption aspnetCoreVersion = new CliOption(ASPNET_CORE_VERSION, "ASP.NET Core version: 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)");
private CliOption classModifier = new CliOption(CLASS_MODIFIER, "Class Modifier for controller classes: Empty string or abstract.");
private CliOption operationModifier = new CliOption(OPERATION_MODIFIER, "Operation Modifier can be virtual or abstract");
private CliOption modelClassModifier = new CliOption(MODEL_CLASS_MODIFIER, "Model Class Modifier can be nothing or partial");
Expand Down Expand Up @@ -123,7 +124,7 @@ public AspNetCoreServerCodegen() {
modelTemplateFiles.put("model.mustache", ".cs");
apiTemplateFiles.put("controller.mustache", ".cs");

embeddedTemplateDir = templateDir = "aspnetcore/2.1";
embeddedTemplateDir = templateDir = "aspnetcore/3.0";

// contextually reserved words
// NOTE: C# uses camel cased reserved words, while models are title cased. We don't want lowercase comparisons.
Expand Down Expand Up @@ -190,6 +191,7 @@ public AspNetCoreServerCodegen() {
aspnetCoreVersion.addEnum("2.2", "ASP.NET Core 2.2");
aspnetCoreVersion.addEnum("3.0", "ASP.NET Core 3.0");
aspnetCoreVersion.addEnum("3.1", "ASP.NET Core 3.1");
aspnetCoreVersion.addEnum("5.0", "ASP.NET Core 5.0");
aspnetCoreVersion.setDefault("3.1");
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue());
Expand Down Expand Up @@ -367,7 +369,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("gitignore", packageFolder, ".gitignore"));
supportingFiles.add(new SupportingFile("validateModel.mustache", packageFolder + File.separator + "Attributes", "ValidateModelStateAttribute.cs"));
supportingFiles.add(new SupportingFile("typeConverter.mustache", packageFolder + File.separator + "Converters", "CustomEnumConverter.cs"));
if (aspnetCoreVersion.getOptValue().startsWith("3.")) {
if (aspnetCoreVersion.getOptValue().startsWith("3.") || aspnetCoreVersion.getOptValue().startsWith("5.0")) {
supportingFiles.add(new SupportingFile("OpenApi" + File.separator + "TypeExtensions.mustache", packageFolder + File.separator + "OpenApi", "TypeExtensions.cs"));
}
supportingFiles.add(new SupportingFile("Project.csproj.mustache", packageFolder, packageName + ".csproj"));
Expand Down Expand Up @@ -535,7 +537,7 @@ private void setBuildTarget() {
private void setAspnetCoreVersion(String packageFolder) {
setCliOption(aspnetCoreVersion);

if (aspnetCoreVersion.getOptValue().startsWith("3.")) {
if (aspnetCoreVersion.getOptValue().startsWith("3.") || aspnetCoreVersion.getOptValue().startsWith("5.0")) {
compatibilityVersion = null;
} else if ("2.0".equals(aspnetCoreVersion.getOptValue())) {
compatibilityVersion = null;
Expand All @@ -552,6 +554,7 @@ private void setAspnetCoreVersion(String packageFolder) {

private String determineTemplateVersion(String frameworkVersion) {
switch (frameworkVersion) {
case "5.0":
case "3.1":
return "3.0";

Expand Down Expand Up @@ -593,17 +596,25 @@ private void setIsFramework() {
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so changing to use frameworkReference instead of packageReference ");
useFrameworkReference = true;
additionalProperties.put(USE_FRAMEWORK_REFERENCE, useFrameworkReference);
additionalProperties.put(TARGET_FRAMEWORK, "netcoreapp" + aspnetCoreVersion);
} else if (aspnetCoreVersion.getOptValue().startsWith("5.")) {// default, do nothing
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so changing to use frameworkReference instead of packageReference ");
useFrameworkReference = true;
additionalProperties.put(USE_FRAMEWORK_REFERENCE, useFrameworkReference);
additionalProperties.put(TARGET_FRAMEWORK, "net5.0");
} else {
if (additionalProperties.containsKey(USE_FRAMEWORK_REFERENCE)) {
useFrameworkReference = convertPropertyToBooleanAndWriteBack(USE_FRAMEWORK_REFERENCE);
} else {
additionalProperties.put(USE_FRAMEWORK_REFERENCE, useFrameworkReference);
}
additionalProperties.put(TARGET_FRAMEWORK, "netcoreapp" + aspnetCoreVersion);
}
}

private void setUseNewtonsoft() {
if (aspnetCoreVersion.getOptValue().startsWith("2.")) {
LOGGER.warn("ASP.NET core version 2.X support has been deprecated. Please use ASP.NET core version 3.1 instead");
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so staying on default json library.");
useNewtonsoft = false;
additionalProperties.put(USE_NEWTONSOFT, useNewtonsoft);
Expand All @@ -617,7 +628,7 @@ private void setUseNewtonsoft() {
}

private void setUseEndpointRouting() {
if (aspnetCoreVersion.getOptValue().startsWith("3.")) {
if (aspnetCoreVersion.getOptValue().startsWith("3.") || aspnetCoreVersion.getOptValue().startsWith("5.")) {
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so switching to old style endpoint routing.");
useDefaultRouting = false;
additionalProperties.put(USE_DEFAULT_ROUTING, useDefaultRouting);
Expand All @@ -633,7 +644,7 @@ private void setUseEndpointRouting() {
private void setSwashbuckleVersion() {
setCliOption(swashbuckleVersion);

if (aspnetCoreVersion.getOptValue().startsWith("3.")) {
if (aspnetCoreVersion.getOptValue().startsWith("3.") || aspnetCoreVersion.getOptValue().startsWith("5.")) {
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so changing default Swashbuckle version to 5.0.0.");
swashbuckleVersion.setOptValue("5.0.0");
additionalProperties.put(SWASHBUCKLE_VERSION, swashbuckleVersion.getOptValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>{{packageName}}</Description>
<Copyright>{{packageName}}</Copyright>
<TargetFramework>netcoreapp{{aspnetCoreVersion}}</TargetFramework>
<TargetFramework>{{targetFramework}}</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PreserveCompilationContext>true</PreserveCompilationContext>
{{#isLibrary}}
Expand Down
24 changes: 24 additions & 0 deletions samples/server/petstore/aspnetcore-5.0/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
src/Org.OpenAPITools/Org.OpenAPITools.csproj
28 changes: 28 additions & 0 deletions samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Org.OpenAPITools.sln
README.md
build.bat
build.sh
src/Org.OpenAPITools/.gitignore
src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs
src/Org.OpenAPITools/Authentication/ApiAuthentication.cs
src/Org.OpenAPITools/Controllers/PetApi.cs
src/Org.OpenAPITools/Controllers/StoreApi.cs
src/Org.OpenAPITools/Controllers/UserApi.cs
src/Org.OpenAPITools/Converters/CustomEnumConverter.cs
src/Org.OpenAPITools/Dockerfile
src/Org.OpenAPITools/Filters/BasePathFilter.cs
src/Org.OpenAPITools/Filters/GeneratePathParamsValidationFilter.cs
src/Org.OpenAPITools/Models/ApiResponse.cs
src/Org.OpenAPITools/Models/Category.cs
src/Org.OpenAPITools/Models/Order.cs
src/Org.OpenAPITools/Models/Pet.cs
src/Org.OpenAPITools/Models/Tag.cs
src/Org.OpenAPITools/Models/User.cs
src/Org.OpenAPITools/OpenApi/TypeExtensions.cs
src/Org.OpenAPITools/Program.cs
src/Org.OpenAPITools/Properties/launchSettings.json
src/Org.OpenAPITools/Startup.cs
src/Org.OpenAPITools/appsettings.json
src/Org.OpenAPITools/wwwroot/README.md
src/Org.OpenAPITools/wwwroot/index.html
src/Org.OpenAPITools/wwwroot/openapi-original.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.1.0-SNAPSHOT
22 changes: 22 additions & 0 deletions samples/server/petstore/aspnetcore-5.0/Org.OpenAPITools.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Org.OpenAPITools", "src\Org.OpenAPITools\Org.OpenAPITools.csproj", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions samples/server/petstore/aspnetcore-5.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Org.OpenAPITools - ASP.NET Core 5.0 Server

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.

## Run

Linux/OS X:

```
sh build.sh
```

Windows:

```
build.bat
```
## Run in Docker

```
cd src/Org.OpenAPITools
docker build -t org.openapitools .
docker run -p 5000:8080 org.openapitools
```
9 changes: 9 additions & 0 deletions samples/server/petstore/aspnetcore-5.0/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:: Generated by: https://openapi-generator.tech
::

@echo off

dotnet restore src\Org.OpenAPITools
dotnet build src\Org.OpenAPITools
echo Now, run the following to start the project: dotnet run -p src\Org.OpenAPITools\Org.OpenAPITools.csproj --launch-profile web.
echo.
8 changes: 8 additions & 0 deletions samples/server/petstore/aspnetcore-5.0/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#
# Generated by: https://openapi-generator.tech
#

dotnet restore src/Org.OpenAPITools/ && \
dotnet build src/Org.OpenAPITools/ && \
echo "Now, run the following to start the project: dotnet run -p src/Org.OpenAPITools/Org.OpenAPITools.csproj --launch-profile web"
Loading