15
15
import java .util .Map ;
16
16
import java .util .Objects ;
17
17
import java .util .Optional ;
18
+ import java .util .stream .Collectors ;
18
19
19
20
import static com .qdesrame .openapi .diff .utils .ChangedUtils .isChanged ;
20
21
@@ -51,8 +52,6 @@ public Optional<ChangedSchema> diff(HashSet<String> refSet, Components leftCompo
51
52
Map <String , Schema > leftProperties = null == left ? null : left .getProperties ();
52
53
Map <String , Schema > rightProperties = null == right ? null : right .getProperties ();
53
54
MapKeyDiff <String , Schema > propertyDiff = MapKeyDiff .diff (leftProperties , rightProperties );
54
- Map <String , Schema > increasedProp = propertyDiff .getIncreased ();
55
- Map <String , Schema > missingProp = propertyDiff .getMissing ();
56
55
57
56
for (String key : propertyDiff .getSharedKey ()) {
58
57
Optional <ChangedSchema > resultSchema = openApiDiff .getSchemaDiff ().diff (refSet , leftProperties .get (key ), rightProperties .get (key ), context );
@@ -61,11 +60,22 @@ public Optional<ChangedSchema> diff(HashSet<String> refSet, Components leftCompo
61
60
62
61
compareAdditionalProperties (refSet , left , right , context );
63
62
64
- changedSchema .getIncreasedProperties ().putAll (increasedProp );
65
- changedSchema .getMissingProperties ().putAll (missingProp );
63
+ changedSchema .getIncreasedProperties ().putAll (filterProperties ( propertyDiff . getIncreased (), context ) );
64
+ changedSchema .getMissingProperties ().putAll (filterProperties ( propertyDiff . getMissing (), context ) );
66
65
return isChanged (changedSchema );
67
66
}
68
67
68
+ private Map <String , Schema > filterProperties (Map <String , Schema > properties , DiffContext context ) {
69
+ return properties .entrySet ().stream ()
70
+ .filter (entry -> isPropertyApplicable (entry .getValue (), context ))
71
+ .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
72
+ }
73
+
74
+ private boolean isPropertyApplicable (Schema schema , DiffContext context ) {
75
+ return !(context .isResponse () && Boolean .TRUE .equals (schema .getWriteOnly ()))
76
+ && !(context .isRequest () && Boolean .TRUE .equals (schema .getReadOnly ()));
77
+ }
78
+
69
79
private void compareAdditionalProperties (HashSet <String > refSet , Schema leftSchema , Schema rightSchema , DiffContext context ) {
70
80
Object left = leftSchema .getAdditionalProperties ();
71
81
Object right = rightSchema .getAdditionalProperties ();
0 commit comments