Skip to content

Commit f39e200

Browse files
jimschubertwing328
authored andcommitted
C# refactor improvements: .NET Standard and .NET Core (#2187)
* [csharp-refactor] limit available target framework This removes .NET 3.x, .NET 4.0, UWP, and the "5.0" option (which referred to PCL 5.0). This gives us a smaller footprint for maintenance, and doesn't necessarily block consumers from creating custom templates to support those target frameworks. A workaround for users wanting these options is to build against openapi-generator 3.3.4. This moves logic for applying additional properties to strategies per target framework, as a means to reduce maintenance overhead at the cost of maybe a little redundancy between strategies. * [csharp-refactor] Fixing .netstandard support * [csharp-refactor] Fixing netcoreapp2.0 support * [csharp-refactor] Regenerate samples * Fix toLowerCase missing Local.ROOT * [csharp-refactor] Remove unnecessary bash/batch scripts, update appveyor. * Update appveyor.yml to test for dotnet/xunit * Update appveyor.yml Wrap xunit console environment variables in quotes, to prevent yaml syntax error. * Update appveyor.yml Try to use dos-style switches, attempting to remove yaml parse error in appveyor. Previous command matched appveyor docs, but resulted in the parser error. * Update appveyor.yml Wrap full commands for netstandard tests in quotes * Fix linux style slashes in dotnet build, use dotnet test over appveyor xunit * [csharp-refactor] Update generator docs
1 parent cdb447d commit f39e200

File tree

248 files changed

+25352
-2654
lines changed

Some content is hidden

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

248 files changed

+25352
-2654
lines changed

CI/samples.ci/client/petstore/csharp-refactor/OpenAPIClient/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,85 +7,30 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod
77
OpenAPI spec version: 1.0.0
88
99
-->
10-
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
10+
<Project Sdk="Microsoft.NET.Sdk">
11+
1112
<PropertyGroup>
12-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
13-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
14-
<ProjectGuid>{19F1DEBC-DE5E-4517-8062-F000CD499087}</ProjectGuid>
15-
<OutputType>Library</OutputType>
16-
<AppDesignerFolder>Properties</AppDesignerFolder>
17-
<RootNamespace>Org.OpenAPITools.Test</RootNamespace>
18-
<AssemblyName>Org.OpenAPITools.Test</AssemblyName>
19-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
20-
<FileAlignment>512</FileAlignment>
21-
</PropertyGroup>
22-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23-
<DebugSymbols>true</DebugSymbols>
24-
<DebugType>full</DebugType>
25-
<Optimize>false</Optimize>
26-
<OutputPath>bin\Debug\</OutputPath>
27-
<DefineConstants>DEBUG;TRACE</DefineConstants>
28-
<ErrorReport>prompt</ErrorReport>
29-
<WarningLevel>4</WarningLevel>
30-
</PropertyGroup>
31-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32-
<DebugType>pdbonly</DebugType>
33-
<Optimize>true</Optimize>
34-
<OutputPath>bin\Release\</OutputPath>
35-
<DefineConstants>TRACE</DefineConstants>
36-
<ErrorReport>prompt</ErrorReport>
37-
<WarningLevel>4</WarningLevel>
13+
<TargetFramework>netcoreapp2.0</TargetFramework>
14+
15+
<IsPackable>false</IsPackable>
3816
</PropertyGroup>
39-
<ItemGroup>
40-
<Reference Include="System" />
41-
<Reference Include="System.Core" />
42-
<Reference Include="System.Xml.Linq" />
43-
<Reference Include="System.Data.DataSetExtensions" />
44-
<Reference Include="System.ComponentModel.DataAnnotations" />
45-
<Reference Include="Microsoft.CSharp" />
46-
<Reference Include="System.Data" />
47-
<Reference Include="System.Runtime.Serialization" />
48-
<Reference Include="System.Xml" />
49-
<Reference Include="Newtonsoft.Json">
50-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
51-
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
52-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
53-
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
54-
</Reference>
55-
<Reference Include="JsonSubTypes">
56-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.1.5.1\lib\net45\JsonSubTypes.dll</HintPath>
57-
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.1.5.1\lib\net45\JsonSubTypes.dll</HintPath>
58-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.1.5.1\lib\net45\JsonSubTypes.dll</HintPath>
59-
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\JsonSubTypes.1.5.1\lib\net45\JsonSubTypes.dll</HintPath>
60-
</Reference>
61-
<Reference Include="RestSharp">
62-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\RestSharp.106.5.4\lib\net452\RestSharp.dll</HintPath>
63-
<HintPath Condition="Exists('..\packages')">..\packages\RestSharp.106.5.4\lib\net452\RestSharp.dll</HintPath>
64-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\RestSharp.106.5.4\lib\net452\RestSharp.dll</HintPath>
65-
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\RestSharp.106.5.4\lib\net452\RestSharp.dll</HintPath>
66-
</Reference>
67-
<Reference Include="nunit.framework">
68-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
69-
<HintPath Condition="Exists('..\packages')">..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
70-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
71-
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
72-
</Reference>
73-
</ItemGroup>
74-
<ItemGroup>
75-
<Compile Include="**\*.cs" Exclude="obj\**" />
76-
</ItemGroup>
77-
<ItemGroup>
78-
<None Include="packages.config" />
79-
</ItemGroup>
80-
<Import Project="$(MsBuildToolsPath)\Microsoft.CSharp.targets" />
17+
8118
<ItemGroup>
8219
<ProjectReference Include="..\Org.OpenAPITools\Org.OpenAPITools.csproj">
83-
<Project>{321C8C3F-0156-40C1-AE42-D59761FB9B6C}</Project>
8420
<Name>Org.OpenAPITools</Name>
8521
</ProjectReference>
8622
</ItemGroup>
8723
<ItemGroup>
8824
<EmbeddedResource Include="linux-logo.png" />
8925
</ItemGroup>
26+
<ItemGroup>
27+
<PackageReference Include="CompareNETObjects" Version="4.57.0" />
28+
<PackageReference Include="JsonSubTypes" Version="1.5.2" />
29+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
30+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
31+
<PackageReference Include="xunit" Version="2.4.1" />
32+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
33+
<PackageReference Include="RestSharp" Version="106.6.7" />
34+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
35+
</ItemGroup>
9036
</Project>
91-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
OpenAPI Petstore
4+
5+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
6+
7+
OpenAPI spec version: 1.0.0
8+
9+
-->
10+
<Project Sdk="Microsoft.NET.Sdk">
11+
12+
<PropertyGroup>
13+
<TargetFramework>netcoreapp2.0</TargetFramework>
14+
15+
<IsPackable>false</IsPackable>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\Org.OpenAPITools\Org.OpenAPITools.csproj">
20+
<Name>Org.OpenAPITools</Name>
21+
</ProjectReference>
22+
</ItemGroup>
23+
<ItemGroup>
24+
<EmbeddedResource Include="linux-logo.png" />
25+
</ItemGroup>
26+
<ItemGroup>
27+
<PackageReference Include="CompareNETObjects" Version="4.57.0" />
28+
<PackageReference Include="JsonSubTypes" Version="1.5.2" />
29+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
30+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
31+
<PackageReference Include="xunit" Version="2.4.1" />
32+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
33+
<PackageReference Include="RestSharp" Version="106.6.7" />
34+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
35+
</ItemGroup>
36+
</Project>

