Skip to content

Commit b442519

Browse files
author
Bart Koelman
authored
Move resource annotations into separate package (#1127)
* Moved resource-related attributes and (I)Identifiable to separate package * Fixed broken links in doc-comments * Update ROADMAP.md
1 parent b2abccb commit b442519

30 files changed

+108
-51
lines changed

JsonApiDotNetCore.sln

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 16
3-
VisualStudioVersion = 16.0.28606.126
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.0.31919.166
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}"
66
EndProject
@@ -48,7 +48,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonApiDotNetCore.SourceGen
4848
EndProject
4949
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGeneratorDebugger", "test\SourceGeneratorDebugger\SourceGeneratorDebugger.csproj", "{87D066F9-3540-4AC7-A748-134900969EE5}"
5050
EndProject
51-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGeneratorTests", "test\SourceGeneratorTests\SourceGeneratorTests.csproj", "{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}"
51+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGeneratorTests", "test\SourceGeneratorTests\SourceGeneratorTests.csproj", "{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}"
52+
EndProject
53+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonApiDotNetCore.Annotations", "src\JsonApiDotNetCore.Annotations\JsonApiDotNetCore.Annotations.csproj", "{83FF097C-C8C6-477B-9FAB-DF99B84978B5}"
5254
EndProject
5355
Global
5456
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -252,6 +254,18 @@ Global
252254
{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}.Release|x64.Build.0 = Release|Any CPU
253255
{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}.Release|x86.ActiveCfg = Release|Any CPU
254256
{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}.Release|x86.Build.0 = Release|Any CPU
257+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
258+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
259+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x64.ActiveCfg = Debug|Any CPU
260+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x64.Build.0 = Debug|Any CPU
261+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x86.ActiveCfg = Debug|Any CPU
262+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x86.Build.0 = Debug|Any CPU
263+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
264+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|Any CPU.Build.0 = Release|Any CPU
265+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x64.ActiveCfg = Release|Any CPU
266+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x64.Build.0 = Release|Any CPU
267+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x86.ActiveCfg = Release|Any CPU
268+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x86.Build.0 = Release|Any CPU
255269
EndGlobalSection
256270
GlobalSection(SolutionProperties) = preSolution
257271
HideSolutionNode = FALSE
@@ -273,6 +287,7 @@ Global
273287
{952C0FDE-AFC8-455C-986F-6CC882ED8953} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
274288
{87D066F9-3540-4AC7-A748-134900969EE5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
275289
{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
290+
{83FF097C-C8C6-477B-9FAB-DF99B84978B5} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
276291
EndGlobalSection
277292
GlobalSection(ExtensibilityGlobals) = postSolution
278293
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}

ROADMAP.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ The need for breaking changes has blocked several efforts in the v4.x release, s
2626
- [x] Configuration validation [#170](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/170)
2727
- [x] Auto-generated controllers [#732](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/732) [#365](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/365)
2828
- [x] Support .NET 6 with EF Core 6 [#1109](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1109)
29+
- [x] Extract annotations into separate package [#730](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/730)
2930

3031
Aside from the list above, we have interest in the following topics. It's too soon yet to decide whether they'll make it into v5.x or in a later major version.
3132

3233
- Optimistic concurrency [#1004](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1004)
33-
- Extract annotations into separate package [#730](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/730)
3434
- OpenAPI (Swagger) [#1046](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1046)
3535
- Fluent API [#776](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/776)
3636
- Resource inheritance [#844](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/844)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# AV1505: Namespace should match with assembly name
4+
dotnet_diagnostic.AV1505.severity = none

src/JsonApiDotNetCore/Configuration/ResourceType.cs renamed to src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ public sealed class ResourceType
4848
public IReadOnlyCollection<EagerLoadAttribute> EagerLoads { get; }
4949

5050
/// <summary>
51-
/// Configures which links to show in the <see cref="Serialization.Objects.TopLevelLinks" /> object for this resource type. Defaults to
52-
/// <see cref="LinkTypes.NotConfigured" />, which falls back to <see cref="IJsonApiOptions.TopLevelLinks" />.
51+
/// Configures which links to write in the top-level links object for this resource type. Defaults to <see cref="LinkTypes.NotConfigured" />, which falls
52+
/// back to TopLevelLinks in global options.
5353
/// </summary>
5454
/// <remarks>
5555
/// In the process of building the resource graph, this value is set based on <see cref="ResourceLinksAttribute.TopLevelLinks" /> usage.
5656
/// </remarks>
5757
public LinkTypes TopLevelLinks { get; }
5858

5959
/// <summary>
60-
/// Configures which links to show in the <see cref="Serialization.Objects.ResourceLinks" /> object for this resource type. Defaults to
61-
/// <see cref="LinkTypes.NotConfigured" />, which falls back to <see cref="IJsonApiOptions.ResourceLinks" />.
60+
/// Configures which links to write in the resource-level links object for this resource type. Defaults to <see cref="LinkTypes.NotConfigured" />, which
61+
/// falls back to ResourceLinks in global options.
6262
/// </summary>
6363
/// <remarks>
6464
/// In the process of building the resource graph, this value is set based on <see cref="ResourceLinksAttribute.ResourceLinks" /> usage.
6565
/// </remarks>
6666
public LinkTypes ResourceLinks { get; }
6767

6868
/// <summary>
69-
/// Configures which links to show in the <see cref="Serialization.Objects.RelationshipLinks" /> object for all relationships of this resource type.
70-
/// Defaults to <see cref="LinkTypes.NotConfigured" />, which falls back to <see cref="IJsonApiOptions.RelationshipLinks" />. This can be overruled per
71-
/// relationship by setting <see cref="RelationshipAttribute.Links" />.
69+
/// Configures which links to write in the relationship-level links object for all relationships of this resource type. Defaults to
70+
/// <see cref="LinkTypes.NotConfigured" />, which falls back to RelationshipLinks in global options. This can be overruled per relationship by setting
71+
/// <see cref="RelationshipAttribute.Links" />.
7272
/// </summary>
7373
/// <remarks>
7474
/// In the process of building the resource graph, this value is set based on <see cref="ResourceLinksAttribute.RelationshipLinks" /> usage.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
4+
<IsPackable>true</IsPackable>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<RootNamespace>JsonApiDotNetCore</RootNamespace>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<VersionPrefix>$(JsonApiDotNetCoreVersionPrefix)</VersionPrefix>
11+
<PackageTags>jsonapidotnetcore;jsonapi;json:api;dotnet;asp.net;rest;web-api</PackageTags>
12+
<Description>Annotations for JsonApiDotNetCore, a framework for building JSON:API compliant REST APIs using ASP.NET and Entity Framework Core.</Description>
13+
<Authors>json-api-dotnet</Authors>
14+
<PackageProjectUrl>https://www.jsonapi.net/</PackageProjectUrl>
15+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
16+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
17+
<PackageReleaseNotes>See https://github.com/json-api-dotnet/JsonApiDotNetCore/releases.</PackageReleaseNotes>
18+
<PackageIcon>logo.png</PackageIcon>
19+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
20+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
21+
<DebugType>embedded</DebugType>
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<None Include="..\..\logo.png" Visible="false">
26+
<Pack>True</Pack>
27+
<PackagePath></PackagePath>
28+
</None>
29+
</ItemGroup>
30+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Benchmarks")]
4+
[assembly: InternalsVisibleTo("JsonApiDotNetCore")]
5+
[assembly: InternalsVisibleTo("JsonApiDotNetCoreTests")]
6+
[assembly: InternalsVisibleTo("UnitTests")]
7+
[assembly: InternalsVisibleTo("TestBuildingBlocks")]

src/JsonApiDotNetCore/Resources/Annotations/RelationshipAttribute.cs renamed to src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public abstract class RelationshipAttribute : ResourceFieldAttribute
6363
public ResourceType RightType { get; internal set; } = null!;
6464

6565
/// <summary>
66-
/// Configures which links to show in the <see cref="Serialization.Objects.RelationshipLinks" /> object for this relationship. Defaults to
67-
/// <see cref="LinkTypes.NotConfigured" />, which falls back to <see cref="ResourceLinksAttribute.RelationshipLinks" /> and then falls back to
68-
/// <see cref="IJsonApiOptions.RelationshipLinks" />.
66+
/// Configures which links to write in the relationship-level links object for this relationship. Defaults to <see cref="LinkTypes.NotConfigured" />,
67+
/// which falls back to <see cref="ResourceLinksAttribute.RelationshipLinks" /> and then falls back to RelationshipLinks in global options.
6968
/// </summary>
7069
public LinkTypes Links { get; set; } = LinkTypes.NotConfigured;
7170

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// When put on a resource class, overrides global configuration for which links to render.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
10+
public sealed class ResourceLinksAttribute : Attribute
11+
{
12+
/// <summary>
13+
/// Configures which links to write in the top-level links object for this resource type. Defaults to <see cref="LinkTypes.NotConfigured" />, which falls
14+
/// back to TopLevelLinks in global options.
15+
/// </summary>
16+
public LinkTypes TopLevelLinks { get; set; } = LinkTypes.NotConfigured;
17+
18+
/// <summary>
19+
/// Configures which links to write in the resource-level links object for this resource type. Defaults to <see cref="LinkTypes.NotConfigured" />, which
20+
/// falls back to ResourceLinks in global options.
21+
/// </summary>
22+
public LinkTypes ResourceLinks { get; set; } = LinkTypes.NotConfigured;
23+
24+
/// <summary>
25+
/// Configures which links to write in the relationship-level links object for all relationships of this resource type. Defaults to
26+
/// <see cref="LinkTypes.NotConfigured" />, which falls back to RelationshipLinks in global options. This can be overruled per relationship by setting
27+
/// <see cref="RelationshipAttribute.Links" />.
28+
/// </summary>
29+
public LinkTypes RelationshipLinks { get; set; } = LinkTypes.NotConfigured;
30+
}

src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ public interface IJsonApiOptions
6363
bool UseRelativeLinks { get; }
6464

6565
/// <summary>
66-
/// Configures which links to show in the <see cref="Serialization.Objects.TopLevelLinks" /> object. Defaults to <see cref="LinkTypes.All" />. This
66+
/// Configures which links to write in the <see cref="Serialization.Objects.TopLevelLinks" /> object. Defaults to <see cref="LinkTypes.All" />. This
6767
/// setting can be overruled per resource type by adding <see cref="ResourceLinksAttribute" /> on the class definition of a resource.
6868
/// </summary>
6969
LinkTypes TopLevelLinks { get; }
7070

7171
/// <summary>
72-
/// Configures which links to show in the <see cref="Serialization.Objects.ResourceLinks" /> object. Defaults to <see cref="LinkTypes.All" />. This
72+
/// Configures which links to write in the <see cref="Serialization.Objects.ResourceLinks" /> object. Defaults to <see cref="LinkTypes.All" />. This
7373
/// setting can be overruled per resource type by adding <see cref="ResourceLinksAttribute" /> on the class definition of a resource.
7474
/// </summary>
7575
LinkTypes ResourceLinks { get; }
7676

7777
/// <summary>
78-
/// Configures which links to show in the <see cref="Serialization.Objects.RelationshipLinks" /> object. Defaults to <see cref="LinkTypes.All" />. This
78+
/// Configures which links to write in the <see cref="Serialization.Objects.RelationshipLinks" /> object. Defaults to <see cref="LinkTypes.All" />. This
7979
/// setting can be overruled for all relationships per resource type by adding <see cref="ResourceLinksAttribute" /> on the class definition of a
8080
/// resource. This can be further overruled per relationship by setting <see cref="RelationshipAttribute.Links" />.
8181
/// </summary>

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31+
<ProjectReference Include="..\JsonApiDotNetCore.Annotations\JsonApiDotNetCore.Annotations.csproj" />
3132
<ProjectReference Include="..\JsonApiDotNetCore.SourceGenerators\JsonApiDotNetCore.SourceGenerators.csproj" IncludeAssets="analyzers" />
3233
</ItemGroup>
3334

src/JsonApiDotNetCore/Resources/Annotations/ResourceLinksAttribute.cs

-31
This file was deleted.

test/SourceGeneratorDebugger/SourceGeneratorDebugger.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<Compile Include="..\..\src\JsonApiDotNetCore\Controllers\JsonApiEndpoints.cs" Link="JsonApiDotNetCore\JsonApiEndpoints.cs" />
17-
<Compile Include="..\..\src\JsonApiDotNetCore\Resources\Annotations\ResourceAttribute.cs" Link="JsonApiDotNetCore\ResourceAttribute.cs" />
16+
<Compile Include="..\..\src\JsonApiDotNetCore.Annotations\Controllers\JsonApiEndpoints.cs" Link="JsonApiDotNetCore\JsonApiEndpoints.cs" />
17+
<Compile Include="..\..\src\JsonApiDotNetCore.Annotations\Resources\Annotations\ResourceAttribute.cs" Link="JsonApiDotNetCore\ResourceAttribute.cs" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

test/SourceGeneratorTests/CompilationBuilder.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using JsonApiDotNetCore.Controllers;
12
using JsonApiDotNetCore.Resources.Annotations;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.CodeAnalysis;
@@ -58,7 +59,8 @@ public CompilationBuilder WithJsonApiDotNetCoreReferences()
5859
foreach (PortableExecutableReference reference in new[]
5960
{
6061
MetadataReference.CreateFromFile(typeof(ControllerBase).Assembly.Location),
61-
MetadataReference.CreateFromFile(typeof(AttrAttribute).Assembly.Location)
62+
MetadataReference.CreateFromFile(typeof(AttrAttribute).Assembly.Location),
63+
MetadataReference.CreateFromFile(typeof(JsonApiController<,>).Assembly.Location)
6264
})
6365
{
6466
_references.Add(reference);

0 commit comments

Comments
 (0)