diff --git a/docs/业务分析.xlsx b/docs/业务分析.xlsx new file mode 100644 index 00000000..a83628e8 Binary files /dev/null and b/docs/业务分析.xlsx differ diff --git a/labs/CSharpObjectJsonSchema/Controllers/ControllerExtensions.cs b/labs/CSharpObjectJsonSchema/Controllers/ControllerExtensions.cs index ef6d609c..70da06a0 100644 --- a/labs/CSharpObjectJsonSchema/Controllers/ControllerExtensions.cs +++ b/labs/CSharpObjectJsonSchema/Controllers/ControllerExtensions.cs @@ -26,6 +26,17 @@ namespace CSharpObjectJsonSchema.Controllers return CreateJson(controller, metadata as DefaultModelMetadata); } + public static object GetJsonSchema(this ControllerBase controller, Type type) + { + if (controller is null) + { + throw new ArgumentNullException(nameof(controller)); + } + var metadata = controller.HttpContext.RequestServices.GetRequiredService().GetMetadataForType(type); + + return CreateJson(controller, metadata as DefaultModelMetadata); + } + public static object CreateJson(this ControllerBase controller, DefaultModelMetadata metadata) { if (metadata is null) @@ -40,7 +51,7 @@ namespace CSharpObjectJsonSchema.Controllers if (metadata.IsComplexType && metadata.IsCollectionType) { json.type = "array"; - json.items = new { type = metadata.ModelType.GenericTypeArguments[0].Name }; + json.items = controller.GetJsonSchema(metadata.ModelType.GenericTypeArguments[0]); } else if (metadata.IsEnum) { diff --git a/labs/CSharpObjectJsonSchema/Models/TestModel.cs b/labs/CSharpObjectJsonSchema/Models/TestModel.cs index 6f191e79..9ab8fe7a 100644 --- a/labs/CSharpObjectJsonSchema/Models/TestModel.cs +++ b/labs/CSharpObjectJsonSchema/Models/TestModel.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; using System; using System.Collections.Generic; using System.ComponentModel; @@ -52,6 +53,8 @@ namespace CSharpObjectJsonSchema.Models public List Ids { get; set; } = new List(); + public List SelectList { get; set; } = new List(); + //public TestModel Model1 { get; set; } }