-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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
16 changes: 16 additions & 0 deletions
16
...gporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderAttribute.cs
This file contains 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,16 @@ | ||
namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialogs.Patch; | ||
|
||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
public sealed class ProducesResponseHeaderAttribute : Attribute | ||
{ | ||
public ProducesResponseHeaderAttribute(int statusCode, string headerName, string description) | ||
{ | ||
HeaderName = headerName; | ||
StatusCode = statusCode; | ||
Description = description; | ||
} | ||
|
||
public string HeaderName { get; } | ||
public int StatusCode { get; } | ||
public string Description { get; } | ||
} |
29 changes: 29 additions & 0 deletions
29
...ebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderOperationProcessor.cs
This file contains 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,29 @@ | ||
using System.Globalization; | ||
using System.Reflection; | ||
using NSwag; | ||
using NSwag.Generation.Processors; | ||
using NSwag.Generation.Processors.Contexts; | ||
|
||
namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialogs.Patch; | ||
|
||
public sealed class ProducesResponseHeaderOperationProcessor : IOperationProcessor | ||
{ | ||
public bool Process(OperationProcessorContext context) | ||
{ | ||
var headerAttribute = context.MethodInfo.GetCustomAttribute<ProducesResponseHeaderAttribute>(); | ||
if (headerAttribute == null) | ||
{ | ||
return true; | ||
} | ||
|
||
var statusCode = headerAttribute.StatusCode.ToString(CultureInfo.InvariantCulture); | ||
var response = context.OperationDescription.Operation.Responses[statusCode]; | ||
var header = new OpenApiHeader | ||
{ | ||
Description = headerAttribute.Description, | ||
}; | ||
|
||
response.Headers.Add(headerAttribute.HeaderName, header); | ||
return true; | ||
} | ||
} |
This file contains 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