File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
main/java/io/github/stavshamir/springwolf/schemas
test/java/io/github/stavshamir/springwolf/schemas Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 12
12
import io .swagger .v3 .core .converter .ModelConverters ;
13
13
import io .swagger .v3 .oas .models .media .MapSchema ;
14
14
import io .swagger .v3 .oas .models .media .Schema ;
15
+ import io .swagger .v3 .oas .models .media .StringSchema ;
15
16
import lombok .extern .slf4j .Slf4j ;
16
17
import org .springframework .stereotype .Service ;
17
18
@@ -64,6 +65,11 @@ public String register(Class<?> type) {
64
65
Map <String , Schema > schemas = converter .readAll (type );
65
66
this .definitions .putAll (schemas );
66
67
68
+ if (schemas .size () == 0 && type .equals (String .class )) {
69
+ this .definitions .put ("String" , new StringSchema ());
70
+ return "String" ;
71
+ }
72
+
67
73
if (schemas .size () == 1 ) {
68
74
return new ArrayList <>(schemas .keySet ()).get (0 );
69
75
}
Original file line number Diff line number Diff line change 17
17
import java .util .Optional ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
+ import static org .junit .Assert .assertNotNull ;
20
21
21
22
public class DefaultSchemasServiceTest {
22
23
@@ -29,6 +30,16 @@ public class DefaultSchemasServiceTest {
29
30
objectMapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
30
31
}
31
32
33
+ @ Test
34
+ public void string () throws IOException , JSONException {
35
+ String modelName = schemasService .register (String .class );
36
+
37
+ assertThat (modelName )
38
+ .isEqualTo ("String" );
39
+
40
+ assertNotNull (schemasService .getDefinitions ().get (modelName ));
41
+ }
42
+
32
43
@ Test
33
44
public void simpleObject () throws IOException , JSONException {
34
45
String modelName = schemasService .register (SimpleFoo .class );
You can’t perform that action at this time.
0 commit comments