appveyor.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# for CI with appveyor.yml
22
# Ref: http://www.yegor256.com/2015/01/10/windows-appveyor-maven.html
33
version: '{branch}-{build}'
4-
os: Windows Server 2012
4+
image: Visual Studio 2017
55
hosts:
66
petstore.swagger.io: 127.0.0.1
77
install:
@@ -23,9 +23,10 @@ install:
2323
- git clone https://github.com/wing328/swagger-samples
2424
- ps: Start-Process -FilePath 'C:\maven\apache-maven-3.2.5\bin\mvn' -ArgumentList 'jetty:run' -WorkingDirectory "$env:appveyor_build_folder\swagger-samples\java\java-jersey-jaxrs-ci"
2525
build_script:
26+
- dotnet --info
2627
# build C# API client (refactor)
27-
- nuget restore samples\client\petstore\csharp-refactor\OpenAPIClient\Org.OpenAPITools.sln
28-
- msbuild samples\client\petstore\csharp-refactor\OpenAPIClient\Org.OpenAPITools.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
28+
- dotnet build samples\client\petstore\csharp-refactor\OpenAPIClient\Org.OpenAPITools.sln
29+
- dotnet build samples\client\petstore\csharp-refactor\OpenAPIClientCore\Org.OpenAPITools.sln
2930
# build C# API client
3031
- nuget restore samples\client\petstore\csharp\OpenAPIClient\Org.OpenAPITools.sln
3132
- msbuild samples\client\petstore\csharp\OpenAPIClient\Org.OpenAPITools.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
@@ -41,7 +42,8 @@ test_script:
4142
# restore test-related files
4243
- copy /b/v/y CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
4344
# test c# API client (refactor)
44-
- nunit-console samples\client\petstore\csharp-refactor\OpenAPIClient\src\Org.OpenAPITools.Test\bin\Debug\Org.OpenAPITools.Test.dll --result=myresults.xml;format=AppVeyor
45+
- dotnet test samples\client\petstore\csharp-refactor\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
46+
- dotnet test samples\client\petstore\csharp-refactor\OpenAPIClientCore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
4547
# test c# API client
4648
- nunit-console samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\bin\Debug\Org.OpenAPITools.Test.dll --result=myresults.xml;format=AppVeyor
4749
# test c# API client (with PropertyChanged)

