1515import java .util .Map ;
1616import java .util .Objects ;
1717import java .util .Optional ;
18+ import java .util .stream .Collectors ;
1819
1920import static com .qdesrame .openapi .diff .utils .ChangedUtils .isChanged ;
2021
@@ -51,8 +52,6 @@ public Optional<ChangedSchema> diff(HashSet<String> refSet, Components leftCompo
5152 Map <String , Schema > leftProperties = null == left ? null : left .getProperties ();
5253 Map <String , Schema > rightProperties = null == right ? null : right .getProperties ();
5354 MapKeyDiff <String , Schema > propertyDiff = MapKeyDiff .diff (leftProperties , rightProperties );
54- Map <String , Schema > increasedProp = propertyDiff .getIncreased ();
55- Map <String , Schema > missingProp = propertyDiff .getMissing ();
5655
5756 for (String key : propertyDiff .getSharedKey ()) {
5857 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
6160
6261 compareAdditionalProperties (refSet , left , right , context );
6362
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 ) );
6665 return isChanged (changedSchema );
6766 }
6867
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+
6979 private void compareAdditionalProperties (HashSet <String > refSet , Schema leftSchema , Schema rightSchema , DiffContext context ) {
7080 Object left = leftSchema .getAdditionalProperties ();
7181 Object right = rightSchema .getAdditionalProperties ();
0 commit comments