File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
Bss.Platform.Api.Documentation Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ public static IServiceCollection AddPlatformApiDocumentation(
32
32
{
33
33
x . SwaggerDoc ( "api" , new OpenApiInfo { Title = title } ) ;
34
34
x . SchemaFilter < XEnumNamesSchemaFilter > ( ) ;
35
+ x . SchemaFilter < ExcludeNullableFromRequiredSchemaFilter > ( ) ;
35
36
36
37
x . AddSecurityDefinition (
37
38
AuthorizationScheme ,
Original file line number Diff line number Diff line change
1
+ using Microsoft . OpenApi . Models ;
2
+
3
+ using Swashbuckle . AspNetCore . SwaggerGen ;
4
+
5
+ namespace Bss . Platform . Api . Documentation . SchemaFilters ;
6
+
7
+ /// <summary>
8
+ /// Exclude nullable property from required.
9
+ /// Needed for supporting correct front-end code generation by GenGen https://github.com/Luxoft/gengen
10
+ /// Additional to https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2036
11
+ /// </summary>
12
+ public class ExcludeNullableFromRequiredSchemaFilter : ISchemaFilter
13
+ {
14
+ public void Apply ( OpenApiSchema schema , SchemaFilterContext context )
15
+ {
16
+ if ( schema . Required . Count == 0 )
17
+ {
18
+ return ;
19
+ }
20
+
21
+ var nullableProperties = context . Type . GetProperties ( )
22
+ . Where ( x => ! x . IsNonNullableReferenceType ( ) )
23
+ . Select ( x => x . Name ) ;
24
+
25
+ var requiredNullableProperty = schema . Required
26
+ . Intersect ( nullableProperties , StringComparer . OrdinalIgnoreCase )
27
+ . ToArray ( ) ;
28
+
29
+ foreach ( var property in requiredNullableProperty )
30
+ {
31
+ schema . Required . Remove ( property ) ;
32
+ }
33
+ }
34
+ }
Original file line number Diff line number Diff line change 4
4
[ assembly: AssemblyCompany ( "Luxoft" ) ]
5
5
[ assembly: AssemblyCopyright ( "Copyright © Luxoft 2024" ) ]
6
6
7
- [ assembly: AssemblyVersion ( "1.5.7 .0" ) ]
8
- [ assembly: AssemblyFileVersion ( "1.5.7 .0" ) ]
9
- [ assembly: AssemblyInformationalVersion ( "1.5.7 .0" ) ]
7
+ [ assembly: AssemblyVersion ( "1.5.8 .0" ) ]
8
+ [ assembly: AssemblyFileVersion ( "1.5.8 .0" ) ]
9
+ [ assembly: AssemblyInformationalVersion ( "1.5.8 .0" ) ]
10
10
11
11
#if DEBUG
12
12
[ assembly: AssemblyConfiguration ( "Debug" ) ]
You can’t perform that action at this time.
0 commit comments