bin/csharp-refactor-petstore-all.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
#!/bin/sh
22

3-
# C# Petstore API client (.NET 3.5)
3+
# C# Petstore API client .NET Standard 2.0
44
./bin/csharp-refactor-petstore.sh
55

6-
# C# Petstore API client with PropertyChanged
7-
./bin/csharp-refactor-property-changed-petstore.sh
8-
9-
# C# Petstore API client (v5.0 for .net standarnd 1.3+)
10-
./bin/csharp-refactor-petstore-net-standard.sh
11-
12-
# C# Petstore API client (.NET 4.0)
13-
./bin/csharp-refactor-petstore-net-40.sh
14-
15-
# C# Petstore API client (.NET 3.5)
16-
./bin/csharp-refactor-petstore-net-35.sh
17-
6+
# C# Petstore API client .NET Core 2.0
7+
./bin/csharp-refactor-petstore-netcore.sh
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
echo "# START SCRIPT: $SCRIPT"
5+
6+
while [ -h "$SCRIPT" ] ; do
7+
ls=`ls -ld "$SCRIPT"`
8+
link=`expr "$ls" : '.*-> \(.*\)$'`
9+
if expr "$link" : '/.*' > /dev/null; then
10+
SCRIPT="$link"
11+
else
12+
SCRIPT=`dirname "$SCRIPT"`/"$link"
13+
fi
14+
done
15+
16+
if [ ! -d "${APP_DIR}" ]; then
17+
APP_DIR=`dirname "$SCRIPT"`/..
18+
APP_DIR=`cd "${APP_DIR}"; pwd`
19+
fi
20+
21+
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
22+
outdir="samples/client/petstore/csharp-refactor/OpenAPIClientCore"
23+
24+
if [ ! -f "$executable" ]
25+
then
26+
mvn -B clean package
27+
fi
28+
29+
# if you've executed sbt assembly previously it will use that instead.
30+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
31+
ags="generate -t modules/openapi-generator/src/main/resources/csharp-refactor/ -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g csharp-refactor -o ${outdir} --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C},useCompareNetObjects=true,targetFramework=netcoreapp2.0 $@"
32+
33+
java $JAVA_OPTS -jar $executable $ags
34+
35+
# restore csproj file
36+
echo "restore csproject file: CI/samples/client/petstore/csharp-refactor/OpenAPIClientCore/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj"
37+
cp ./CI/samples.ci/client/petstore/csharp-refactor/OpenAPIClientCore/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj ./samples/client/petstore/csharp-refactor/OpenAPIClientCore/src/Org.OpenAPITools.Test/
38+

docs/generators/csharp-refactor.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sidebar_label: csharp-refactor
1212
|sourceFolder|source folder for generated code| |src|
1313
|packageGuid|The GUID that will be associated with the C# project| |null|
1414
|interfacePrefix|Prefix interfaces with a community standard or widely accepted prefix.| |I|
15-
|targetFramework|The target .NET framework version.|<dl><dt>**v3.5**</dt><dd>.NET Framework 3.5 compatible</dd><dt>**v4.0**</dt><dd>.NET Framework 4.0 compatible</dd><dt>**v4.5.2**</dt><dd>.NET Framework 4.5.2+ compatible</dd><dt>**v5.0**</dt><dd>.NET Standard 1.3 compatible</dd><dt>**uwp**</dt><dd>Universal Windows Platform (IMPORTANT: this will be decommissioned and replaced by v5.0)</dd><dl>|v4.5.2|
15+
|targetFramework|The target .NET framework version.|<dl><dt>**netstandard1.3**</dt><dd>.NET Standard 1.3 compatible</dd><dt>**netstandard1.4**</dt><dd>.NET Standard 1.4 compatible</dd><dt>**netstandard1.5**</dt><dd>.NET Standard 1.5 compatible</dd><dt>**netstandard1.6**</dt><dd>.NET Standard 1.6 compatible</dd><dt>**netstandard2.0**</dt><dd>.NET Standard 2.0 compatible</dd><dt>**netcoreapp2.0**</dt><dd>.NET Core 2.0 compatible</dd><dl>|v4.6.1|
1616
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |PascalCase|
1717
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
1818
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
@@ -23,7 +23,6 @@ sidebar_label: csharp-refactor
2323
|optionalAssemblyInfo|Generate AssemblyInfo.cs.| |true|
2424
|optionalProjectFile|Generate {PackageName}.csproj.| |true|
2525
|optionalEmitDefaultValues|Set DataMember's EmitDefaultValue.| |false|
26-
|generatePropertyChanged|Specifies a AssemblyDescription for the .NET Framework global assembly attributes stored in the AssemblyInfo file.| |false|
2726
|nonPublicApi|Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.| |false|
2827
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
2928
|netCoreProjectFile|Use the new format (.NET Core) for .NET project files (.csproj).| |false|

0 commit comments

Comments
 (0)