File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using OpenShock . Common . Models ;
1+ using Microsoft . AspNetCore . OpenApi ;
2+ using OpenShock . Common . Models ;
23using System . Text . Json . Serialization . Metadata ;
34
45namespace OpenShock . Common . OpenApi ;
56
6- public static class OpenApiSchemaReferenceIdUtil
7+ public static class OpenApiSchemaUtils
78{
89 private static readonly HashSet < Type > CollectionTypes =
910 [
@@ -67,7 +68,7 @@ private static bool IsSystemType(Type type)
6768 return type . Name + suffix ;
6869 }
6970
70- public static string ? GetFriendlyName ( Type type )
71+ private static string ? GetFriendlyName ( Type type )
7172 {
7273 if ( IsSystemType ( type ) ) return null ;
7374
@@ -76,8 +77,13 @@ private static bool IsSystemType(Type type)
7677
7778 return type . Name ;
7879 }
79- public static string ? GetFriendlyName ( JsonTypeInfo jsonTypeInfo )
80+
81+
82+ public static void ConfigureOptions ( OpenApiOptions options )
8083 {
81- return GetFriendlyName ( jsonTypeInfo . Type ) ;
84+ options . CreateSchemaReferenceId = ( jsonTypeInfo ) => GetFriendlyName ( jsonTypeInfo . Type ) ;
85+
86+ options . AddDocumentTransformer < OpenApiDocumentTransformer > ( ) ;
87+ options . AddOperationTransformer < OpenApiOperationTransformer > ( ) ;
8288 }
8389}
Original file line number Diff line number Diff line change @@ -119,20 +119,8 @@ public static IServiceCollection AddOpenShockServices(this IServiceCollection se
119119 x . JsonSerializerOptions . Converters . Add ( new CustomJsonStringEnumConverter ( ) ) ;
120120 } ) ;
121121
122- services . AddOpenApi ( "1" , options =>
123- {
124- options . CreateSchemaReferenceId = OpenApiSchemaReferenceIdUtil . GetFriendlyName ;
125-
126- options . AddDocumentTransformer < OpenApiDocumentTransformer > ( ) ;
127- options . AddOperationTransformer < OpenApiOperationTransformer > ( ) ;
128- } ) ;
129- services . AddOpenApi ( "2" , options =>
130- {
131- options . CreateSchemaReferenceId = OpenApiSchemaReferenceIdUtil . GetFriendlyName ;
132-
133- options . AddDocumentTransformer < OpenApiDocumentTransformer > ( ) ;
134- options . AddOperationTransformer < OpenApiOperationTransformer > ( ) ;
135- } ) ;
122+ services . AddOpenApi ( "1" , OpenApiSchemaUtils . ConfigureOptions ) ;
123+ services . AddOpenApi ( "2" , OpenApiSchemaUtils . ConfigureOptions ) ;
136124
137125 var apiVersioningBuilder = services . AddApiVersioning ( options =>
138126 {
You can’t perform that action at this time.
0 commit comments