Skip to content
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

v4.0 #9

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageOutputPath>$(MSBuildThisFileDirectory)artifacts\packages\$(Configuration)</PackageOutputPath>
<NeutralLanguage>en</NeutralLanguage>
<Version>3.1.0</Version>
<Version>4.0.0</Version>
</PropertyGroup>

<Choose>
Expand All @@ -33,7 +33,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 3 additions & 2 deletions ProblemDetails.Core/ProblemDetails.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<AssemblyName>IntelligentPlant.ProblemDetails.Core</AssemblyName>
<RootNamespace>IntelligentPlant.ProblemDetails</RootNamespace>
<PackageId>IntelligentPlant.ProblemDetails.Core</PackageId>
<Description>Core types for RFC 7807 problem details.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
</ItemGroup>

</Project>
21 changes: 13 additions & 8 deletions ProblemDetails.Core/ProblemDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System;
using System.Collections.Generic;

using Newtonsoft.Json;

namespace IntelligentPlant.ProblemDetails {
/// <summary>
/// A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807.
Expand All @@ -20,33 +18,38 @@ public class ProblemDetails {
/// (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be
/// "about:blank".
/// </summary>
[JsonProperty("type")]
[Newtonsoft.Json.JsonProperty("type")]
[System.Text.Json.Serialization.JsonPropertyName("type")]
public string? Type { get; set; }

/// <summary>
/// A short, human-readable summary of the problem type.It SHOULD NOT change from occurrence to occurrence
/// of the problem, except for purposes of localization(e.g., using proactive content negotiation;
/// see[RFC7231], Section 3.4).
/// </summary>
[JsonProperty("title")]
[Newtonsoft.Json.JsonProperty("title")]
[System.Text.Json.Serialization.JsonPropertyName("title")]
public string? Title { get; set; }

/// <summary>
/// The HTTP status code([RFC7231], Section 6) generated by the origin server for this occurrence of the problem.
/// </summary>
[JsonProperty("status")]
[Newtonsoft.Json.JsonProperty("status")]
[System.Text.Json.Serialization.JsonPropertyName("status")]
public int? Status { get; set; }

/// <summary>
/// A human-readable explanation specific to this occurrence of the problem.
/// </summary>
[JsonProperty("detail")]
[Newtonsoft.Json.JsonProperty("detail")]
[System.Text.Json.Serialization.JsonPropertyName("detail")]
public string? Detail { get; set; }

/// <summary>
/// A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
/// </summary>
[JsonProperty("instance")]
[Newtonsoft.Json.JsonProperty("instance")]
[System.Text.Json.Serialization.JsonPropertyName("instance")]
public string? Instance { get; set; }

/// <summary>
Expand All @@ -60,7 +63,9 @@ public class ProblemDetails {
/// The round-tripping behavior for <see cref="Extensions"/> is determined by the implementation of the Input / Output formatters.
/// In particular, complex types or collection types may not round-trip to the original type when using the built-in JSON or XML formatters.
/// </remarks>
[JsonExtensionData]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public IDictionary<string, object> Extensions { get; } = new Dictionary<string, object>(StringComparer.Ordinal);

}
}
13 changes: 11 additions & 2 deletions ProblemDetails.WebApi.Sample/Controllers/ExampleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Net.Http;
using System.Web.Http;

using IntelligentPlant.ProblemDetails.WebApi;
Expand Down Expand Up @@ -65,6 +66,14 @@ public IHttpActionResult CreateDirect() {
}


[HttpGet]
[Route("create-direct2")]
public IHttpActionResult CreateDirect2() {
var problem = IntelligentPlant.ProblemDetails.ProblemDetailsFactory.Default.CreateProblemDetails(Request.GetOwinContext(), 403, detail: "Problem details object was directly created");
return this.CreateProblemDetailsResponse(problem);
}


[HttpGet]
[Route("create-from-error")]
public IHttpActionResult CreateFromError(bool? detail = null) {
Expand Down Expand Up @@ -117,10 +126,10 @@ public IHttpActionResult CreateFromModelStateDictionary() {

public class Model {

public string Id { get; set; }
public string Id { get; set; } = default!;

[Required]
public string Name { get; set; }
public string Name { get; set; } = default!;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFramework>net48</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<SignOutput>false</SignOutput>
<IsSignable>false</IsSignable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Owin" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Owin" Version="4.2.2" />
<PackageReference Include="Owin" Version="1.0.0" />
</ItemGroup>

Expand Down
10 changes: 5 additions & 5 deletions ProblemDetails.WebApi.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,35 @@ private static void AddCustomProperties(IntelligentPlant.ProblemDetails.ProblemD
}


public override IntelligentPlant.ProblemDetails.ProblemDetails CreateProblemDetails(IOwinContext httpContext, int? statusCode = null, string title = null, string type = null, string detail = null, string instance = null) {
public override IntelligentPlant.ProblemDetails.ProblemDetails CreateProblemDetails(IOwinContext httpContext, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null) {
var result = base.CreateProblemDetails(httpContext, statusCode, title, type, detail, instance);
AddCustomProperties(result);
return result;
}


public override IntelligentPlant.ProblemDetails.ServerErrorProblemDetails CreateServerErrorProblemDetails(IOwinContext httpContext, Exception error = null, int? statusCode = null, string title = null, string type = null, string detail = null, string instance = null) {
public override IntelligentPlant.ProblemDetails.ServerErrorProblemDetails CreateServerErrorProblemDetails(IOwinContext httpContext, Exception? error = null, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null) {
var result = base.CreateServerErrorProblemDetails(httpContext, error, statusCode, title, type, detail, instance);
AddCustomProperties(result);
return result;
}


public override IntelligentPlant.ProblemDetails.ValidationProblemDetails CreateValidationProblemDetails(IOwinContext httpContext, IEnumerable<ValidationResult> errors, int? statusCode = null, string title = null, string type = null, string detail = null, string instance = null) {
public override IntelligentPlant.ProblemDetails.ValidationProblemDetails CreateValidationProblemDetails(IOwinContext httpContext, IEnumerable<ValidationResult> errors, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null) {
var result = base.CreateValidationProblemDetails(httpContext, errors, statusCode, title, type, detail, instance);
AddCustomProperties(result);
return result;
}


public override IntelligentPlant.ProblemDetails.ValidationProblemDetails CreateValidationProblemDetails(IOwinContext httpContext, ModelStateDictionary modelStateDictionary, int? statusCode = null, string title = null, string type = null, string detail = null, string instance = null) {
public override IntelligentPlant.ProblemDetails.ValidationProblemDetails CreateValidationProblemDetails(IOwinContext httpContext, ModelStateDictionary modelStateDictionary, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null) {
var result = base.CreateValidationProblemDetails(httpContext, modelStateDictionary, statusCode, title, type, detail, instance);
AddCustomProperties(result);
return result;
}


public override IntelligentPlant.ProblemDetails.ValidationProblemDetails CreateValidationProblemDetails(IOwinContext httpContext, ValidationException error, int? statusCode = null, string title = null, string type = null, string detail = null, string instance = null) {
public override IntelligentPlant.ProblemDetails.ValidationProblemDetails CreateValidationProblemDetails(IOwinContext httpContext, ValidationException error, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null) {
var result = base.CreateValidationProblemDetails(httpContext, error, statusCode, title, type, detail, instance);
AddCustomProperties(result);
return result;
Expand Down
5 changes: 2 additions & 3 deletions ProblemDetails.WebApi/ProblemDetails.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;net46</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<AssemblyName>IntelligentPlant.ProblemDetails.WebApi</AssemblyName>
<RootNamespace>IntelligentPlant.ProblemDetails</RootNamespace>
<PackageId>IntelligentPlant.ProblemDetails.WebApi</PackageId>
<Description>Web API 2/OWIN support for RFC 7807 problem details.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Owin" Version="5.2.7" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Owin" Version="5.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions ProblemDetails.WebApi/ServerErrorProblemDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Newtonsoft.Json;

namespace IntelligentPlant.ProblemDetails {

Expand All @@ -15,7 +14,8 @@ public class ServerErrorProblemDetails : ProblemDetails {
/// <summary>
/// The stack trace for the error.
/// </summary>
[JsonProperty("stackTrace")]
[Newtonsoft.Json.JsonProperty("stackTrace")]
[System.Text.Json.Serialization.JsonPropertyName("stackTrace")]
public string? StackTrace { get; set; }


Expand Down
5 changes: 2 additions & 3 deletions ProblemDetails.WebApi/ValidationProblemDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using System.Linq;
using System.Web.Http.ModelBinding;

using Newtonsoft.Json;

namespace IntelligentPlant.ProblemDetails {
/// <summary>
/// A <see cref="ProblemDetails"/> for validation errors.
Expand All @@ -20,7 +18,8 @@ public class ValidationProblemDetails : ProblemDetails {
/// <summary>
/// Gets the validation errors associated with this instance of <see cref="ValidationProblemDetails"/>.
/// </summary>
[JsonProperty("errors")]
[Newtonsoft.Json.JsonProperty("errors")]
[System.Text.Json.Serialization.JsonPropertyName("errors")]
public IDictionary<string, string[]> Errors { get; } = new Dictionary<string, string[]>(StringComparer.Ordinal);


Expand Down
Loading