Skip to content

Commit

Permalink
Support net8 in aspnetcore (OpenAPITools#19051)
Browse files Browse the repository at this point in the history
* Support net8 in aspnetcore

* gen

* typo

* more

* default swashbuckle

* gen

---------

Co-authored-by: Liri S <[email protected]>
  • Loading branch information
ReallyLiri and liriID authored Jul 16, 2024
1 parent c8587bb commit 0002f8c
Show file tree
Hide file tree
Showing 264 changed files with 26,959 additions and 232 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/samples-dotnet8-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Samples C# .Net 8 Server

on:
push:
paths:
- samples/server/petstore/aspnetcore-8.0/**
- samples/server/petstore/aspnetcore-8.0-*/**
pull_request:
paths:
- samples/server/petstore/aspnetcore-8.0/**
- samples/server/petstore/aspnetcore-8.0-*/**
jobs:
build:
name: Build .Net 8 servers
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
- samples/server/petstore/aspnetcore-8.0
- samples/server/petstore/aspnetcore-8.0-NewtonsoftFalse
- samples/server/petstore/aspnetcore-8.0-nullableReferenceTypes
- samples/server/petstore/aspnetcore-8.0-pocoModels
- samples/server/petstore/aspnetcore-8.0-project4Models
- samples/server/petstore/aspnetcore-8.0-useSwashBuckle
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
dotnet-version: '8.0.x'
- name: Build
working-directory: ${{ matrix.sample }}
run: dotnet build Org.OpenAPITools.sln
- name: Test
working-directory: ${{ matrix.sample }}
run: dotnet test Org.OpenAPITools.sln
9 changes: 9 additions & 0 deletions bin/configs/aspnetcore-8.0-NewtonsoftFalse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-NewtonsoftFalse
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
useNewtonsoft: false
9 changes: 9 additions & 0 deletions bin/configs/aspnetcore-8.0-nullableReferenceTypes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-nullableReferenceTypes
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
nullableReferenceTypes: true
9 changes: 9 additions & 0 deletions bin/configs/aspnetcore-8.0-pocoModels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-pocoModels
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
pocoModels: true
9 changes: 9 additions & 0 deletions bin/configs/aspnetcore-8.0-project4Models.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-project4Models
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
useSeparateModelProject: true
11 changes: 11 additions & 0 deletions bin/configs/aspnetcore-8.0-useSwashBuckle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-useSwashBuckle
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
useSwashBuckle: false
buildTarget: library
isLibrary: true
8 changes: 8 additions & 0 deletions bin/configs/aspnetcore-8.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
4 changes: 2 additions & 2 deletions docs/generators/aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|aspnetCoreVersion|ASP.NET Core version: 6.0, 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)|<dl><dt>**2.0**</dt><dd>ASP.NET Core 2.0</dd><dt>**2.1**</dt><dd>ASP.NET Core 2.1</dd><dt>**2.2**</dt><dd>ASP.NET Core 2.2</dd><dt>**3.0**</dt><dd>ASP.NET Core 3.0</dd><dt>**3.1**</dt><dd>ASP.NET Core 3.1</dd><dt>**5.0**</dt><dd>ASP.NET Core 5.0</dd><dt>**6.0**</dt><dd>ASP.NET Core 6.0</dd></dl>|3.1|
|aspnetCoreVersion|ASP.NET Core version: 6.0, 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)|<dl><dt>**2.0**</dt><dd>ASP.NET Core 2.0</dd><dt>**2.1**</dt><dd>ASP.NET Core 2.1</dd><dt>**2.2**</dt><dd>ASP.NET Core 2.2</dd><dt>**3.0**</dt><dd>ASP.NET Core 3.0</dd><dt>**3.1**</dt><dd>ASP.NET Core 3.1</dd><dt>**5.0**</dt><dd>ASP.NET Core 5.0</dd><dt>**6.0**</dt><dd>ASP.NET Core 6.0</dd><dt>**7.0**</dt><dd>ASP.NET Core 7.0</dd><dt>**8.0**</dt><dd>ASP.NET Core 8.0</dd></dl>|8.0|
|buildTarget|Target to build an application or library|<dl><dt>**program**</dt><dd>Generate code for a standalone server</dd><dt>**library**</dt><dd>Generate code for a server abstract class library</dd></dl>|program|
|classModifier|Class Modifier for controller classes: Empty string or abstract.| ||
|compatibilityVersion|ASP.Net Core CompatibilityVersion| |Version_2_2|
Expand All @@ -45,7 +45,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|returnICollection|Return ICollection&lt;T&gt; instead of the concrete type.| |false|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src|
|swashbuckleVersion|Swashbuckle version: 3.0.0 (deprecated), 4.0.0 (deprecated), 5.0.0 (deprecated), 6.4.0|<dl><dt>**3.0.0**</dt><dd>Swashbuckle 3.0.0</dd><dt>**4.0.0**</dt><dd>Swashbuckle 4.0.0</dd><dt>**5.0.0**</dt><dd>Swashbuckle 5.0.0</dd><dt>**6.4.0**</dt><dd>Swashbuckle 6.4.0</dd></dl>|3.0.0|
|swashbuckleVersion|Swashbuckle version: 3.0.0 (deprecated), 4.0.0 (deprecated), 5.0.0 (deprecated), 6.4.0|<dl><dt>**3.0.0**</dt><dd>Swashbuckle 3.0.0</dd><dt>**4.0.0**</dt><dd>Swashbuckle 4.0.0</dd><dt>**5.0.0**</dt><dd>Swashbuckle 5.0.0</dd><dt>**6.4.0**</dt><dd>Swashbuckle 6.4.0</dd></dl>|6.4.0|
|useCollection|Deserialize array types to Collection&lt;T&gt; instead of List&lt;T&gt;.| |false|
|useDateTimeForDate|Use DateTime to model date properties even if DateOnly supported. (.net 6.0+ only)| |false|
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,17 @@ public AspNetServerCodegen() {
aspnetCoreVersion.addEnum("3.1", "ASP.NET Core 3.1");
aspnetCoreVersion.addEnum("5.0", "ASP.NET Core 5.0");
aspnetCoreVersion.addEnum("6.0", "ASP.NET Core 6.0");
aspnetCoreVersion.setDefault("3.1");
aspnetCoreVersion.addEnum("7.0", "ASP.NET Core 7.0");
aspnetCoreVersion.addEnum("8.0", "ASP.NET Core 8.0");
aspnetCoreVersion.setDefault("8.0");
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
cliOptions.add(aspnetCoreVersion);

swashbuckleVersion.addEnum("3.0.0", "Swashbuckle 3.0.0");
swashbuckleVersion.addEnum("4.0.0", "Swashbuckle 4.0.0");
swashbuckleVersion.addEnum("5.0.0", "Swashbuckle 5.0.0");
swashbuckleVersion.addEnum("6.4.0", "Swashbuckle 6.4.0");
swashbuckleVersion.setDefault("3.0.0");
swashbuckleVersion.setDefault("6.4.0");
swashbuckleVersion.setOptValue(swashbuckleVersion.getDefault());
cliOptions.add(swashbuckleVersion);

Expand Down Expand Up @@ -427,7 +429,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("typeConverter.mustache", packageFolder + File.separator + "Converters", "CustomEnumConverter.cs"));
}

if (aspnetCoreVersion.getOptValue().startsWith("3.") || aspnetCoreVersion.getOptValue().startsWith("5.0") || aspnetCoreVersion.getOptValue().startsWith("6.")) {
if (!aspnetCoreVersion.getOptValue().startsWith("2.")) {
supportingFiles.add(new SupportingFile("OpenApi" + File.separator + "TypeExtensions.mustache", packageFolder + File.separator + "OpenApi", "TypeExtensions.cs"));
}

Expand Down Expand Up @@ -681,7 +683,7 @@ private void setBuildTarget() {
private void setAspnetCoreVersion(String packageFolder) {
setCliOption(aspnetCoreVersion);

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

private String determineTemplateVersion(String frameworkVersion) {
switch (frameworkVersion) {
case "8.0":
case "7.0":
case "6.0":
case "5.0":
case "3.1":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prepare": "npm run build"
},
"dependencies": {
"axios": "^1.6.1"
"axios": ""
},
"devDependencies": {
"@types/node": "12.11.5 - 12.20.42",
Expand Down
Loading

0 comments on commit 0002f8c

Please sign in to comment.