diff --git a/docs/schema/V1/swagger.verified.json b/docs/schema/V1/swagger.verified.json index 766a0763f..322a57cf0 100644 --- a/docs/schema/V1/swagger.verified.json +++ b/docs/schema/V1/swagger.verified.json @@ -6145,140 +6145,6 @@ "requestBody": { "content": { "application/json": { - "example": { - "Activities": [ - { - "CreatedAt": null, - "Description": [ - { - "LanguageCode": "en", - "Value": "Some description" - }, - { - "LanguageCode": "nb", - "Value": "En beskrivelse" - } - ], - "ExtendedType": null, - "Id": "8b95d42d-d2b6-4c01-8ca0-a817a4b3c50d", - "PerformedBy": { - "ActorId": null, - "ActorName": null, - "ActorType": 2 - }, - "TransmissionId": null, - "Type": 3 - } - ], - "ApiActions": [ - { - "Action": "submit", - "AuthorizationAttribute": null, - "Endpoints": [ - { - "Deprecated": false, - "DocumentationUrl": "https://example.com/some-api-action-doc", - "HttpMethod": 2, - "Id": null, - "RequestSchema": "https://example.com/some-api-action-request-schema", - "ResponseSchema": "https://example.com/some-api-action-response-schema", - "SunsetAt": null, - "Url": "https://example.com/some-api-action", - "Version": "20231015" - } - ], - "Id": "948b07ba-1a82-403e-8eaa-2e5784af07a9" - } - ], - "Attachments": [ - { - "DisplayName": [ - { - "LanguageCode": "en", - "Value": "Some display name" - } - ], - "Id": "02a72809-eddd-4192-864d-8f1755d72f4e", - "Urls": [ - { - "ConsumerType": 0, - "Id": "858177cb-8584-4d10-a086-3a5defa7a6c3", - "MediaType": null, - "Url": "https://example.com/some-url" - } - ] - } - ], - "Content": { - "AdditionalInfo": { - "MediaType": "text/markdown", - "Value": [ - { - "LanguageCode": "en", - "Value": "Some description with *markdown* support" - } - ] - }, - "ExtendedStatus": null, - "MainContentReference": null, - "SenderName": null, - "Summary": { - "MediaType": "text/plain", - "Value": [ - { - "LanguageCode": "en", - "Value": "Some Summary" - } - ] - }, - "Title": { - "MediaType": "text/plain", - "Value": [ - { - "LanguageCode": "en", - "Value": "Some title" - } - ] - } - }, - "DueAt": "2084-04-04T12:13:10.01344\u002B00:00", - "ExpiresAt": "2095-05-04T12:13:10.01344\u002B00:00", - "ExtendedStatus": "Some extended status", - "ExternalReference": "Some external reference", - "GuiActions": [ - { - "Action": "submit", - "AuthorizationAttribute": null, - "HttpMethod": 1, - "Id": "8c64ecc8-7678-44b2-8788-0b5852dd8fa0", - "IsDeleteDialogAction": false, - "Priority": 1, - "Prompt": null, - "Title": [ - { - "LanguageCode": "en", - "Value": "GUI action title" - }, - { - "LanguageCode": "nb", - "Value": "GUI action-tittel" - } - ], - "Url": "https://example.com/some-url" - } - ], - "Progress": 42, - "SearchTags": [ - { - "Value": "searchTag" - }, - { - "Value": "anotherSearchTag" - } - ], - "Status": 1, - "VisibleFrom": "2054-03-04T12:13:10.01344\u002B00:00" - }, "schema": { "$ref": "#/components/schemas/V1ServiceOwnerDialogsCommandsUpdate_Dialog" } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Update/UpdateDialogEndpointSummary.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Update/UpdateDialogEndpointSummary.cs new file mode 100644 index 000000000..08a2b5541 --- /dev/null +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Update/UpdateDialogEndpointSummary.cs @@ -0,0 +1,29 @@ +using Digdir.Domain.Dialogporten.WebApi.Common; +using Digdir.Domain.Dialogporten.WebApi.Common.Authorization; +using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; +using FastEndpoints; + +namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialogs.Update; + +public sealed class UpdateDialogEndpointSummary : Summary +{ + public UpdateDialogEndpointSummary() + { + Summary = "Replaces a dialog"; + Description = $""" + Replaces a given dialog with the supplied model. For more information see the documentation (link TBD). + + {Constants.SwaggerSummary.OptimisticConcurrencyNote} + """; + Responses[StatusCodes.Status204NoContent] = Constants.SwaggerSummary.Updated.FormatInvariant("aggregate"); + Responses[StatusCodes.Status400BadRequest] = Constants.SwaggerSummary.ValidationError; + Responses[StatusCodes.Status401Unauthorized] = + Constants.SwaggerSummary.ServiceOwnerAuthenticationFailure.FormatInvariant(AuthorizationScope + .ServiceProvider); + Responses[StatusCodes.Status403Forbidden] = + Constants.SwaggerSummary.AccessDeniedToDialog.FormatInvariant("update"); + Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound; + Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch; + Responses[StatusCodes.Status422UnprocessableEntity] = Constants.SwaggerSummary.DomainError; + } +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Update/UpdateDialogSwaggerConfig.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Update/UpdateDialogSwaggerConfig.cs deleted file mode 100644 index c8b7a2afc..000000000 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Update/UpdateDialogSwaggerConfig.cs +++ /dev/null @@ -1,195 +0,0 @@ -using System.Globalization; -using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; -using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Common.Actors; -using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update; -using Digdir.Domain.Dialogporten.Domain; -using Digdir.Domain.Dialogporten.Domain.Actors; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actions; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; -using Digdir.Domain.Dialogporten.Domain.Http; -using Digdir.Domain.Dialogporten.WebApi.Common; -using Digdir.Domain.Dialogporten.WebApi.Common.Authorization; -using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; -using FastEndpoints; - -namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialogs.Update; - -internal abstract class UpdateDialogSwaggerConfig -{ - // TODO: Create fakers - public static object GetExample() => new UpdateDialogDto - { - Progress = 42, - ExtendedStatus = "Some extended status", - ExternalReference = "Some external reference", - Status = DialogStatus.Values.New, - SearchTags = - [ - new SearchTagDto - { - Value = "searchTag" - }, - new SearchTagDto - { - Value = "anotherSearchTag" - } - ], - Content = new() - { - Title = new() - { - Value = - [ - new LocalizationDto - { - LanguageCode = "en-us", - Value = "Some title" - } - ] - }, - Summary = new() - { - Value = - [ - new LocalizationDto - { - LanguageCode = "en-us", - Value = "Some Summary" - } - ] - }, - AdditionalInfo = new() - { - MediaType = MediaTypes.Markdown, - Value = - [ - new LocalizationDto - { - LanguageCode = "en-us", - Value = "Some description with *markdown* support" - } - ] - } - }, - VisibleFrom = DateTimeOffset.Parse("2054-03-04T12:13:10.0134400+00:00", CultureInfo.InvariantCulture), - ExpiresAt = DateTimeOffset.Parse("2095-05-04T12:13:10.0134400+00:00", CultureInfo.InvariantCulture), - DueAt = DateTimeOffset.Parse("2084-04-04T12:13:10.0134400+00:00", CultureInfo.InvariantCulture), - Attachments = - [ - new AttachmentDto - { - Id = Guid.Parse("02a72809-eddd-4192-864d-8f1755d72f4e"), - DisplayName = - [ - new LocalizationDto - { - LanguageCode = "en-us", - Value = "Some display name" - } - ], - Urls = - [ - new AttachmentUrlDto - { - Id = Guid.Parse("858177cb-8584-4d10-a086-3a5defa7a6c3"), - Url = new Uri("https://example.com/some-url") - } - ] - } - ], - GuiActions = - [ - new GuiActionDto - { - Id = Guid.Parse("8c64ecc8-7678-44b2-8788-0b5852dd8fa0"), - Action = "submit", - Priority = DialogGuiActionPriority.Values.Primary, - Url = new Uri("https://example.com/some-url"), - IsDeleteDialogAction = false, - Title = - [ - new LocalizationDto - { - LanguageCode = "en-us", - Value = "GUI action title" - }, - new LocalizationDto - { - LanguageCode = "nb-no", - Value = "GUI action-tittel" - } - ] - } - ], - ApiActions = - [ - new ApiActionDto - { - Id = Guid.Parse("948b07ba-1a82-403e-8eaa-2e5784af07a9"), - Action = "submit", - Endpoints = - [ - new ApiActionEndpointDto - { - Version = "20231015", - HttpMethod = HttpVerb.Values.POST, - Deprecated = false, - Url = new Uri("https://example.com/some-api-action"), - DocumentationUrl = new Uri("https://example.com/some-api-action-doc"), - RequestSchema = new Uri("https://example.com/some-api-action-request-schema"), - ResponseSchema = new Uri("https://example.com/some-api-action-response-schema") - } - ] - } - ], - Activities = - [ - new ActivityDto - { - Id = Guid.Parse("8b95d42d-d2b6-4c01-8ca0-a817a4b3c50d"), - Type = DialogActivityType.Values.Information, - PerformedBy = new ActorDto - { - ActorType = ActorType.Values.ServiceOwner - }, - Description = - [ - new LocalizationDto - { - LanguageCode = "en-us", - Value = "Some description" - }, - new LocalizationDto - { - LanguageCode = "nb-no", - Value = "En beskrivelse" - } - ] - } - ] - }; -} - -public sealed class UpdateDialogEndpointSummary : Summary -{ - public UpdateDialogEndpointSummary() - { - Summary = "Replaces a dialog"; - Description = $""" - Replaces a given dialog with the supplied model. For more information see the documentation (link TBD). - - {Constants.SwaggerSummary.OptimisticConcurrencyNote} - """; - Responses[StatusCodes.Status204NoContent] = Constants.SwaggerSummary.Updated.FormatInvariant("aggregate"); - Responses[StatusCodes.Status400BadRequest] = Constants.SwaggerSummary.ValidationError; - Responses[StatusCodes.Status401Unauthorized] = - Constants.SwaggerSummary.ServiceOwnerAuthenticationFailure.FormatInvariant(AuthorizationScope - .ServiceProvider); - Responses[StatusCodes.Status403Forbidden] = - Constants.SwaggerSummary.AccessDeniedToDialog.FormatInvariant("update"); - Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound; - Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch; - Responses[StatusCodes.Status422UnprocessableEntity] = Constants.SwaggerSummary.DomainError; - } -} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs b/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs index c48e0dec4..384199f89 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs @@ -6,45 +6,6 @@ namespace Digdir.Domain.Dialogporten.WebApi; public static class OpenApiDocumentExtensions { - /// - /// This is a workaround for a bug/weird behavior in FastEndpoints where examples - /// to the RequestExamples array are not added to the OpenAPI document. - /// Each SwaggerConfig file implements a GetExample method that returns the example - /// - /// This sets for those who have a request body. - /// - /// - public static void ReplaceRequestExampleBodies(this OpenApiDocument openApiDocument) - { - foreach (var path in openApiDocument.Paths) - { - foreach (var openApiOperation in path.Value.Values) - { - openApiOperation.ReplaceRequestExampleBody(); - } - } - } - - private static void ReplaceRequestExampleBody(this OpenApiOperation openApiOperation) - { - if (openApiOperation.RequestBody?.Content == null) - { - return; - } - - var operationId = openApiOperation.OperationId; - - // TEMP hard coding of operationId, there is only one endpoint with a request body example - // More to follow, make look up function based on operationId - if (operationId != "V1ServiceOwnerDialogsUpdate_Dialog") return; - - foreach (var (_, value) in openApiOperation.RequestBody.Content) - { - var example = UpdateDialogSwaggerConfig.GetExample(); - value.Example = example; - } - } - /// /// When generating ProblemDetails and ProblemDetails_Error, there is a bug/weird behavior in NSwag or FastEndpoints /// which results in certain 'Description' properties being generated when running on f.ex. MacOS, diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index d08c68cc2..5185cc8cf 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -200,7 +200,6 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura document.Servers.Add(new OpenApiServer { Url = dialogportenBaseUri }); document.Generator = null; document.ReplaceProblemDetailsDescriptions(); - document.ReplaceRequestExampleBodies(); document.MakeCollectionsNullable(); }; }, uiConfig =>