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