From 70c3c9d0951b0514a16b0278eae40597b43c2023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Wed, 8 Jan 2025 16:10:20 +0100 Subject: [PATCH] idefix --- docs/schema/V1/swagger.verified.json | 36 +++++++++++++++---- .../Headers/HttpResponseHeaderExamples.cs | 1 + .../Dialogs/Patch/PatchDialogsController.cs | 2 +- .../Patch/ProducesResponseHeaderAttribute.cs | 10 +++++- ...roducesResponseHeaderOperationProcessor.cs | 6 ++++ .../OpenApiDocumentExtensions.cs | 19 ++++++++++ .../Program.cs | 1 + 7 files changed, 67 insertions(+), 8 deletions(-) diff --git a/docs/schema/V1/swagger.verified.json b/docs/schema/V1/swagger.verified.json index 375c25de3..123733d29 100644 --- a/docs/schema/V1/swagger.verified.json +++ b/docs/schema/V1/swagger.verified.json @@ -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" + } } } }, @@ -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" + } } } }, @@ -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" + } } } }, @@ -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" + } } } }, @@ -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" + } } } }, @@ -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" + } } } }, diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Common/Headers/HttpResponseHeaderExamples.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Common/Headers/HttpResponseHeaderExamples.cs index 288ed510d..b0edc3761 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Common/Headers/HttpResponseHeaderExamples.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Common/Headers/HttpResponseHeaderExamples.cs @@ -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" }; } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/PatchDialogsController.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/PatchDialogsController.cs index f56fbb7ef..47eb5ade9 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/PatchDialogsController.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/PatchDialogsController.cs @@ -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 Patch( [FromRoute] Guid dialogId, [FromHeader(Name = Constants.IfMatch)] Guid? etag, diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderAttribute.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderAttribute.cs index 77e2d3e12..595c6bd82 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderAttribute.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderAttribute.cs @@ -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; } } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderOperationProcessor.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderOperationProcessor.cs index 26ec4387e..b0b3518ff 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderOperationProcessor.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Patch/ProducesResponseHeaderOperationProcessor.cs @@ -1,5 +1,6 @@ using System.Globalization; using System.Reflection; +using NJsonSchema; using NSwag; using NSwag.Generation.Processors; using NSwag.Generation.Processors.Contexts; @@ -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); diff --git a/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs b/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs index a9d53de3f..cdec5280c 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs @@ -5,6 +5,25 @@ namespace Digdir.Domain.Dialogporten.WebApi; public static class OpenApiDocumentExtensions { + /// + /// FastEndpoints generates a title for headers with the format "System_String", which is a C# specific type. + /// + /// + 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; + } + } + /// /// To have this be validated in BlackDuck, we need to lower case the bearer scheme name. /// From editor.swagger.io: diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index 7674052f5..2e91d65ae 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -214,6 +214,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura document.ReplaceProblemDetailsDescriptions(); document.MakeCollectionsNullable(); document.FixJwtBearerCasing(); + document.RemoveSystemStringHeaderTitles(); }; }, uiConfig => {