From 2bba395fbe24b57f894a938f8e9570f1b75c31db Mon Sep 17 00:00:00 2001 From: Davis Hoang Date: Sat, 4 Jan 2025 21:57:52 +0800 Subject: [PATCH] Use AdditionalNamespaceUsages for nswag gen --- QuizApp.Api/QuizApiClient.cs | 93 ++---------------------------------- QuizApp/Program.cs | 2 + 2 files changed, 6 insertions(+), 89 deletions(-) diff --git a/QuizApp.Api/QuizApiClient.cs b/QuizApp.Api/QuizApiClient.cs index e4f19c2..7b156be 100644 --- a/QuizApp.Api/QuizApiClient.cs +++ b/QuizApp.Api/QuizApiClient.cs @@ -4,6 +4,9 @@ // //---------------------- +using QuizApp.Common.DTO; +using QuizApp.Common.Request; + #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." #pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." #pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' @@ -907,95 +910,7 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class UserDTO - { - [Newtonsoft.Json.JsonProperty("FullName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string FullName { get; set; } - - [Newtonsoft.Json.JsonProperty("Username", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Username { get; set; } - - [Newtonsoft.Json.JsonProperty("UserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string UserId { get; set; } - - [Newtonsoft.Json.JsonProperty("Role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Role { get; set; } - - [Newtonsoft.Json.JsonProperty("Email", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Email { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class SaveSubmissionRequest - { - [Newtonsoft.Json.JsonProperty("QuizId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int QuizId { get; set; } - - [Newtonsoft.Json.JsonProperty("UserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int UserId { get; set; } - - [Newtonsoft.Json.JsonProperty("UserAnswerDTOs", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.Generic.ICollection UserAnswerDTOs { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class UserAnswerDTO - { - [Newtonsoft.Json.JsonProperty("QuestionId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int QuestionId { get; set; } - - [Newtonsoft.Json.JsonProperty("SelectedAnswerId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int SelectedAnswerId { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class QuizDTO - { - [Newtonsoft.Json.JsonProperty("Id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int? Id { get; set; } - - [Newtonsoft.Json.JsonProperty("Name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } - - [Newtonsoft.Json.JsonProperty("Description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class QuestionDTO - { - [Newtonsoft.Json.JsonProperty("QuizId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int QuizId { get; set; } - - [Newtonsoft.Json.JsonProperty("Id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int Id { get; set; } - - [Newtonsoft.Json.JsonProperty("Title", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Title { get; set; } - - [Newtonsoft.Json.JsonProperty("Answers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.Generic.ICollection Answers { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AnswerDTO - { - [Newtonsoft.Json.JsonProperty("Id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int Id { get; set; } - - [Newtonsoft.Json.JsonProperty("Text", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Text { get; set; } - - [Newtonsoft.Json.JsonProperty("IsCorrect", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool IsCorrect { get; set; } - - } + diff --git a/QuizApp/Program.cs b/QuizApp/Program.cs index 9c8cb96..2c367fa 100644 --- a/QuizApp/Program.cs +++ b/QuizApp/Program.cs @@ -134,6 +134,8 @@ await app.GenerateClientsAndExitAsync( c.ClassName = "QuizApiClient"; c.InjectHttpClient = true; c.GenerateClientInterfaces = true; + c.GenerateDtoTypes = false; + c.AdditionalNamespaceUsages = ["QuizApp.Common.DTO", "QuizApp.Common.Request"]; c.CSharpGeneratorSettings.Namespace = "QuizApp.Api"; c.CSharpGeneratorSettings.JsonLibrary = CSharpJsonLibrary.NewtonsoftJson; },