@@ -64,13 +64,21 @@ public <T> Map<String, Object> schemas(Class<? extends T> cls) {
64
64
return this .schemas (cls , false );
65
65
}
66
66
67
+ private void replaceOneOfWithAnyOf (ObjectNode objectNode ) {
68
+ objectNode .findParents ("oneOf" ).forEach (jsonNode -> {
69
+ if (jsonNode instanceof ObjectNode oNode ) {
70
+ oNode .set ("anyOf" , oNode .remove ("oneOf" ));
71
+ }
72
+ });
73
+ }
74
+
67
75
public <T > Map <String , Object > schemas (Class <? extends T > cls , boolean arrayOf ) {
68
76
SchemaGeneratorConfigBuilder builder = new SchemaGeneratorConfigBuilder (
69
77
SchemaVersion .DRAFT_7 ,
70
78
OptionPreset .PLAIN_JSON
71
79
);
72
80
73
- this .build (builder ,true );
81
+ this .build (builder , true );
74
82
75
83
SchemaGeneratorConfig schemaGeneratorConfig = builder .build ();
76
84
@@ -80,8 +88,8 @@ public <T> Map<String, Object> schemas(Class<? extends T> cls, boolean arrayOf)
80
88
if (arrayOf ) {
81
89
objectNode .put ("type" , "array" );
82
90
}
83
- replaceAnyOfWithOneOf (objectNode );
84
- pullDocumentationAndDefaultFromOneOf (objectNode );
91
+ replaceOneOfWithAnyOf (objectNode );
92
+ pullDocumentationAndDefaultFromAnyOf (objectNode );
85
93
removeRequiredOnPropsWithDefaults (objectNode );
86
94
87
95
return JacksonMapper .toMap (objectNode );
@@ -111,23 +119,15 @@ private void removeRequiredOnPropsWithDefaults(ObjectNode objectNode) {
111
119
});
112
120
}
113
121
114
- private void replaceAnyOfWithOneOf (ObjectNode objectNode ) {
115
- objectNode .findParents ("anyOf" ).forEach (jsonNode -> {
116
- if (jsonNode instanceof ObjectNode oNode ) {
117
- oNode .set ("oneOf" , oNode .remove ("anyOf" ));
118
- }
119
- });
120
- }
121
-
122
- // This hack exists because for Property we generate a oneOf for properties that are not strings.
123
- // By default, the 'default' is in each oneOf which Monaco editor didn't take into account.
124
- // So, we pull off the 'default' from any of the oneOf to the parent.
122
+ // This hack exists because for Property we generate a anyOf for properties that are not strings.
123
+ // By default, the 'default' is in each anyOf which Monaco editor didn't take into account.
124
+ // So, we pull off the 'default' from any of the anyOf to the parent.
125
125
// same thing for documentation fields: 'title', 'description', '$deprecated'
126
- private void pullDocumentationAndDefaultFromOneOf (ObjectNode objectNode ) {
127
- objectNode .findParents ("oneOf " ).forEach (jsonNode -> {
126
+ private void pullDocumentationAndDefaultFromAnyOf (ObjectNode objectNode ) {
127
+ objectNode .findParents ("anyOf " ).forEach (jsonNode -> {
128
128
if (jsonNode instanceof ObjectNode oNode ) {
129
- JsonNode oneOf = oNode .get ("oneOf " );
130
- if (oneOf instanceof ArrayNode arrayNode ) {
129
+ JsonNode anyOf = oNode .get ("anyOf " );
130
+ if (anyOf instanceof ArrayNode arrayNode ) {
131
131
Iterator <JsonNode > it = arrayNode .elements ();
132
132
var nodesToPullUp = new HashMap <String , Optional <JsonNode >>(Map .ofEntries (
133
133
Map .entry ("default" , Optional .empty ()),
@@ -287,11 +287,11 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
287
287
TypeContext context = target .getContext ();
288
288
Class <?> erasedType = javaType .getTypeParameters ().getFirst ().getErasedType ();
289
289
290
- if (String .class .isAssignableFrom (erasedType )) {
290
+ if (String .class .isAssignableFrom (erasedType )) {
291
291
return List .of (
292
292
context .resolve (String .class )
293
293
);
294
- } else if (Object .class .equals (erasedType )) {
294
+ } else if (Object .class .equals (erasedType )) {
295
295
return List .of (
296
296
context .resolve (Object .class )
297
297
);
@@ -401,7 +401,7 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
401
401
// handle deprecated tasks
402
402
Schema schema = scope .getType ().getErasedType ().getAnnotation (Schema .class );
403
403
Deprecated deprecated = scope .getType ().getErasedType ().getAnnotation (Deprecated .class );
404
- if ((schema != null && schema .deprecated ()) || deprecated != null ) {
404
+ if ((schema != null && schema .deprecated ()) || deprecated != null ) {
405
405
collectedTypeAttributes .put ("$deprecated" , "true" );
406
406
}
407
407
});
@@ -426,7 +426,7 @@ public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, Sch
426
426
});
427
427
428
428
// Subtype resolver for all plugins
429
- if (builder .build ().getSchemaVersion () != SchemaVersion .DRAFT_2019_09 ) {
429
+ if (builder .build ().getSchemaVersion () != SchemaVersion .DRAFT_2019_09 ) {
430
430
builder .forTypesInGeneral ()
431
431
.withSubtypeResolver ((declaredType , context ) -> {
432
432
TypeContext typeContext = context .getTypeContext ();
@@ -615,7 +615,7 @@ private boolean defaultInAllOf(JsonNode property) {
615
615
if (property .has ("allOf" )) {
616
616
for (Iterator <JsonNode > it = property .get ("allOf" ).elements (); it .hasNext (); ) {
617
617
JsonNode child = it .next ();
618
- if (child .has ("default" )) {
618
+ if (child .has ("default" )) {
619
619
return true ;
620
620
}
621
621
}
@@ -629,7 +629,7 @@ protected <T> Map<String, Object> generate(Class<? extends T> cls, @Nullable Cla
629
629
OptionPreset .PLAIN_JSON
630
630
);
631
631
632
- this .build (builder ,false );
632
+ this .build (builder , false );
633
633
634
634
// we don't return base properties unless specified with @PluginProperty
635
635
builder
@@ -641,8 +641,8 @@ protected <T> Map<String, Object> generate(Class<? extends T> cls, @Nullable Cla
641
641
SchemaGenerator generator = new SchemaGenerator (schemaGeneratorConfig );
642
642
try {
643
643
ObjectNode objectNode = generator .generateSchema (cls );
644
- replaceAnyOfWithOneOf (objectNode );
645
- pullDocumentationAndDefaultFromOneOf (objectNode );
644
+ replaceOneOfWithAnyOf (objectNode );
645
+ pullDocumentationAndDefaultFromAnyOf (objectNode );
646
646
removeRequiredOnPropsWithDefaults (objectNode );
647
647
648
648
return JacksonMapper .toMap (extractMainRef (objectNode ));
@@ -753,7 +753,8 @@ private Object defaultValue(Object instance, Class<?> cls, String fieldName) {
753
753
754
754
field .setAccessible (true );
755
755
return field .invoke (instance );
756
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored ) {
756
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException |
757
+ IllegalArgumentException ignored ) {
757
758
758
759
}
759
760
@@ -762,7 +763,8 @@ private Object defaultValue(Object instance, Class<?> cls, String fieldName) {
762
763
763
764
field .setAccessible (true );
764
765
return field .invoke (instance );
765
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored ) {
766
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException |
767
+ IllegalArgumentException ignored ) {
766
768
767
769
}
768
770
0 commit comments