-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sanitize generated property names, may be overly strict added new tests that pull an unofficial generated openapi document describing the Twitch API * Update src/libs/OpenApiGenerator.Core/Models/PropertyData.cs Co-authored-by: Konstantin S. <[email protected]> * add UnsanitaryName init property helper to PropertyData for use in `PropertyData.Default with { ... }` patterns * add opt-out word separation handling step to SanitizeName for use by the UnsanitaryName init helper * unify code that handles of word separators in PropertyData to reduce maintenance * add post-HandleWordSeparators empty string scenario comment out inspection helper from OpenApiGenerator.IntegrationTests.Twitch.Data.csproj accept changes for Properties (NOTE: EnumValues unsanitized) --------- Co-authored-by: Konstantin S. <[email protected]>
- Loading branch information
Showing
10 changed files
with
232 additions
and
17 deletions.
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
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
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
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
54 changes: 54 additions & 0 deletions
54
...nerator.IntegrationTests.Twitch.Data/OpenApiGenerator.IntegrationTests.Twitch.Data.csproj
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,54 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<Import Project="../../libs/OpenApiGenerator/OpenApiGenerator.props" /> | ||
|
||
<PropertyGroup> | ||
<OpenApiGenerator_Namespace>OpenApiGenerator.IntegrationTests.Twitch</OpenApiGenerator_Namespace> | ||
<OpenApiGenerator_GenerateSdk>false</OpenApiGenerator_GenerateSdk> | ||
<OpenApiGenerator_GenerateModels>true</OpenApiGenerator_GenerateModels> | ||
<OpenApiGenerator_GenerateSuperTypeForJsonSerializerContext>true</OpenApiGenerator_GenerateSuperTypeForJsonSerializerContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="Resources\openapi.json" /> | ||
</ItemGroup> | ||
|
||
<!-- for inspection --> | ||
<!--<PropertyGroup> | ||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Remove="Generated\**\*" /> | ||
<None Include="Generated\**\*" /> | ||
</ItemGroup>--> | ||
|
||
|
||
<Target Name="FetchTwitchOpenApiJson" BeforeTargets="Build;BeforeCompile;CompileDesignTime"> | ||
<!-- Download the OpenAPI JSON file (if expired) --> | ||
<DownloadFile | ||
SourceUrl="https://twitch-api-swagger.surge.sh/openapi.json" | ||
DestinationFolder="$(ProjectDir)Resources" | ||
DestinationFileName="openapi.json" | ||
SkipUnchangedFiles="true" | ||
Retries="2" /> | ||
</Target> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> | ||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" /> | ||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.14" /> | ||
<PackageReference Include="SharpYaml" Version="2.1.1" /> | ||
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\libs\OpenApiGenerator.Core\OpenApiGenerator.Core.csproj" OutputItemType="Analyzer" /> | ||
<ProjectReference Include="..\..\libs\OpenApiGenerator\OpenApiGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
src/tests/OpenApiGenerator.IntegrationTests.Twitch.Data/Resources/openapi.json
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
.../OpenApiGenerator.IntegrationTests.Twitch/OpenApiGenerator.IntegrationTests.Twitch.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<Import Project="../../libs/OpenApiGenerator/OpenApiGenerator.props" /> | ||
|
||
<PropertyGroup> | ||
<OpenApiGenerator_GenerateSdk>false</OpenApiGenerator_GenerateSdk> | ||
<OpenApiGenerator_GenerateMethods>true</OpenApiGenerator_GenerateMethods> | ||
<OpenApiGenerator_GenerateConstructors>true</OpenApiGenerator_GenerateConstructors> | ||
<OpenApiGenerator_JsonSerializerContext>OpenApiGenerator.IntegrationTests.Twitch.SourceGenerationContext</OpenApiGenerator_JsonSerializerContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Label="Base packages"> | ||
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.4.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.4.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="GlobalUsings"> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
<Using Include="FluentAssertions" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="H.Resources.Generator" Version="1.6.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> | ||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" /> | ||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.14" /> | ||
<PackageReference Include="SharpYaml" Version="2.1.1" /> | ||
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\libs\OpenApiGenerator.Core\OpenApiGenerator.Core.csproj" OutputItemType="Analyzer" /> | ||
<ProjectReference Include="..\..\libs\OpenApiGenerator\OpenApiGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="..\OpenApiGenerator.IntegrationTests.Data\OpenApiGenerator.IntegrationTests.Data.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
7 changes: 7 additions & 0 deletions
7
src/tests/OpenApiGenerator.IntegrationTests.Twitch/SourceGenerationContext.cs
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,7 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenApiGenerator.IntegrationTests.Twitch; | ||
|
||
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
[JsonSerializable(typeof(OpenApiGeneratorTrimmableSupport))] | ||
internal sealed partial class SourceGenerationContext : JsonSerializerContext; |
28 changes: 28 additions & 0 deletions
28
src/tests/OpenApiGenerator.IntegrationTests.Twitch/Tests.cs
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,28 @@ | ||
using System.Text.Json; | ||
|
||
namespace OpenApiGenerator.IntegrationTests.Twitch; | ||
|
||
[TestClass] | ||
public class NSwagGeneratorTests | ||
{ | ||
[TestMethod] | ||
public void Models() | ||
{ | ||
var json = JsonSerializer.Serialize(new Error | ||
{ | ||
Error1 = new() | ||
{ | ||
Title = "title", | ||
Message = "message", | ||
} | ||
}); | ||
|
||
var error = JsonSerializer.Deserialize<Error>(json); | ||
error.Should().NotBeNull(); | ||
error!.Error1.Should().BeEquivalentTo(new ErrorError | ||
{ | ||
Title = "title", | ||
Message = "message", | ||
}); | ||
} | ||
} |
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