|
|
|
@ -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<IModelMetadataProvider>().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)
|
|
|
|
|
{
|
|
|
|
|