diff --git a/JsonApiDotNetCore.sln b/JsonApiDotNetCore.sln index ade710c475..7237596aed 100644 --- a/JsonApiDotNetCore.sln +++ b/JsonApiDotNetCore.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28606.126 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}" EndProject @@ -48,7 +48,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonApiDotNetCore.SourceGen EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGeneratorDebugger", "test\SourceGeneratorDebugger\SourceGeneratorDebugger.csproj", "{87D066F9-3540-4AC7-A748-134900969EE5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGeneratorTests", "test\SourceGeneratorTests\SourceGeneratorTests.csproj", "{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGeneratorTests", "test\SourceGeneratorTests\SourceGeneratorTests.csproj", "{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonApiDotNetCore.Annotations", "src\JsonApiDotNetCore.Annotations\JsonApiDotNetCore.Annotations.csproj", "{83FF097C-C8C6-477B-9FAB-DF99B84978B5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -252,6 +254,18 @@ Global {0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}.Release|x64.Build.0 = Release|Any CPU {0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}.Release|x86.ActiveCfg = Release|Any CPU {0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9}.Release|x86.Build.0 = Release|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x64.ActiveCfg = Debug|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x64.Build.0 = Debug|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x86.ActiveCfg = Debug|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Debug|x86.Build.0 = Debug|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|Any CPU.Build.0 = Release|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x64.ActiveCfg = Release|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x64.Build.0 = Release|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x86.ActiveCfg = Release|Any CPU + {83FF097C-C8C6-477B-9FAB-DF99B84978B5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -273,6 +287,7 @@ Global {952C0FDE-AFC8-455C-986F-6CC882ED8953} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF} {87D066F9-3540-4AC7-A748-134900969EE5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F} {0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F} + {83FF097C-C8C6-477B-9FAB-DF99B84978B5} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4} diff --git a/ROADMAP.md b/ROADMAP.md index 9a890f2014..559e0bfe7d 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -26,11 +26,11 @@ The need for breaking changes has blocked several efforts in the v4.x release, s - [x] Configuration validation [#170](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/170) - [x] Auto-generated controllers [#732](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/732) [#365](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/365) - [x] Support .NET 6 with EF Core 6 [#1109](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1109) +- [x] Extract annotations into separate package [#730](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/730) 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. - Optimistic concurrency [#1004](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1004) -- Extract annotations into separate package [#730](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/730) - OpenAPI (Swagger) [#1046](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1046) - Fluent API [#776](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/776) - Resource inheritance [#844](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/844) diff --git a/src/JsonApiDotNetCore.Annotations/.editorconfig b/src/JsonApiDotNetCore.Annotations/.editorconfig new file mode 100644 index 0000000000..6e602763d4 --- /dev/null +++ b/src/JsonApiDotNetCore.Annotations/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# AV1505: Namespace should match with assembly name +dotnet_diagnostic.AV1505.severity = none diff --git a/src/JsonApiDotNetCore/ArgumentGuard.cs b/src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs similarity index 100% rename from src/JsonApiDotNetCore/ArgumentGuard.cs rename to src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs diff --git a/src/JsonApiDotNetCore/CollectionConverter.cs b/src/JsonApiDotNetCore.Annotations/CollectionConverter.cs similarity index 100% rename from src/JsonApiDotNetCore/CollectionConverter.cs rename to src/JsonApiDotNetCore.Annotations/CollectionConverter.cs diff --git a/src/JsonApiDotNetCore/Configuration/ResourceType.cs b/src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs similarity index 90% rename from src/JsonApiDotNetCore/Configuration/ResourceType.cs rename to src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs index f305bcb9e6..ce7ccd1870 100644 --- a/src/JsonApiDotNetCore/Configuration/ResourceType.cs +++ b/src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs @@ -48,8 +48,8 @@ public sealed class ResourceType public IReadOnlyCollection EagerLoads { get; } /// - /// Configures which links to show in the object for this resource type. Defaults to - /// , which falls back to . + /// Configures which links to write in the top-level links object for this resource type. Defaults to , which falls + /// back to TopLevelLinks in global options. /// /// /// In the process of building the resource graph, this value is set based on usage. @@ -57,8 +57,8 @@ public sealed class ResourceType public LinkTypes TopLevelLinks { get; } /// - /// Configures which links to show in the object for this resource type. Defaults to - /// , which falls back to . + /// Configures which links to write in the resource-level links object for this resource type. Defaults to , which + /// falls back to ResourceLinks in global options. /// /// /// In the process of building the resource graph, this value is set based on usage. @@ -66,9 +66,9 @@ public sealed class ResourceType public LinkTypes ResourceLinks { get; } /// - /// Configures which links to show in the object for all relationships of this resource type. - /// Defaults to , which falls back to . This can be overruled per - /// relationship by setting . + /// Configures which links to write in the relationship-level links object for all relationships of this resource type. Defaults to + /// , which falls back to RelationshipLinks in global options. This can be overruled per relationship by setting + /// . /// /// /// In the process of building the resource graph, this value is set based on usage. diff --git a/src/JsonApiDotNetCore/Controllers/JsonApiEndpoints.cs b/src/JsonApiDotNetCore.Annotations/Controllers/JsonApiEndpoints.cs similarity index 100% rename from src/JsonApiDotNetCore/Controllers/JsonApiEndpoints.cs rename to src/JsonApiDotNetCore.Annotations/Controllers/JsonApiEndpoints.cs diff --git a/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj b/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj new file mode 100644 index 0000000000..7c78f620ed --- /dev/null +++ b/src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj @@ -0,0 +1,30 @@ + + + $(TargetFrameworkName) + true + true + JsonApiDotNetCore + + + + $(JsonApiDotNetCoreVersionPrefix) + jsonapidotnetcore;jsonapi;json:api;dotnet;asp.net;rest;web-api + Annotations for JsonApiDotNetCore, a framework for building JSON:API compliant REST APIs using ASP.NET and Entity Framework Core. + json-api-dotnet + https://www.jsonapi.net/ + MIT + false + See https://github.com/json-api-dotnet/JsonApiDotNetCore/releases. + logo.png + true + true + embedded + + + + + True + + + + diff --git a/src/JsonApiDotNetCore/ObjectExtensions.cs b/src/JsonApiDotNetCore.Annotations/ObjectExtensions.cs similarity index 100% rename from src/JsonApiDotNetCore/ObjectExtensions.cs rename to src/JsonApiDotNetCore.Annotations/ObjectExtensions.cs diff --git a/src/JsonApiDotNetCore.Annotations/Properties/AssemblyInfo.cs b/src/JsonApiDotNetCore.Annotations/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..155a48c3c2 --- /dev/null +++ b/src/JsonApiDotNetCore.Annotations/Properties/AssemblyInfo.cs @@ -0,0 +1,7 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Benchmarks")] +[assembly: InternalsVisibleTo("JsonApiDotNetCore")] +[assembly: InternalsVisibleTo("JsonApiDotNetCoreTests")] +[assembly: InternalsVisibleTo("UnitTests")] +[assembly: InternalsVisibleTo("TestBuildingBlocks")] diff --git a/src/JsonApiDotNetCore/Resources/Annotations/AttrAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/AttrAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrAttribute.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/AttrCapabilities.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrCapabilities.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/AttrCapabilities.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrCapabilities.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/EagerLoadAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/EagerLoadAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/EagerLoadAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/EagerLoadAttribute.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/HasManyAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasManyAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/HasManyAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasManyAttribute.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/HasOneAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasOneAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/HasOneAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/HasOneAttribute.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/LinkTypes.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/LinkTypes.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/LinkTypes.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/LinkTypes.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/NoResourceAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/NoResourceAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/NoResourceAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/NoResourceAttribute.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/RelationshipAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs similarity index 90% rename from src/JsonApiDotNetCore/Resources/Annotations/RelationshipAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs index 4e335d2c8c..6406ba17ff 100644 --- a/src/JsonApiDotNetCore/Resources/Annotations/RelationshipAttribute.cs +++ b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/RelationshipAttribute.cs @@ -63,9 +63,8 @@ public abstract class RelationshipAttribute : ResourceFieldAttribute public ResourceType RightType { get; internal set; } = null!; /// - /// Configures which links to show in the object for this relationship. Defaults to - /// , which falls back to and then falls back to - /// . + /// Configures which links to write in the relationship-level links object for this relationship. Defaults to , + /// which falls back to and then falls back to RelationshipLinks in global options. /// public LinkTypes Links { get; set; } = LinkTypes.NotConfigured; diff --git a/src/JsonApiDotNetCore/Resources/Annotations/ResourceAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/ResourceAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceAttribute.cs diff --git a/src/JsonApiDotNetCore/Resources/Annotations/ResourceFieldAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Annotations/ResourceFieldAttribute.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs diff --git a/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceLinksAttribute.cs b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceLinksAttribute.cs new file mode 100644 index 0000000000..010f87db5e --- /dev/null +++ b/src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceLinksAttribute.cs @@ -0,0 +1,30 @@ +using JetBrains.Annotations; + +namespace JsonApiDotNetCore.Resources.Annotations; + +/// +/// When put on a resource class, overrides global configuration for which links to render. +/// +[PublicAPI] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +public sealed class ResourceLinksAttribute : Attribute +{ + /// + /// Configures which links to write in the top-level links object for this resource type. Defaults to , which falls + /// back to TopLevelLinks in global options. + /// + public LinkTypes TopLevelLinks { get; set; } = LinkTypes.NotConfigured; + + /// + /// Configures which links to write in the resource-level links object for this resource type. Defaults to , which + /// falls back to ResourceLinks in global options. + /// + public LinkTypes ResourceLinks { get; set; } = LinkTypes.NotConfigured; + + /// + /// Configures which links to write in the relationship-level links object for all relationships of this resource type. Defaults to + /// , which falls back to RelationshipLinks in global options. This can be overruled per relationship by setting + /// . + /// + public LinkTypes RelationshipLinks { get; set; } = LinkTypes.NotConfigured; +} diff --git a/src/JsonApiDotNetCore/Resources/IIdentifiable.cs b/src/JsonApiDotNetCore.Annotations/Resources/IIdentifiable.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/IIdentifiable.cs rename to src/JsonApiDotNetCore.Annotations/Resources/IIdentifiable.cs diff --git a/src/JsonApiDotNetCore/Resources/Identifiable.cs b/src/JsonApiDotNetCore.Annotations/Resources/Identifiable.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Identifiable.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Identifiable.cs diff --git a/src/JsonApiDotNetCore/Resources/Internal/RuntimeTypeConverter.cs b/src/JsonApiDotNetCore.Annotations/Resources/Internal/RuntimeTypeConverter.cs similarity index 100% rename from src/JsonApiDotNetCore/Resources/Internal/RuntimeTypeConverter.cs rename to src/JsonApiDotNetCore.Annotations/Resources/Internal/RuntimeTypeConverter.cs diff --git a/src/JsonApiDotNetCore/TypeExtensions.cs b/src/JsonApiDotNetCore.Annotations/TypeExtensions.cs similarity index 100% rename from src/JsonApiDotNetCore/TypeExtensions.cs rename to src/JsonApiDotNetCore.Annotations/TypeExtensions.cs diff --git a/src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs index 350b8e0132..597d22294d 100644 --- a/src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs @@ -63,19 +63,19 @@ public interface IJsonApiOptions bool UseRelativeLinks { get; } /// - /// Configures which links to show in the object. Defaults to . This + /// Configures which links to write in the object. Defaults to . This /// setting can be overruled per resource type by adding on the class definition of a resource. /// LinkTypes TopLevelLinks { get; } /// - /// Configures which links to show in the object. Defaults to . This + /// Configures which links to write in the object. Defaults to . This /// setting can be overruled per resource type by adding on the class definition of a resource. /// LinkTypes ResourceLinks { get; } /// - /// Configures which links to show in the object. Defaults to . This + /// Configures which links to write in the object. Defaults to . This /// setting can be overruled for all relationships per resource type by adding on the class definition of a /// resource. This can be further overruled per relationship by setting . /// diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index 6842b86545..cc91d0f324 100644 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -28,6 +28,7 @@ + diff --git a/src/JsonApiDotNetCore/Resources/Annotations/ResourceLinksAttribute.cs b/src/JsonApiDotNetCore/Resources/Annotations/ResourceLinksAttribute.cs deleted file mode 100644 index de290b04f7..0000000000 --- a/src/JsonApiDotNetCore/Resources/Annotations/ResourceLinksAttribute.cs +++ /dev/null @@ -1,31 +0,0 @@ -using JetBrains.Annotations; -using JsonApiDotNetCore.Configuration; - -namespace JsonApiDotNetCore.Resources.Annotations; - -/// -/// When put on a resource class, overrides global configuration for which links to render. -/// -[PublicAPI] -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] -public sealed class ResourceLinksAttribute : Attribute -{ - /// - /// Configures which links to show in the object for this resource type. Defaults to - /// , which falls back to . - /// - public LinkTypes TopLevelLinks { get; set; } = LinkTypes.NotConfigured; - - /// - /// Configures which links to show in the object for this resource type. Defaults to - /// , which falls back to . - /// - public LinkTypes ResourceLinks { get; set; } = LinkTypes.NotConfigured; - - /// - /// Configures which links to show in the object for all relationships of this resource type. - /// Defaults to , which falls back to . This can be overruled per - /// relationship by setting . - /// - public LinkTypes RelationshipLinks { get; set; } = LinkTypes.NotConfigured; -} diff --git a/test/SourceGeneratorDebugger/SourceGeneratorDebugger.csproj b/test/SourceGeneratorDebugger/SourceGeneratorDebugger.csproj index d756cbb4e1..2909905e2b 100644 --- a/test/SourceGeneratorDebugger/SourceGeneratorDebugger.csproj +++ b/test/SourceGeneratorDebugger/SourceGeneratorDebugger.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/test/SourceGeneratorTests/CompilationBuilder.cs b/test/SourceGeneratorTests/CompilationBuilder.cs index 4565ff29b1..6029b68eae 100644 --- a/test/SourceGeneratorTests/CompilationBuilder.cs +++ b/test/SourceGeneratorTests/CompilationBuilder.cs @@ -1,3 +1,4 @@ +using JsonApiDotNetCore.Controllers; using JsonApiDotNetCore.Resources.Annotations; using Microsoft.AspNetCore.Mvc; using Microsoft.CodeAnalysis; @@ -58,7 +59,8 @@ public CompilationBuilder WithJsonApiDotNetCoreReferences() foreach (PortableExecutableReference reference in new[] { MetadataReference.CreateFromFile(typeof(ControllerBase).Assembly.Location), - MetadataReference.CreateFromFile(typeof(AttrAttribute).Assembly.Location) + MetadataReference.CreateFromFile(typeof(AttrAttribute).Assembly.Location), + MetadataReference.CreateFromFile(typeof(JsonApiController<,>).Assembly.Location) }) { _references.Add(reference);