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

fix(webi): Add missing type on ETag response headers #1666

Merged
merged 2 commits into from
Jan 8, 2025
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
36 changes: 30 additions & 6 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -5866,7 +5866,11 @@
"description": "The UUID of the created dialog aggregate. A relative URL to the newly created activity is set in the \u0022Location\u0022 header.",
"headers": {
"Etag": {
"description": "The new UUID ETag of the dialog"
"description": "The new UUID ETag of the dialog",
"example": "123e4567-e89b-12d3-a456-426614174000",
"schema": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -5940,7 +5944,11 @@
"description": "The dialog aggregate was deleted successfully.",
"headers": {
"Etag": {
"description": "The new UUID ETag of the dialog"
"description": "The new UUID ETag of the dialog",
"example": "123e4567-e89b-12d3-a456-426614174000",
"schema": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -6101,7 +6109,11 @@
"description": "Patch was successfully applied.",
"headers": {
"Etag": {
"description": "The new UUID ETag of the dialog"
"description": "The new UUID ETag of the dialog",
"example": "123e4567-e89b-12d3-a456-426614174000",
"schema": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -6201,7 +6213,11 @@
"description": "The dialog aggregate was updated successfully.",
"headers": {
"Etag": {
"description": "The new UUID ETag of the dialog"
"description": "The new UUID ETag of the dialog",
"example": "123e4567-e89b-12d3-a456-426614174000",
"schema": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -6504,7 +6520,11 @@
"description": "The UUID of the created dialog activity. A relative URL to the newly created activity is set in the \u0022Location\u0022 header.",
"headers": {
"Etag": {
"description": "The new UUID ETag of the dialog"
"description": "The new UUID ETag of the dialog",
"example": "123e4567-e89b-12d3-a456-426614174000",
"schema": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -6872,7 +6892,11 @@
"description": "The UUID of the created dialog transmission. A relative URL to the newly created activity is set in the \u0022Location\u0022 header.",
"headers": {
"Etag": {
"description": "The new UUID ETag of the dialog"
"description": "The new UUID ETag of the dialog",
"example": "123e4567-e89b-12d3-a456-426614174000",
"schema": {
"type": "string"
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public static ResponseHeader NewDialogETagHeader(int statusCode)
=> new(statusCode, Constants.ETag)
{
Description = "The new UUID ETag of the dialog",
Example = "123e4567-e89b-12d3-a456-426614174000"
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public PatchDialogsController(ISender sender, IMapper mapper)
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseHeader(StatusCodes.Status204NoContent, Constants.ETag, "The new UUID ETag of the dialog")]
[ProducesResponseHeader(StatusCodes.Status204NoContent, Constants.ETag, "The new UUID ETag of the dialog", "123e4567-e89b-12d3-a456-426614174000")]
public async Task<IActionResult> Patch(
[FromRoute] Guid dialogId,
[FromHeader(Name = Constants.IfMatch)] Guid? etag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
using NJsonSchema;

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)
public ProducesResponseHeaderAttribute(int statusCode, string headerName,
string description, string example, JsonObjectType type = JsonObjectType.String)
{
HeaderName = headerName;
StatusCode = statusCode;
Description = description;
Example = example;
Type = type;
}

public string HeaderName { get; }
public int StatusCode { get; }
public string Description { get; }
public string Example { get; }

public JsonObjectType Type { get; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Globalization;
using System.Reflection;
using NJsonSchema;
using NSwag;
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;
Expand All @@ -21,6 +22,11 @@ public bool Process(OperationProcessorContext context)
var header = new OpenApiHeader
{
Description = headerAttribute.Description,
Example = headerAttribute.Example,
Schema = new JsonSchema
{
Type = headerAttribute.Type
}
};

response.Headers.Add(headerAttribute.HeaderName, header);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ namespace Digdir.Domain.Dialogporten.WebApi;

public static class OpenApiDocumentExtensions
{
/// <summary>
/// FastEndpoints generates a title for headers with the format "System_String", which is a C# specific type.
/// </summary>
/// <param name="openApiDocument"></param>
public static void RemoveSystemStringHeaderTitles(this OpenApiDocument openApiDocument)
{
const string systemString = "System_String";
var headers = openApiDocument.Paths
.SelectMany(path => path.Value
.SelectMany(operation => operation.Value.Responses
.SelectMany(response => response.Value.Headers
.Where(header => header.Value.Schema.Title == systemString))));

foreach (var header in headers)
{
header.Value.Schema.Title = null;
}
}

/// <summary>
/// To have this be validated in BlackDuck, we need to lower case the bearer scheme name.
/// From editor.swagger.io:
Expand Down
1 change: 1 addition & 0 deletions src/Digdir.Domain.Dialogporten.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
document.ReplaceProblemDetailsDescriptions();
document.MakeCollectionsNullable();
document.FixJwtBearerCasing();
document.RemoveSystemStringHeaderTitles();
};
}, uiConfig =>
{
Expand Down
Loading