11package com .qdesrame .openapi .diff .compare ;
22
3- import static java .util .Optional .ofNullable ;
4-
53import com .qdesrame .openapi .diff .compare .schemadiffresult .ArraySchemaDiffResult ;
64import com .qdesrame .openapi .diff .compare .schemadiffresult .ComposedSchemaDiffResult ;
75import com .qdesrame .openapi .diff .compare .schemadiffresult .SchemaDiffResult ;
86import com .qdesrame .openapi .diff .model .ChangedSchema ;
97import com .qdesrame .openapi .diff .model .DiffContext ;
108import com .qdesrame .openapi .diff .utils .RefPointer ;
119import com .qdesrame .openapi .diff .utils .RefType ;
10+
11+ import java .util .ArrayList ;
12+ import java .util .HashSet ;
13+ import java .util .LinkedHashMap ;
14+ import java .util .List ;
15+ import java .util .Map ;
16+ import java .util .Objects ;
17+ import java .util .Optional ;
18+
1219import io .swagger .v3 .oas .models .Components ;
20+ import io .swagger .v3 .oas .models .ExternalDocumentation ;
1321import io .swagger .v3 .oas .models .media .ArraySchema ;
1422import io .swagger .v3 .oas .models .media .ComposedSchema ;
23+ import io .swagger .v3 .oas .models .media .Discriminator ;
1524import io .swagger .v3 .oas .models .media .Schema ;
16- import java .util .*;
25+ import io .swagger .v3 .oas .models .media .XML ;
26+
27+ import static java .util .Optional .ofNullable ;
1728
1829public class SchemaDiff extends ReferenceDiffCache <Schema , ChangedSchema > {
1930
@@ -87,10 +98,9 @@ protected static Schema resolveComposedSchema(Components components, Schema sche
8798 protected static Schema addSchema (Schema <?> schema , Schema <?> fromSchema ) {
8899 if (fromSchema .getProperties () != null ) {
89100 if (schema .getProperties () == null ) {
90- schema .setProperties (fromSchema .getProperties ());
91- } else {
92- schema .getProperties ().putAll (fromSchema .getProperties ());
101+ schema .setProperties (new LinkedHashMap <>());
93102 }
103+ schema .getProperties ().putAll (fromSchema .getProperties ());
94104 }
95105
96106 if (fromSchema .getRequired () != null ) {
@@ -100,7 +110,165 @@ protected static Schema addSchema(Schema<?> schema, Schema<?> fromSchema) {
100110 schema .getRequired ().addAll (fromSchema .getRequired ());
101111 }
102112 }
103- // TODO copy other things from fromSchema
113+
114+ if (fromSchema .getReadOnly () != null ) {
115+ schema .setReadOnly (fromSchema .getReadOnly ());
116+ }
117+ if (fromSchema .getWriteOnly () != null ) {
118+ schema .setWriteOnly (fromSchema .getWriteOnly ());
119+ }
120+ if (fromSchema .getDeprecated () != null ) {
121+ schema .setDeprecated (fromSchema .getDeprecated ());
122+ }
123+ if (fromSchema .getExclusiveMaximum () != null ) {
124+ schema .setExclusiveMaximum (fromSchema .getExclusiveMaximum ());
125+ }
126+ if (fromSchema .getExclusiveMinimum () != null ) {
127+ schema .setExclusiveMinimum (fromSchema .getExclusiveMinimum ());
128+ }
129+ if (fromSchema .getNullable () != null ) {
130+ schema .setNullable (fromSchema .getNullable ());
131+ }
132+ if (fromSchema .getUniqueItems () != null ) {
133+ schema .setUniqueItems (fromSchema .getUniqueItems ());
134+ }
135+ if (fromSchema .getDescription () != null ) {
136+ schema .setDescription (fromSchema .getDescription ());
137+ }
138+ if (fromSchema .getFormat () != null ) {
139+ schema .setFormat (fromSchema .getFormat ());
140+ }
141+ if (fromSchema .getType () != null ) {
142+ schema .setType (fromSchema .getType ());
143+ }
144+ if (fromSchema .getEnum () != null ) {
145+ if (schema .getEnum () == null ) {
146+ schema .setEnum (new ArrayList <>());
147+ }
148+ //noinspection unchecked
149+ schema .getEnum ().addAll ((List ) fromSchema .getEnum ());
150+ }
151+ if (fromSchema .getExtensions () != null ) {
152+ if (schema .getExtensions () == null ) {
153+ schema .setExtensions (new LinkedHashMap <>());
154+ }
155+ schema .getExtensions ().putAll (fromSchema .getExtensions ());
156+ }
157+ if (fromSchema .getDiscriminator () != null ) {
158+ if (schema .getDiscriminator () == null ) {
159+ schema .setDiscriminator (new Discriminator ());
160+ }
161+ final Discriminator discriminator = schema .getDiscriminator ();
162+ final Discriminator fromDiscriminator = fromSchema .getDiscriminator ();
163+ if (fromDiscriminator .getPropertyName () != null ) {
164+ discriminator .setPropertyName (fromDiscriminator .getPropertyName ());
165+ }
166+ if (fromDiscriminator .getMapping () != null ) {
167+ if (discriminator .getMapping () == null ) {
168+ discriminator .setMapping (new LinkedHashMap <>());
169+ }
170+ discriminator .getMapping ().putAll (fromDiscriminator .getMapping ());
171+ }
172+ }
173+ if (fromSchema .getTitle () != null ) {
174+ schema .setTitle (fromSchema .getTitle ());
175+ }
176+ if (fromSchema .getName () != null ) {
177+ schema .setName (fromSchema .getName ());
178+ }
179+ if (fromSchema .getAdditionalProperties () != null ) {
180+ schema .setAdditionalProperties (fromSchema .getAdditionalProperties ());
181+ }
182+ if (fromSchema .getDefault () != null ) {
183+ schema .setDefault (fromSchema .getDefault ());
184+ }
185+ if (fromSchema .getExample () != null ) {
186+ schema .setExample (fromSchema .getExample ());
187+ }
188+ if (fromSchema .getExternalDocs () != null ) {
189+ if (schema .getExternalDocs () == null ) {
190+ schema .setExternalDocs (new ExternalDocumentation ());
191+ }
192+ final ExternalDocumentation externalDocs = schema .getExternalDocs ();
193+ final ExternalDocumentation fromExternalDocs = fromSchema .getExternalDocs ();
194+ if (fromExternalDocs .getDescription () != null ) {
195+ externalDocs .setDescription (fromExternalDocs .getDescription ());
196+ }
197+ if (fromExternalDocs .getExtensions () != null ) {
198+ if (externalDocs .getExtensions () == null ) {
199+ externalDocs .setExtensions (new LinkedHashMap <>());
200+ }
201+ externalDocs .getExtensions ().putAll (fromExternalDocs .getExtensions ());
202+ }
203+ if (fromExternalDocs .getUrl () != null ) {
204+ externalDocs .setUrl (fromExternalDocs .getUrl ());
205+ }
206+ }
207+ if (fromSchema .getMaximum () != null ) {
208+ schema .setMaximum (fromSchema .getMaximum ());
209+ }
210+ if (fromSchema .getMinimum () != null ) {
211+ schema .setMinimum (fromSchema .getMinimum ());
212+ }
213+ if (fromSchema .getMaxItems () != null ) {
214+ schema .setMaxItems (fromSchema .getMaxItems ());
215+ }
216+ if (fromSchema .getMinItems () != null ) {
217+ schema .setMinItems (fromSchema .getMinItems ());
218+ }
219+ if (fromSchema .getMaxProperties () != null ) {
220+ schema .setMaxProperties (fromSchema .getMaxProperties ());
221+ }
222+ if (fromSchema .getMinProperties () != null ) {
223+ schema .setMinProperties (fromSchema .getMinProperties ());
224+ }
225+ if (fromSchema .getMaxLength () != null ) {
226+ schema .setMaxLength (fromSchema .getMaxLength ());
227+ }
228+ if (fromSchema .getMinLength () != null ) {
229+ schema .setMinLength (fromSchema .getMinLength ());
230+ }
231+ if (fromSchema .getMultipleOf () != null ) {
232+ schema .setMultipleOf (fromSchema .getMultipleOf ());
233+ }
234+ if (fromSchema .getNot () != null ) {
235+ if (schema .getNot () == null ) {
236+ schema .setNot (addSchema (new Schema (), fromSchema .getNot ()));
237+ } else {
238+ addSchema (schema .getNot (), fromSchema .getNot ());
239+ }
240+ }
241+ if (fromSchema .getPattern () != null ) {
242+ schema .setPattern (fromSchema .getPattern ());
243+ }
244+ if (fromSchema .getXml () != null ) {
245+ if (schema .getXml () == null ) {
246+ schema .setXml (new XML ());
247+ }
248+ final XML xml = schema .getXml ();
249+ final XML fromXml = fromSchema .getXml ();
250+ if (fromXml .getAttribute () != null ) {
251+ xml .setAttribute (fromXml .getAttribute ());
252+ }
253+ if (fromXml .getName () != null ) {
254+ xml .setName (fromXml .getName ());
255+ }
256+ if (fromXml .getNamespace () != null ) {
257+ xml .setNamespace (fromXml .getNamespace ());
258+ }
259+ if (fromXml .getExtensions () != null ) {
260+ if (xml .getExtensions () == null ) {
261+ xml .setExtensions (new LinkedHashMap <>());
262+ }
263+ xml .getExtensions ().putAll (fromXml .getExtensions ());
264+ }
265+ if (fromXml .getPrefix () != null ) {
266+ xml .setPrefix (fromXml .getPrefix ());
267+ }
268+ if (fromXml .getWrapped () != null ) {
269+ xml .setWrapped (fromXml .getWrapped ());
270+ }
271+ }
104272 return schema ;
105273 }
106274
0 commit comments