Skip to content

Commit ea3ab72

Browse files
authored
Merge pull request #1192 from json-api-dotnet/multi-target-annotations
Multi-target Annotations against .NET Standard 1.0
2 parents 2e2c123 + 70c06b9 commit ea3ab72

19 files changed

+191
-2
lines changed

Diff for: JsonApiDotNetCore.sln

+15
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonApiDotNetCore.Annotatio
5353
EndProject
5454
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabasePerTenantExample", "src\Examples\DatabasePerTenantExample\DatabasePerTenantExample.csproj", "{60334658-BE51-43B3-9C4D-F2BBF56C89CE}"
5555
EndProject
56+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnnotationTests", "test\AnnotationTests\AnnotationTests.csproj", "{24B0C12F-38CD-4245-8785-87BEFAD55B00}"
57+
EndProject
5658
Global
5759
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5860
Debug|Any CPU = Debug|Any CPU
@@ -267,6 +269,18 @@ Global
267269
{60334658-BE51-43B3-9C4D-F2BBF56C89CE}.Release|x64.Build.0 = Release|Any CPU
268270
{60334658-BE51-43B3-9C4D-F2BBF56C89CE}.Release|x86.ActiveCfg = Release|Any CPU
269271
{60334658-BE51-43B3-9C4D-F2BBF56C89CE}.Release|x86.Build.0 = Release|Any CPU
272+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
273+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|Any CPU.Build.0 = Debug|Any CPU
274+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x64.ActiveCfg = Debug|Any CPU
275+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x64.Build.0 = Debug|Any CPU
276+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x86.ActiveCfg = Debug|Any CPU
277+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x86.Build.0 = Debug|Any CPU
278+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|Any CPU.ActiveCfg = Release|Any CPU
279+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|Any CPU.Build.0 = Release|Any CPU
280+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x64.ActiveCfg = Release|Any CPU
281+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x64.Build.0 = Release|Any CPU
282+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x86.ActiveCfg = Release|Any CPU
283+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x86.Build.0 = Release|Any CPU
270284
EndGlobalSection
271285
GlobalSection(SolutionProperties) = preSolution
272286
HideSolutionNode = FALSE
@@ -289,6 +303,7 @@ Global
289303
{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
290304
{83FF097C-C8C6-477B-9FAB-DF99B84978B5} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
291305
{60334658-BE51-43B3-9C4D-F2BBF56C89CE} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
306+
{24B0C12F-38CD-4245-8785-87BEFAD55B00} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
292307
EndGlobalSection
293308
GlobalSection(ExtensibilityGlobals) = postSolution
294309
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}

Diff for: src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
3+
<TargetFrameworks>$(TargetFrameworkName);netstandard1.0</TargetFrameworks>
44
<IsPackable>true</IsPackable>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<RootNamespace>JsonApiDotNetCore</RootNamespace>
7+
<LangVersion>latest</LangVersion>
78
</PropertyGroup>
89

910
<PropertyGroup>
@@ -27,4 +28,21 @@
2728
<PackagePath></PackagePath>
2829
</None>
2930
</ItemGroup>
31+
32+
<!-- We multi-target against NetStandard solely to enable consumers to share their models project with .NET Framework code. -->
33+
34+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
35+
<Using Remove="System.Net.Http" />
36+
</ItemGroup>
37+
38+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
39+
<Compile Remove="**/*.cs" />
40+
<Compile Include="**/*.shared.cs" />
41+
<Compile Include="**/*.netstandard.cs" />
42+
</ItemGroup>
43+
44+
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.0' ">
45+
<Compile Remove="**/*.netstandard.cs" />
46+
<None Include="**/*.netstandard.cs" />
47+
</ItemGroup>
3048
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class AttrAttribute : ResourceFieldAttribute
11+
{
12+
/// <summary />
13+
public AttrCapabilities Capabilities { get; set; }
14+
}

Diff for: src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrCapabilities.cs renamed to src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrCapabilities.shared.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using JetBrains.Annotations;
2+
13
namespace JsonApiDotNetCore.Resources.Annotations;
24

