From 8663bad5a1f8d487ae20faccf90a959cd34bd4f6 Mon Sep 17 00:00:00 2001 From: Ivar Nesje Date: Sat, 18 Jan 2025 08:27:38 +0100 Subject: [PATCH] Fix a few nullability issues in api spec (#1041) * Fix a few nullability issues in api spec * Fix another issue and update generated spec --- .../Models/DataPatchResponseMultiple.cs | 11 ++--- src/Altinn.App.Api/Models/DataPostResponse.cs | 11 ++--- .../Validation/ValidationIssueWithSource.cs | 7 ++-- ...angeDetection.SaveJsonSwagger.verified.txt | 40 ++++++++++--------- .../Altinn.App.Api.Tests/OpenApi/swagger.json | 38 ++++++++++-------- 5 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/Altinn.App.Api/Models/DataPatchResponseMultiple.cs b/src/Altinn.App.Api/Models/DataPatchResponseMultiple.cs index dcd2c41b9..8bf763b9a 100644 --- a/src/Altinn.App.Api/Models/DataPatchResponseMultiple.cs +++ b/src/Altinn.App.Api/Models/DataPatchResponseMultiple.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using Altinn.App.Api.Controllers; using Altinn.App.Core.Models.Validation; @@ -13,19 +14,19 @@ public class DataPatchResponseMultiple /// /// The validation issues that were found during the patch operation. /// - [JsonPropertyName("validationIssues")] + [JsonPropertyName("validationIssues"), Required] public required List ValidationIssues { get; init; } /// /// The current data in all data models updated by the patch operation. /// - [JsonPropertyName("newDataModels")] + [JsonPropertyName("newDataModels"), Required] public required List NewDataModels { get; init; } /// /// The instance with updated dataElement list. /// - [JsonPropertyName("instance")] + [JsonPropertyName("instance"), Required] public required Instance Instance { get; init; } } @@ -35,6 +36,6 @@ public class DataPatchResponseMultiple /// The guid of the DataElement /// The form data of the data element public record DataModelPairResponse( - [property: JsonPropertyName("dataElementId")] Guid DataElementId, - [property: JsonPropertyName("data")] object Data + [property: JsonPropertyName("dataElementId"), Required] Guid DataElementId, + [property: JsonPropertyName("data"), Required] object Data ); diff --git a/src/Altinn.App.Api/Models/DataPostResponse.cs b/src/Altinn.App.Api/Models/DataPostResponse.cs index 11a26145e..72948820c 100644 --- a/src/Altinn.App.Api/Models/DataPostResponse.cs +++ b/src/Altinn.App.Api/Models/DataPostResponse.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.Net; using System.Text.Json.Serialization; using Altinn.App.Core.Models.Validation; @@ -14,25 +15,25 @@ public class DataPostResponse /// /// The Id of the created data element /// - [JsonPropertyName("newDataElementId")] + [JsonPropertyName("newDataElementId"), Required] public required Guid NewDataElementId { get; init; } /// /// The instance with updated data /// - [JsonPropertyName("instance")] + [JsonPropertyName("instance"), Required] public required Instance Instance { get; init; } /// /// List of validation issues that reported to have relevant changes after a new data element was added /// - [JsonPropertyName("validationIssues")] + [JsonPropertyName("validationIssues"), Required] public required List ValidationIssues { get; init; } /// /// List of updated DataModels caused by dataProcessing /// - [JsonPropertyName("newDataModels")] + [JsonPropertyName("newDataModels"), Required] public required List NewDataModels { get; init; } } @@ -55,6 +56,6 @@ public DataPostErrorResponse(string detail, List vali /// /// List of the validators that reported to have relevant changes after a new data element was added /// - [JsonPropertyName("uploadValidationIssues")] + [JsonPropertyName("uploadValidationIssues"), Required] public List UploadValidationIssues { get; } } diff --git a/src/Altinn.App.Core/Models/Validation/ValidationIssueWithSource.cs b/src/Altinn.App.Core/Models/Validation/ValidationIssueWithSource.cs index 551c6ac27..8c54e6c7a 100644 --- a/src/Altinn.App.Core/Models/Validation/ValidationIssueWithSource.cs +++ b/src/Altinn.App.Core/Models/Validation/ValidationIssueWithSource.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using Altinn.App.Core.Features; @@ -70,7 +71,7 @@ public static ValidationIssueWithSource FromIssue(ValidationIssue issue, string /// /// The short name of the class that crated the message (set automatically after return of list) /// - [JsonPropertyName("source")] + [JsonPropertyName("source"), Required] public required string Source { get; set; } /// @@ -106,6 +107,6 @@ public static ValidationIssueWithSource FromIssue(ValidationIssue issue, string /// The for the Validator that created theese issues /// List of issues public record ValidationSourcePair( - [property: JsonPropertyName("source")] string Source, - [property: JsonPropertyName("issues")] List Issues + [property: JsonPropertyName("source"), Required] string Source, + [property: JsonPropertyName("issues"), Required] List Issues ); diff --git a/test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.txt b/test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.txt index a49147298..14d3f68e0 100644 --- a/test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.txt +++ b/test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.txt @@ -1,4 +1,4 @@ -{ +{ openapi: 3.0.1, info: { title: Altinn App Api, @@ -6442,6 +6442,10 @@ to a model, and then finally the state of the instance., additionalProperties: false }, DataModelPairResponse: { + required: [ + data, + dataElementId + ], type: object, properties: { dataElementId: { @@ -6450,8 +6454,7 @@ to a model, and then finally the state of the instance., format: uuid }, data: { - description: The form data of the data element, - nullable: true + description: The form data of the data element } }, additionalProperties: false, @@ -6555,16 +6558,14 @@ version that supports multiple data models in the same request. items: { $ref: #/components/schemas/ValidationSourcePair }, - description: The validation issues that were found during the patch operation., - nullable: true + description: The validation issues that were found during the patch operation. }, newDataModels: { type: array, items: { $ref: #/components/schemas/DataModelPairResponse }, - description: The current data in all data models updated by the patch operation., - nullable: true + description: The current data in all data models updated by the patch operation. }, instance: { $ref: #/components/schemas/Instance @@ -6574,6 +6575,9 @@ version that supports multiple data models in the same request. description: Represents the response from a data patch operation on the Altinn.App.Api.Controllers.DataController. }, DataPostErrorResponse: { + required: [ + uploadValidationIssues + ], type: object, properties: { type: { @@ -6603,7 +6607,6 @@ version that supports multiple data models in the same request. $ref: #/components/schemas/ValidationIssueWithSource }, description: List of the validators that reported to have relevant changes after a new data element was added, - nullable: true, readOnly: true } }, @@ -6631,16 +6634,14 @@ version that supports multiple data models in the same request. items: { $ref: #/components/schemas/ValidationSourcePair }, - description: List of validation issues that reported to have relevant changes after a new data element was added, - nullable: true + description: List of validation issues that reported to have relevant changes after a new data element was added }, newDataModels: { type: array, items: { $ref: #/components/schemas/DataModelPairResponse }, - description: List of updated DataModels caused by dataProcessing, - nullable: true + description: List of updated DataModels caused by dataProcessing } }, additionalProperties: false, @@ -8147,8 +8148,8 @@ Validators that are not listed in the dictionary are assumed to have not been ex nullable: true }, source: { - type: string, - nullable: true + minLength: 1, + type: string }, noIncrementalUpdates: { type: boolean @@ -8168,18 +8169,21 @@ Validators that are not listed in the dictionary are assumed to have not been ex additionalProperties: false }, ValidationSourcePair: { + required: [ + issues, + source + ], type: object, properties: { source: { - type: string, - nullable: true + minLength: 1, + type: string }, issues: { type: array, items: { $ref: #/components/schemas/ValidationIssueWithSource - }, - nullable: true + } } }, additionalProperties: false diff --git a/test/Altinn.App.Api.Tests/OpenApi/swagger.json b/test/Altinn.App.Api.Tests/OpenApi/swagger.json index aa147604a..c52af90c8 100644 --- a/test/Altinn.App.Api.Tests/OpenApi/swagger.json +++ b/test/Altinn.App.Api.Tests/OpenApi/swagger.json @@ -6443,6 +6443,10 @@ "additionalProperties": false }, "DataModelPairResponse": { + "required": [ + "data", + "dataElementId" + ], "type": "object", "properties": { "dataElementId": { @@ -6451,8 +6455,7 @@ "format": "uuid" }, "data": { - "description": "The form data of the data element", - "nullable": true + "description": "The form data of the data element" } }, "additionalProperties": false, @@ -6550,16 +6553,14 @@ "items": { "$ref": "#/components/schemas/ValidationSourcePair" }, - "description": "The validation issues that were found during the patch operation.", - "nullable": true + "description": "The validation issues that were found during the patch operation." }, "newDataModels": { "type": "array", "items": { "$ref": "#/components/schemas/DataModelPairResponse" }, - "description": "The current data in all data models updated by the patch operation.", - "nullable": true + "description": "The current data in all data models updated by the patch operation." }, "instance": { "$ref": "#/components/schemas/Instance" @@ -6569,6 +6570,9 @@ "description": "Represents the response from a data patch operation on the Altinn.App.Api.Controllers.DataController." }, "DataPostErrorResponse": { + "required": [ + "uploadValidationIssues" + ], "type": "object", "properties": { "type": { @@ -6598,7 +6602,6 @@ "$ref": "#/components/schemas/ValidationIssueWithSource" }, "description": "List of the validators that reported to have relevant changes after a new data element was added", - "nullable": true, "readOnly": true } }, @@ -6627,16 +6630,14 @@ "items": { "$ref": "#/components/schemas/ValidationSourcePair" }, - "description": "List of validation issues that reported to have relevant changes after a new data element was added", - "nullable": true + "description": "List of validation issues that reported to have relevant changes after a new data element was added" }, "newDataModels": { "type": "array", "items": { "$ref": "#/components/schemas/DataModelPairResponse" }, - "description": "List of updated DataModels caused by dataProcessing", - "nullable": true + "description": "List of updated DataModels caused by dataProcessing" } }, "additionalProperties": false, @@ -8143,8 +8144,8 @@ "nullable": true }, "source": { - "type": "string", - "nullable": true + "minLength": 1, + "type": "string" }, "noIncrementalUpdates": { "type": "boolean" @@ -8164,18 +8165,21 @@ "additionalProperties": false }, "ValidationSourcePair": { + "required": [ + "issues", + "source" + ], "type": "object", "properties": { "source": { - "type": "string", - "nullable": true + "minLength": 1, + "type": "string" }, "issues": { "type": "array", "items": { "$ref": "#/components/schemas/ValidationIssueWithSource" - }, - "nullable": true + } } }, "additionalProperties": false