@@ -11,7 +11,13 @@ namespace Simplify.Web.Swagger
1111 /// </summary>
1212 public class SimplifyWebDocumentFilter : IDocumentFilter
1313 {
14- private const string VersionEndPoint = "/version" ;
14+ // private const string VersionEndPoint = "/version";
15+
16+ private static IList < string > RemovePrefixes = new List < string >
17+ {
18+ "Controllers." ,
19+ "Api.v1."
20+ } ;
1521
1622 /// <summary>
1723 /// Applies current filter
@@ -47,18 +53,23 @@ private static OpenApiPathItem CreateOpenApiPathItems(HttpMethod method, string
4753 {
4854 var pathItem = new OpenApiPathItem ( ) ;
4955
50- pathItem . AddOperation ( HttpMethodToOperationType ( method ) , CreateOperation ( ) ) ;
56+ pathItem . AddOperation ( HttpMethodToOperationType ( method ) , CreateOperation ( item ) ) ;
5157
5258 return pathItem ;
5359 }
5460
55- private static OpenApiOperation CreateOperation ( )
61+ private static OpenApiOperation CreateOperation ( IControllerMetaData item )
5662 {
63+ // TODO
64+
5765 var operation = new OpenApiOperation
5866 {
5967 } ;
6068
61- // operation.Responses.Add("200", response);
69+ operation . Tags . Add ( new OpenApiTag
70+ {
71+ Name = FormatOperationName ( item )
72+ } ) ;
6273
6374 return operation ;
6475 }
@@ -75,17 +86,40 @@ private static OperationType HttpMethodToOperationType(HttpMethod method) =>
7586 _ => OperationType . Get
7687 } ;
7788
78- // private KeyValuePair<string, OpenApiResponse> CreateResponse()
79- // {
80- // var response = new OpenApiResponse
81- // {
82- // Description = "Success"
83- // };
89+ // TODO
90+ private static KeyValuePair < string , OpenApiResponse > CreateResponse ( )
91+ {
92+ var response = new OpenApiResponse
93+ {
94+ } ;
8495
85- // return response;
86- // }
96+ return new KeyValuePair < string , OpenApiResponse > ( "" , response ) ;
97+ }
8798
8899 private static string FormatControllerName ( string route , HttpMethod method , bool needToAddPostfix ) =>
89100 needToAddPostfix ? $ "{ route } ({ method } )" : route ;
101+
102+ private static string ? FormatOperationName ( IControllerMetaData item ) =>
103+ item . ControllerType . FullName != null ? FormatOperationName ( item . ControllerType . FullName ) : null ;
104+
105+ private static string FormatOperationName ( string str )
106+ {
107+ foreach ( var prefix in RemovePrefixes )
108+ {
109+ var prefixIndex = str . IndexOf ( prefix ) ;
110+
111+ if ( prefixIndex == - 1 )
112+ continue ;
113+
114+ str = str . Substring ( prefixIndex + prefix . Length ) ;
115+ }
116+
117+ str = str . Replace ( "." , "/" ) ;
118+
119+ if ( str . EndsWith ( "Controller" ) )
120+ str = str . Substring ( 0 , str . LastIndexOf ( "Controller" ) ) ;
121+
122+ return str ;
123+ }
90124 }
91125}
0 commit comments