-
-
Notifications
You must be signed in to change notification settings - Fork 158
Adds option to emit jsonapi version in response documents #992
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
src/JsonApiDotNetCore/Serialization/Objects/JsonApiObject.cs
This file contains hidden or 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,26 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace JsonApiDotNetCore.Serialization.Objects | ||
{ | ||
/// <summary> | ||
/// https://jsonapi.org/format/1.1/#document-jsonapi-object. | ||
/// </summary> | ||
public sealed class JsonApiObject | ||
{ | ||
[JsonProperty("version", NullValueHandling = NullValueHandling.Ignore)] | ||
public string Version { get; set; } | ||
|
||
[JsonProperty("ext", NullValueHandling = NullValueHandling.Ignore)] | ||
public ICollection<string> Ext { get; set; } | ||
|
||
[JsonProperty("profile", NullValueHandling = NullValueHandling.Ignore)] | ||
public ICollection<string> Profile { get; set; } | ||
|
||
/// <summary> | ||
/// see "meta" in https://jsonapi.org/format/1.1/#document-meta | ||
/// </summary> | ||
[JsonProperty("meta", NullValueHandling = NullValueHandling.Ignore)] | ||
public IDictionary<string, object> Meta { get; set; } | ||
} | ||
} |
This file contains hidden or 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
101 changes: 101 additions & 0 deletions
101
...otNetCoreExampleTests/IntegrationTests/AtomicOperations/Mixed/AtomicSerializationTests.cs
This file contains hidden or 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,101 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.Resources; | ||
using JsonApiDotNetCoreExample.Controllers; | ||
using JsonApiDotNetCoreExampleTests.Startups; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TestBuildingBlocks; | ||
using Xunit; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.AtomicOperations.Mixed | ||
{ | ||
public sealed class AtomicSerializationTests : IClassFixture<ExampleIntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext>> | ||
{ | ||
private readonly ExampleIntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext> _testContext; | ||
private readonly OperationsFakers _fakers = new OperationsFakers(); | ||
|
||
public AtomicSerializationTests(ExampleIntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext> testContext) | ||
{ | ||
_testContext = testContext; | ||
|
||
testContext.UseController<OperationsController>(); | ||
|
||
testContext.ConfigureServicesAfterStartup(services => | ||
{ | ||
services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); | ||
}); | ||
|
||
var options = (JsonApiOptions)testContext.Factory.Services.GetRequiredService<IJsonApiOptions>(); | ||
options.IncludeJsonApiVersion = true; | ||
options.AllowClientGeneratedIds = true; | ||
} | ||
|
||
[Fact] | ||
public async Task Includes_version_with_ext_on_operations_endpoint() | ||
{ | ||
// Arrange | ||
const int newArtistId = 12345; | ||
string newArtistName = _fakers.Performer.Generate().ArtistName; | ||
|
||
await _testContext.RunOnDatabaseAsync(async dbContext => | ||
{ | ||
await dbContext.ClearTableAsync<Performer>(); | ||
}); | ||
|
||
var requestBody = new | ||
{ | ||
atomic__operations = new[] | ||
{ | ||
new | ||
{ | ||
op = "add", | ||
data = new | ||
{ | ||
type = "performers", | ||
id = newArtistId, | ||
attributes = new | ||
{ | ||
artistName = newArtistName | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const string route = "/operations"; | ||
|
||
// Act | ||
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAtomicAsync<string>(route, requestBody); | ||
|
||
// Assert | ||
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK); | ||
|
||
responseDocument.Should().BeJson(@"{ | ||
""jsonapi"": { | ||
""version"": ""1.1"", | ||
""ext"": [ | ||
""https://jsonapi.org/ext/atomic"" | ||
] | ||
}, | ||
""atomic:results"": [ | ||
{ | ||
""data"": { | ||
""type"": ""performers"", | ||
""id"": """ + newArtistId + @""", | ||
""attributes"": { | ||
""artistName"": """ + newArtistName + @""", | ||
""bornAt"": ""0001-01-01T01:00:00+01:00"" | ||
}, | ||
""links"": { | ||
""self"": ""http://localhost/performers/" + newArtistId + @""" | ||
} | ||
} | ||
} | ||
] | ||
}"); | ||
} | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.