@@ -60,6 +60,7 @@ class AllAnyOneOfSchemaRule extends SchemaRule {
60
60
}
61
61
62
62
private static final String REF = "$ref" ;
63
+ private static final String TITLE = "title" ;
63
64
private static final String PATTERN = "pattern" ;
64
65
65
66
private enum Format {
@@ -154,6 +155,16 @@ public JType apply(
154
155
&& allOfTypes .isEmpty ()
155
156
&& refType .isPresent ()) {
156
157
javaType = refType .get ();
158
+ } else if (!schemaNode .has ("properties" )
159
+ && oneOfTypes .isEmpty ()
160
+ && allOfTypes .size () == 1
161
+ && refType .isEmpty ()) {
162
+ javaType = allOfTypes .get (0 ).getType ();
163
+ } else if (!schemaNode .has ("properties" )
164
+ && oneOfTypes .size () == 1
165
+ && allOfTypes .isEmpty ()
166
+ && refType .isEmpty ()) {
167
+ javaType = oneOfTypes .get (0 ).getType ();
157
168
} else {
158
169
JPackage container = generatableType .getPackage ();
159
170
javaType = ruleFactory .getTypeRule ().apply (nodeName , schemaNode , parent , container , schema );
@@ -469,6 +480,9 @@ private void unionType(
469
480
Collection <JTypeWrapper > types ) {
470
481
if (schemaNode .has (prefix )) {
471
482
ArrayNode array = (ArrayNode ) schemaNode .get (prefix );
483
+ if (schemaNode .has (TITLE )) {
484
+ nodeName = schemaNode .get (TITLE ).asText ();
485
+ }
472
486
int i = 0 ;
473
487
for (JsonNode oneOf : array ) {
474
488
if (!ignoreNode (oneOf )) {
@@ -491,6 +505,23 @@ private void unionType(
491
505
}
492
506
493
507
private static boolean ignoreNode (JsonNode node ) {
508
+ return allRequired (node ) || allRemoveProperties (node );
509
+ }
510
+
511
+ private static boolean allRemoveProperties (JsonNode node ) {
512
+ if (node .size () == 1 && node .has ("properties" )) {
513
+ JsonNode propsNode = node .get ("properties" );
514
+ for (JsonNode propNode : propsNode ) {
515
+ if (!propNode .isBoolean () || propNode .asBoolean ()) {
516
+ return false ;
517
+ }
518
+ }
519
+ return true ;
520
+ }
521
+ return false ;
522
+ }
523
+
524
+ private static boolean allRequired (JsonNode node ) {
494
525
return node .size () == 1 && node .has ("required" );
495
526
}
496
527
@@ -514,7 +545,7 @@ private Optional<JType> refType(
514
545
schema .isGenerated ()
515
546
? schema .getJavaType ()
516
547
: apply (
517
- nameFromRef (ref , nodeName ),
548
+ nameFromRef (ref , nodeName , schemaNode ),
518
549
schema .getContent (),
519
550
parent ,
520
551
generatableType ,
@@ -556,7 +587,10 @@ private String pattern(JsonNode node) {
556
587
return format != null ? format .pattern () : getFromNode (node , PATTERN );
557
588
}
558
589
559
- private String nameFromRef (String ref , String nodeName ) {
590
+ private String nameFromRef (String ref , String nodeName , JsonNode schemaNode ) {
591
+ if (schemaNode .has (TITLE )) {
592
+ return schemaNode .get (TITLE ).asText ();
593
+ }
560
594
if ("#" .equals (ref )) {
561
595
return nodeName ;
562
596
}
0 commit comments