Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c2e36c
commit 6917fbb
Showing
11 changed files
with
138 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Namotion.Reflection; | ||
using NJsonSchema.Generation; | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Colder.Api.Abstractions; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class EnumSchemaProcessor : ISchemaProcessor | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="context"></param> | ||
public void Process(SchemaProcessorContext context) | ||
{ | ||
var type = context.ContextualType.Type; | ||
if (!type.IsEnum) | ||
{ | ||
return; | ||
} | ||
|
||
var sb = new StringBuilder(); | ||
sb.AppendLine(type.GetXmlDocsSummary()); | ||
|
||
var members = type.GetMembers(); | ||
var schema = context.Schema; | ||
for (var i = 0; i < schema.Enumeration.Count; i++) | ||
{ | ||
var item = schema.Enumeration.ElementAt(i); | ||
var enumName = Enum.GetName(type, item); | ||
|
||
var summary = members.FirstOrDefault(a => a.Name == enumName) | ||
.GetXmlDocsSummary(); | ||
|
||
sb.AppendLine($"{item} = {summary}"); | ||
} | ||
|
||
schema.Description = sb.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Colder.Api.Abstractions/Options/SwaggerDocumentOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace Colder.Api.Abstractions.Options; | ||
|
||
/// <summary> | ||
/// Swagger 文档配置。 | ||
/// </summary> | ||
public class SwaggerDocumentOptions | ||
{ | ||
/// <summary> | ||
/// 获取或设置 Swagger 标题。 | ||
/// </summary> | ||
public string Title { get; set; } | ||
|
||
/// <summary> | ||
/// 获取或设置文档名称。 | ||
/// </summary> | ||
public string DocumentName { get; set; } | ||
|
||
/// <summary> | ||
/// 获取或设置 API 分组名称。 | ||
/// </summary> | ||
public string[] ApiGroupNames { get; set; } = Array.Empty<string>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters