Skip to content

Commit

Permalink
fix(webi): Add missing type on ETag response headers (#1666)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Related Issue(s)

- #1665 

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)

Co-authored-by: Knut Haug <knut.espen.haug@digdir.no>
  • Loading branch information
oskogstad and knuhau authored Jan 8, 2025
1 parent 1d947b1 commit df559ed
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
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
19 changes: 19 additions & 0 deletions src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs
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

0 comments on commit df559ed

Please sign in to comment.