@@ -124,5 +124,48 @@ public async Task When_generic_type_mapper_is_defined_then_it_is_called_and_the_
124
124
Assert . False ( schema . Definitions . ContainsKey ( "MyWrapperOfMyBar" ) ) ;
125
125
}
126
126
127
+ public class MyStringFoo
128
+ {
129
+ public MyWrapper < string > PropertyString { get ; set ; }
130
+
131
+ public MyWrapper < MyBar > PropertyMyBar { get ; set ; }
132
+ }
133
+
134
+ public class WithoutReferenceTypeMapper : ITypeMapper
135
+ {
136
+ public Type MappedType => typeof ( MyWrapper < > ) ;
137
+
138
+ public bool UseReference => false ;
139
+
140
+ public void GenerateSchema ( JsonSchema schema , TypeMapperContext context )
141
+ {
142
+ context . JsonSchemaGenerator . Generate ( schema , context . Type . GenericTypeArguments [ 0 ] , context . JsonSchemaResolver ) ;
143
+ }
144
+ }
145
+
146
+
147
+ [ Fact ]
148
+ public async Task When_generic_type_mapper_is_defined_then_it_is_called_and_the_use_reference_false_is_used ( )
149
+ {
150
+ // Act
151
+ var schema = NewtonsoftJsonSchemaGenerator . FromType < MyStringFoo > ( new NewtonsoftJsonSchemaGeneratorSettings
152
+ {
153
+ TypeMappers =
154
+ {
155
+ new WithoutReferenceTypeMapper ( )
156
+ }
157
+ } ) ;
158
+
159
+ // Assert
160
+ var json = schema . ToJson ( ) ;
161
+ Assert . False ( schema . Definitions . ContainsKey ( "string" ) ) ;
162
+ Assert . False ( schema . Definitions . ContainsKey ( "MyWrapperOfString" ) ) ;
163
+ Assert . True ( schema . Definitions . ContainsKey ( "MyBar" ) ) ;
164
+
165
+ Assert . Contains ( "$ref" , json ) ; // The $ref to MyBar should be present
166
+ // There should only be one $ref, which is to Bar, this is the case when the first and last index of "$ref" is the same
167
+ Assert . True ( json . IndexOf ( "$ref" , StringComparison . Ordinal ) == json . LastIndexOf ( "$ref" , StringComparison . Ordinal ) ) ;
168
+ }
169
+
127
170
}
128
171
}
0 commit comments