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

Make OpenAPI.NET library trim-compatible #1717

Merged
merged 20 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d8eda7a
Make library trim-compatible
captainsafia Jul 4, 2024
08718e1
Avoid using generic overload for all enum types
captainsafia Jul 4, 2024
11466d7
Update PublicApi.Approved.txt
captainsafia Jul 4, 2024
a0b6f9d
Avoid binary compat break in CloneFromCopyConstructor
captainsafia Jul 6, 2024
5b006b2
Add obsoletion attributes and fix CloneFromCopyConstructor
captainsafia Jul 9, 2024
8ea0964
Add ReferenceType.Path and tests for display names
captainsafia Jul 9, 2024
2128408
Guard ReferenceType consumption for ExternalResource
captainsafia Jul 15, 2024
bced7d5
Add trimming test project and fix warnings
captainsafia Jul 17, 2024
be1046d
Apply suggestions from code review
baywet Jul 17, 2024
4cc030d
ci: adds trimming project to solution
baywet Jul 17, 2024
74275b8
ci: adds readers project to trimming test project
baywet Jul 17, 2024
7f7c54a
ci: adds missing trimming root assembly directive
baywet Jul 17, 2024
06b54c3
Fix build, address feedback, and remove Readers from trim tests
captainsafia Jul 17, 2024
c117bc5
Rely on enum fields never being trimmed
captainsafia Jul 18, 2024
35811cc
Address feedback
captainsafia Jul 19, 2024
8267c40
Add back doc comment on M.O.Readers
captainsafia Jul 19, 2024
6200767
Update test/Microsoft.OpenApi.Tests/Attributes/DisplayAttributeTests.cs
MaggieKimani1 Jul 22, 2024
47ad39d
Fix syntax error
MaggieKimani1 Jul 22, 2024
3f597ba
Merge branch 'vnext' into safia/trimmable
MaggieKimani1 Jul 22, 2024
321e20d
Use native AOT-friendly generic overload
MaggieKimani1 Jul 22, 2024
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
7 changes: 7 additions & 0 deletions Microsoft.OpenApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Hidi", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.Hidi.Tests", "test\Microsoft.OpenApi.Hidi.Tests\Microsoft.OpenApi.Hidi.Tests.csproj", "{D8F799DD-04AC-4A13-B344-45A5B944450A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.Trimming.Tests", "test\Microsoft.OpenApi.Trimming.Tests\Microsoft.OpenApi.Trimming.Tests.csproj", "{1D2E0C6E-B103-4CB6-912E-D56FA1501296}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -68,6 +70,10 @@ Global
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Release|Any CPU.Build.0 = Release|Any CPU
{1D2E0C6E-B103-4CB6-912E-D56FA1501296}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D2E0C6E-B103-4CB6-912E-D56FA1501296}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D2E0C6E-B103-4CB6-912E-D56FA1501296}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D2E0C6E-B103-4CB6-912E-D56FA1501296}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -81,6 +87,7 @@ Global
{AD79B61D-88CF-497C-9ED5-41AE3867C5AC} = {6357D7FD-2DE4-4900-ADB9-ABC37052040A}
{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE} = {E546B92F-20A8-49C3-8323-4B25BB78F3E1}
{D8F799DD-04AC-4A13-B344-45A5B944450A} = {6357D7FD-2DE4-4900-ADB9-ABC37052040A}
{1D2E0C6E-B103-4CB6-912E-D56FA1501296} = {6357D7FD-2DE4-4900-ADB9-ABC37052040A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F171EFC-0DB5-4B10-ABFA-AF48D52CC565}
Expand Down
27 changes: 26 additions & 1 deletion src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.Reflection;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.OpenApi.Any
{
Expand All @@ -15,6 +16,8 @@ public class OpenApiAnyCloneHelper
/// </summary>
/// <param name="obj">The object instance.</param>
/// <returns>A clone copy or the object itself.</returns>
[Obsolete("Use native AoT-friendly generic overload of CloneFromCopyConstructor instead.")]
[RequiresUnreferencedCode("CloneFromCopyConstructor is not trim-compatible. Recommended to use native AoT-friendly type-specific overloads of CloneFromCopyConstructor instead.")]
public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj)
{
if (obj != null)
Expand All @@ -32,5 +35,27 @@ public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj)

return obj;
}

/// <summary>
/// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
/// </summary>
/// <param name="obj">The object instance.</param>
/// <returns>A clone copy or the object itself.</returns>
public static T CloneFromCopyConstructor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(T obj) where T : IOpenApiAny
{
if (obj != null)
{
foreach (var ci in typeof(T).GetConstructors())
{
var pi = ci.GetParameters();
if (pi.Length == 1 && pi[0].ParameterType == typeof(T))
{
return (T)ci.Invoke([obj]);
}
}
}

return obj;
}
}
}
Loading
Loading