|
2 | 2 |
|
3 | 3 | import io.swagger.models.*; |
4 | 4 | import io.swagger.models.properties.ArrayProperty; |
| 5 | +import io.swagger.models.properties.ComposedProperty; |
5 | 6 | import io.swagger.models.properties.MapProperty; |
6 | 7 | import io.swagger.models.properties.ObjectProperty; |
7 | 8 | import io.swagger.models.properties.Property; |
|
15 | 16 | import org.slf4j.LoggerFactory; |
16 | 17 |
|
17 | 18 | import java.net.URI; |
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.Collection; |
18 | 21 | import java.util.LinkedHashMap; |
19 | 22 | import java.util.List; |
20 | 23 | import java.util.Map; |
@@ -131,26 +134,7 @@ public String processRefToExternalDefinition(String $ref, RefFormat refFormat) { |
131 | 134 | processDiscriminator(discriminator,modelImpl.getProperties(), file); |
132 | 135 | } |
133 | 136 |
|
134 | | - Property additionalProperties = modelImpl.getAdditionalProperties(); |
135 | | - if (additionalProperties != null) { |
136 | | - if (additionalProperties instanceof RefProperty) { |
137 | | - processRefProperty(((RefProperty) additionalProperties), file); |
138 | | - } else if (additionalProperties instanceof ArrayProperty) { |
139 | | - ArrayProperty arrayProp = (ArrayProperty) additionalProperties; |
140 | | - if (arrayProp.getItems() instanceof RefProperty) { |
141 | | - processRefProperty((RefProperty) arrayProp.getItems(), file); |
142 | | - } |
143 | | - } else if (additionalProperties instanceof MapProperty) { |
144 | | - MapProperty mapProp = (MapProperty) additionalProperties; |
145 | | - if (mapProp.getAdditionalProperties() instanceof RefProperty) { |
146 | | - processRefProperty((RefProperty) mapProp.getAdditionalProperties(), file); |
147 | | - } else if (mapProp.getAdditionalProperties() instanceof ArrayProperty && |
148 | | - ((ArrayProperty) mapProp.getAdditionalProperties()).getItems() instanceof RefProperty) { |
149 | | - processRefProperty((RefProperty) ((ArrayProperty) mapProp.getAdditionalProperties()).getItems(), file); |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - } |
| 137 | + processProperties(Arrays.asList(modelImpl.getAdditionalProperties()), file); |
154 | 138 | } |
155 | 139 | if (model instanceof ArrayModel && ((ArrayModel) model).getItems() instanceof RefProperty) { |
156 | 140 | processRefProperty((RefProperty) ((ArrayModel) model).getItems(), file); |
@@ -233,38 +217,27 @@ private void processDiscriminator(String discriminator, Map<String, Property> pr |
233 | 217 | } |
234 | 218 |
|
235 | 219 | private void processProperties(final Map<String, Property> subProps, final String file) { |
236 | | - if (subProps == null || 0 == subProps.entrySet().size() ) { |
| 220 | + if (subProps == null || subProps.isEmpty()) { |
237 | 221 | return; |
238 | 222 | } |
239 | | - for (Map.Entry<String, Property> prop : subProps.entrySet()) { |
240 | | - if (prop.getValue() instanceof RefProperty) { |
241 | | - processRefProperty((RefProperty) prop.getValue(), file); |
242 | | - } else if (prop.getValue() instanceof ArrayProperty) { |
243 | | - ArrayProperty arrayProp = (ArrayProperty) prop.getValue(); |
244 | | - if (arrayProp.getItems() instanceof RefProperty) { |
245 | | - processRefProperty((RefProperty) arrayProp.getItems(), file); |
246 | | - } |
247 | | - if (arrayProp.getItems() != null){ |
248 | | - if (arrayProp.getItems() instanceof ObjectProperty) { |
249 | | - ObjectProperty objectProperty = (ObjectProperty) arrayProp.getItems(); |
250 | | - processProperties(objectProperty.getProperties(), file); |
251 | | - } |
252 | | - } |
253 | | - } else if (prop.getValue() instanceof MapProperty) { |
254 | | - MapProperty mapProp = (MapProperty) prop.getValue(); |
255 | | - if (mapProp.getAdditionalProperties() instanceof RefProperty) { |
256 | | - processRefProperty((RefProperty) mapProp.getAdditionalProperties(), file); |
257 | | - } else if (mapProp.getAdditionalProperties() instanceof ArrayProperty && |
258 | | - ((ArrayProperty) mapProp.getAdditionalProperties()).getItems() instanceof RefProperty) { |
259 | | - processRefProperty((RefProperty) ((ArrayProperty) mapProp.getAdditionalProperties()).getItems(), |
260 | | - file); |
261 | | - } |
262 | | - } |
263 | | - else if (prop.getValue() instanceof ObjectProperty){ |
264 | | - ObjectProperty objProp = (ObjectProperty) prop.getValue(); |
265 | | - if(objProp.getProperties() != null ){ |
266 | | - processProperties(objProp.getProperties(),file); |
267 | | - } |
| 223 | + processProperties(subProps.values(), file); |
| 224 | + } |
| 225 | + |
| 226 | + private void processProperties(final Collection<Property> subProps, final String file) { |
| 227 | + if (subProps == null || subProps.isEmpty()) { |
| 228 | + return; |
| 229 | + } |
| 230 | + for (Property prop : subProps) { |
| 231 | + if (prop instanceof RefProperty) { |
| 232 | + processRefProperty((RefProperty) prop, file); |
| 233 | + } else if (prop instanceof ArrayProperty) { |
| 234 | + processProperties(Arrays.asList(((ArrayProperty) prop).getItems()), file); |
| 235 | + } else if (prop instanceof MapProperty) { |
| 236 | + processProperties(Arrays.asList(((MapProperty) prop).getAdditionalProperties()), file); |
| 237 | + } else if (prop instanceof ObjectProperty) { |
| 238 | + processProperties(((ObjectProperty) prop).getProperties(), file); |
| 239 | + } else if (prop instanceof ComposedProperty) { |
| 240 | + processProperties(((ComposedProperty) prop).getAllOf(), file); |
268 | 241 | } |
269 | 242 | } |
270 | 243 | } |
|
0 commit comments