From 74c2fd264e91bb7ae9b9188d42276cf45918f67f Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sun, 2 Jul 2017 18:03:01 -0500 Subject: [PATCH 1/4] fix(ci): support pre-release versions in tags --- Build.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Build.ps1 b/Build.ps1 index 9a5e17d170..fa06ca8823 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -14,9 +14,21 @@ echo "VERSION-SUFFIX: alpha1-$revision" If($env:APPVEYOR_REPO_TAG -eq $true) { echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts " - dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts + $revision = Get-Version-Suffix-From-Tag + dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision } Else { echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision } + +# Gets the version suffix from the repo tag +# example: v1.0.0-preview1-final => preview1-final +function Get-Version-Suffix-From-Tag +{ + $tag=$env:APPVEYOR_REPO_TAG_NAME + $split=$tag -split "-" + $suffix=$split[1..2] + $final=$suffix -join "-" + return $c +} \ No newline at end of file From 34aabb6ae498b8ba1c2110a42e1f0e2ec21581c0 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sun, 2 Jul 2017 18:09:32 -0500 Subject: [PATCH 2/4] fix build script --- Build.ps1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index fa06ca8823..ebed6fb638 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,3 +1,14 @@ +# Gets the version suffix from the repo tag +# example: v1.0.0-preview1-final => preview1-final +function Get-Version-Suffix-From-Tag +{ + $tag=$env:APPVEYOR_REPO_TAG_NAME + $split=$tag -split "-" + $suffix=$split[1..2] + $final=$suffix -join "-" + return $c +} + $revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) @@ -15,20 +26,9 @@ echo "VERSION-SUFFIX: alpha1-$revision" If($env:APPVEYOR_REPO_TAG -eq $true) { echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts " $revision = Get-Version-Suffix-From-Tag - dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision + dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision } Else { echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision -} - -# Gets the version suffix from the repo tag -# example: v1.0.0-preview1-final => preview1-final -function Get-Version-Suffix-From-Tag -{ - $tag=$env:APPVEYOR_REPO_TAG_NAME - $split=$tag -split "-" - $suffix=$split[1..2] - $final=$suffix -join "-" - return $c } \ No newline at end of file From a8966ac5edb663be487027a93f0ba5eac44f7fbf Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sun, 2 Jul 2017 18:20:17 -0500 Subject: [PATCH 3/4] fix build script --- Build.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index ebed6fb638..6a37b7f8a5 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -6,7 +6,7 @@ function Get-Version-Suffix-From-Tag $split=$tag -split "-" $suffix=$split[1..2] $final=$suffix -join "-" - return $c + return $final } $revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; @@ -21,14 +21,16 @@ dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj dotnet build .\src\JsonApiDotNetCore -c Release echo "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG" -echo "VERSION-SUFFIX: alpha1-$revision" + If($env:APPVEYOR_REPO_TAG -eq $true) { - echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts " $revision = Get-Version-Suffix-From-Tag + echo "VERSION-SUFFIX: $revision" + echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision" dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision } Else { + echo "VERSION-SUFFIX: alpha1-$revision" echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision } \ No newline at end of file From 0ab3522a38dfd0727772836a8955e5f0776dd135 Mon Sep 17 00:00:00 2001 From: Jared Nance Date: Sat, 22 Jul 2017 21:58:26 -0500 Subject: [PATCH 4/4] fix(JsonApiReader): do not write to the response body stream instead add an error to the ModelState --- src/JsonApiDotNetCore/Formatters/JsonApiReader.cs | 14 ++++++-------- src/JsonApiDotNetCore/JsonApiDotNetCore.csproj | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs b/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs index 103c1b9ab5..274d14bc15 100644 --- a/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs +++ b/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Text; using System.Threading.Tasks; using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Serialization; @@ -16,7 +15,7 @@ public class JsonApiReader : IJsonApiReader private readonly IJsonApiDeSerializer _deSerializer; private readonly IJsonApiContext _jsonApiContext; private readonly ILogger _logger; - + public JsonApiReader(IJsonApiDeSerializer deSerializer, IJsonApiContext jsonApiContext, ILoggerFactory loggerFactory) { @@ -37,11 +36,11 @@ public Task ReadAsync(InputFormatterContext context) try { var body = GetRequestBody(context.HttpContext.Request.Body); - var model = _jsonApiContext.IsRelationshipPath ? + var model = _jsonApiContext.IsRelationshipPath ? _deSerializer.DeserializeRelationship(body) : _deSerializer.Deserialize(body); - if(model == null) + if (model == null) _logger?.LogError("An error occurred while de-serializing the payload"); return InputFormatterResult.SuccessAsync(model); @@ -49,14 +48,13 @@ public Task ReadAsync(InputFormatterContext context) catch (JsonSerializationException ex) { _logger?.LogError(new EventId(), ex, "An error occurred while de-serializing the payload"); - context.HttpContext.Response.StatusCode = 422; + context.ModelState.AddModelError(context.ModelName, ex, context.Metadata); return InputFormatterResult.FailureAsync(); } - catch(JsonApiException jex) + catch (JsonApiException jex) { _logger?.LogError(new EventId(), jex, "An error occurred while de-serializing the payload"); - context.HttpContext.Response.StatusCode = jex.GetStatusCode(); - context.HttpContext.Response.Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jex.GetError()))); + context.ModelState.AddModelError(context.ModelName, jex, context.Metadata); return InputFormatterResult.FailureAsync(); } } diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index 55775d73f5..f512d3505c 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -1,6 +1,6 @@  - 2.1.0 + 2.1.1 netstandard1.6 JsonApiDotNetCore JsonApiDotNetCore