mirror of
https://github.com/RRQM/TouchSocket.git
synced 2025-12-17 17:06:45 +08:00
@@ -11,6 +11,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using TouchSocket.Core;
|
||||
|
||||
@@ -37,6 +38,11 @@ public class RpcParameter
|
||||
/// </summary>
|
||||
public ParameterInfo ParameterInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数描述
|
||||
/// </summary>
|
||||
public string ParameterDesc => this.ParameterInfo.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
|
||||
/// <summary>
|
||||
/// 参数名称
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,9 @@ internal class OpenApiParameter
|
||||
|
||||
[JsonProperty("in")]
|
||||
public string In { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[JsonProperty("schema")]
|
||||
public OpenApiSchema Schema { get; set; }
|
||||
|
||||
@@ -30,4 +30,7 @@ internal class OpenApiProperty
|
||||
|
||||
[JsonProperty("items")]
|
||||
public OpenApiProperty Items { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -313,6 +314,7 @@ public sealed class SwaggerPlugin : PluginBase, IServerStartedPlugin, IHttpPlugi
|
||||
{
|
||||
var openApiParameter = this.GetParameter(parameter.ParameterInfo);
|
||||
openApiParameter.In = "query";
|
||||
openApiParameter.Description = parameter.ParameterDesc;
|
||||
this.AddSchemaType(parameter.Type, schemaTypeList);
|
||||
openApiParameters.Add(openApiParameter);
|
||||
}
|
||||
@@ -349,11 +351,10 @@ public sealed class SwaggerPlugin : PluginBase, IServerStartedPlugin, IHttpPlugi
|
||||
openApiPathValue.Responses.Add("200", openApiResponse);
|
||||
}
|
||||
|
||||
private OpenApiProperty CreateProperty(Type type)
|
||||
private OpenApiProperty CreateProperty(Type type, string description = "")
|
||||
{
|
||||
var openApiProperty = new OpenApiProperty();
|
||||
var dataTypes = this.ParseDataTypes(type);
|
||||
|
||||
switch (dataTypes)
|
||||
{
|
||||
case OpenApiDataTypes.String:
|
||||
@@ -379,7 +380,7 @@ public sealed class SwaggerPlugin : PluginBase, IServerStartedPlugin, IHttpPlugi
|
||||
case OpenApiDataTypes.Array:
|
||||
{
|
||||
openApiProperty.Type = dataTypes;
|
||||
openApiProperty.Items = this.CreateProperty(type.IsArray ? type.GetElementType() : type.GetGenericArguments()[0]);
|
||||
openApiProperty.Items = this.CreateProperty(type.IsArray ? type.GetElementType() : type.GetGenericArguments()[0], description);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -399,7 +400,7 @@ public sealed class SwaggerPlugin : PluginBase, IServerStartedPlugin, IHttpPlugi
|
||||
}
|
||||
|
||||
openApiProperty.Format = this.GetSchemaFormat(type);
|
||||
|
||||
openApiProperty.Description = description;
|
||||
return openApiProperty;
|
||||
}
|
||||
|
||||
@@ -485,7 +486,8 @@ public sealed class SwaggerPlugin : PluginBase, IServerStartedPlugin, IHttpPlugi
|
||||
var properties = new Dictionary<string, OpenApiProperty>();
|
||||
foreach (var propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
|
||||
{
|
||||
properties.Add(propertyInfo.Name, this.CreateProperty(propertyInfo.PropertyType));
|
||||
var description = propertyInfo.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
properties.Add(propertyInfo.Name, this.CreateProperty(propertyInfo.PropertyType, description));
|
||||
}
|
||||
schema.Properties = properties.Count == 0 ? default : properties;
|
||||
components.Schemas.TryAdd(this.GetSchemaName(type), schema);
|
||||
|
||||
Reference in New Issue
Block a user