|
34 | 34 | import java.util.LinkedHashSet;
|
35 | 35 | import java.util.List;
|
36 | 36 | import java.util.Map;
|
| 37 | +import java.util.Map.Entry; |
37 | 38 | import java.util.Optional;
|
38 | 39 | import java.util.Set;
|
39 | 40 |
|
|
45 | 46 | import io.swagger.v3.core.converter.ResolvedSchema;
|
46 | 47 | import io.swagger.v3.core.util.AnnotationsUtils;
|
47 | 48 | import io.swagger.v3.oas.annotations.Hidden;
|
| 49 | +import io.swagger.v3.oas.annotations.media.Encoding; |
48 | 50 | import io.swagger.v3.oas.annotations.media.ExampleObject;
|
49 | 51 | import io.swagger.v3.oas.annotations.media.SchemaProperty;
|
50 | 52 | import io.swagger.v3.oas.models.Components;
|
@@ -142,7 +144,7 @@ public static Schema extractSchema(Components components, Type returnType, JsonV
|
142 | 144 | componentSchemas.putAll(schemaMap);
|
143 | 145 | }
|
144 | 146 | else
|
145 |
| - for (Map.Entry<String, Schema> entry : schemaMap.entrySet()) { |
| 147 | + for (Entry<String, Schema> entry : schemaMap.entrySet()) { |
146 | 148 | // If we've seen this schema before but find later it should be polymorphic,
|
147 | 149 | // replace the existing schema with this richer version.
|
148 | 150 | Schema existingSchema = componentSchemas.get(entry.getKey());
|
@@ -200,7 +202,7 @@ public static Optional<Content> getContent(io.swagger.v3.oas.annotations.media.C
|
200 | 202 | ExampleObject[] examples = annotationContent.examples();
|
201 | 203 | setExamples(mediaType, examples);
|
202 | 204 | addExtension(annotationContent, mediaType, openapi31);
|
203 |
| - io.swagger.v3.oas.annotations.media.Encoding[] encodings = annotationContent.encoding(); |
| 205 | + Encoding[] encodings = annotationContent.encoding(); |
204 | 206 | addEncodingToMediaType(jsonViewAnnotation, mediaType, encodings, openapi31);
|
205 | 207 | if (StringUtils.isNotBlank(annotationContent.mediaType())) {
|
206 | 208 | content.addMediaType(annotationContent.mediaType(), mediaType);
|
@@ -230,8 +232,11 @@ public static void mergeSchema(Content existingContent, Schema<?> schemaN, Strin
|
230 | 232 | if (!schemaN.equals(mediaType.getSchema())) {
|
231 | 233 | // Merge the two schemas for the same mediaType
|
232 | 234 | Schema firstSchema = mediaType.getSchema();
|
233 |
| - ComposedSchema schemaObject; |
234 |
| - if (firstSchema instanceof ComposedSchema) { |
| 235 | + Schema<?> schemaObject = null; |
| 236 | + if (firstSchema == null) { |
| 237 | + schemaObject = schemaN; |
| 238 | + } |
| 239 | + else if (firstSchema instanceof ComposedSchema) { |
235 | 240 | schemaObject = (ComposedSchema) firstSchema;
|
236 | 241 | List<Schema> listOneOf = schemaObject.getOneOf();
|
237 | 242 | if (!CollectionUtils.isEmpty(listOneOf) && !listOneOf.contains(schemaN))
|
@@ -311,8 +316,8 @@ public static void removeAnnotationsToIgnore(Class<?>... classes) {
|
311 | 316 | * @param openapi31 the openapi 31
|
312 | 317 | */
|
313 | 318 | private static void addEncodingToMediaType(JsonView jsonViewAnnotation, MediaType mediaType,
|
314 |
| - io.swagger.v3.oas.annotations.media.Encoding[] encodings, boolean openapi31) { |
315 |
| - for (io.swagger.v3.oas.annotations.media.Encoding encoding : encodings) { |
| 319 | + Encoding[] encodings, boolean openapi31) { |
| 320 | + for (Encoding encoding : encodings) { |
316 | 321 | addEncodingToMediaType(mediaType, encoding, jsonViewAnnotation, openapi31);
|
317 | 322 | }
|
318 | 323 | }
|
|
0 commit comments