35
/// <summary>
46
/// Indicates capabilities that can be performed on an <see cref="AttrAttribute" />.
57
/// </summary>
8+
[PublicAPI]
69
[Flags]
710
public enum AttrCapabilities
811
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class EagerLoadAttribute : Attribute
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class HasManyAttribute : RelationshipAttribute
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class HasOneAttribute : RelationshipAttribute
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
public abstract class RelationshipAttribute : ResourceFieldAttribute
10+
{
11+
/// <summary />
12+
public LinkTypes Links { get; set; } = LinkTypes.NotConfigured;
13+
14+
/// <summary />
15+
public bool CanInclude { get; set; } = true;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
public abstract class ResourceFieldAttribute : Attribute
10+
{
11+
/// <summary />
12+
public string PublicName { get; set; } = null!;
13+
}

Diff for: src/JsonApiDotNetCore.Annotations/Resources/IIdentifiable.cs renamed to src/JsonApiDotNetCore.Annotations/Resources/IIdentifiable.shared.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using JetBrains.Annotations;
2+
13
namespace JsonApiDotNetCore.Resources;
24

35
/// <summary>
46
/// Defines the basic contract for a JSON:API resource. All resource classes must implement <see cref="IIdentifiable{TId}" />.
57
/// </summary>
8+
[PublicAPI]
69
public interface IIdentifiable
710
{
811
/// <summary>
@@ -22,6 +25,7 @@ public interface IIdentifiable
2225
/// <typeparam name="TId">
2326
/// The resource identifier type.
2427
/// </typeparam>
28+
[PublicAPI]
2529
public interface IIdentifiable<TId> : IIdentifiable
2630
{
2731
/// <summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace JsonApiDotNetCore.Resources;
2+
3+
/// <summary>
4+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
5+
/// </summary>
6+
public abstract class Identifiable<TId> : IIdentifiable<TId>
7+
{
8+
/// <summary />
9+
public virtual TId Id { get; set; } = default!;
10+
11+
/// <summary />
12+
public string? StringId { get; set; }
13+
14+
/// <summary />
15+
public string? LocalId { get; set; }
16+
}

Diff for: test/AnnotationTests/AnnotationTests.csproj

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>$(TargetFrameworkName);netstandard1.0</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<None Update="xunit.runner.json">
9+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
10+
</None>
11+
</ItemGroup>
12+
13+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
14+
<Using Remove="System.Net.Http" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\src\JsonApiDotNetCore.Annotations\JsonApiDotNetCore.Annotations.csproj" />
19+
</ItemGroup>
20+
</Project>

Diff for: test/AnnotationTests/Models/HiddenNode.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using JetBrains.Annotations;
2+
using JsonApiDotNetCore.Resources;
3+
using JsonApiDotNetCore.Resources.Annotations;
4+
5+
namespace AnnotationTests.Models;
6+
7+
[PublicAPI]
8+
[NoResource]
9+
[ResourceLinks(TopLevelLinks = LinkTypes.None, ResourceLinks = LinkTypes.None, RelationshipLinks = LinkTypes.None)]
10+
public sealed class HiddenNode : Identifiable<Guid>
11+
{
12+
[EagerLoad]
13+
public HiddenNode? Parent { get; set; }
14+
}

Diff for: test/AnnotationTests/Models/TreeNode.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using JetBrains.Annotations;
2+
using JsonApiDotNetCore.Controllers;
3+
using JsonApiDotNetCore.Resources;
4+
using JsonApiDotNetCore.Resources.Annotations;
5+
6+
namespace AnnotationTests.Models;
7+
8+
[PublicAPI]
9+
[Resource(PublicName = "tree-node", ControllerNamespace = "Models", GenerateControllerEndpoints = JsonApiEndpoints.Query)]
10+
public sealed class TreeNode : Identifiable<long>
11+
{
12+
[Attr(PublicName = "name", Capabilities = AttrCapabilities.AllowSort)]
13+
public string? DisplayName { get; set; }
14+
15+
[HasOne(PublicName = "orders", CanInclude = true, Links = LinkTypes.All)]
16+
public TreeNode? Parent { get; set; }
17+
18+
[HasMany(PublicName = "orders", CanInclude = true, Links = LinkTypes.All)]
19+
public ISet<TreeNode> Children { get; set; } = new HashSet<TreeNode>();
20+
}

0 commit comments

Comments
 (0)