|
34 | 34 | import io.swagger.v3.parser.ResolverCache;
|
35 | 35 | import io.swagger.v3.parser.models.RefFormat;
|
36 | 36 | import io.swagger.v3.parser.models.RefType;
|
| 37 | + |
37 | 38 | import org.apache.commons.io.FilenameUtils;
|
38 | 39 | import org.apache.commons.lang3.StringUtils;
|
39 | 40 | import org.slf4j.LoggerFactory;
|
@@ -325,71 +326,75 @@ public PathItem processRefToExternalPathItem(String $ref, RefFormat refFormat) {
|
325 | 326 | cache.putRenamedRef($ref, newRef);
|
326 | 327 |
|
327 | 328 | if(pathItem != null) {
|
328 |
| - if(pathItem.readOperationsMap() != null) { |
329 |
| - final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap(); |
330 |
| - for (PathItem.HttpMethod httpMethod : operationMap.keySet()) { |
331 |
| - Operation operation = operationMap.get(httpMethod); |
332 |
| - if (operation.getResponses() != null) { |
333 |
| - final Map<String, ApiResponse> responses = operation.getResponses(); |
334 |
| - if (responses != null) { |
335 |
| - for (String responseCode : responses.keySet()) { |
336 |
| - ApiResponse response = responses.get(responseCode); |
337 |
| - if (response != null) { |
338 |
| - Schema schema = null; |
339 |
| - if (response.getContent() != null) { |
340 |
| - Map<String, MediaType> content = response.getContent(); |
341 |
| - for (String mediaName : content.keySet()) { |
342 |
| - MediaType mediaType = content.get(mediaName); |
343 |
| - if (mediaType.getSchema() != null) { |
344 |
| - schema = mediaType.getSchema(); |
345 |
| - if (schema != null) { |
346 |
| - processRefSchemaObject(mediaType.getSchema(), $ref); |
347 |
| - } |
348 |
| - if (mediaType.getExamples() != null) { |
349 |
| - processRefExamples(mediaType.getExamples(), $ref); |
350 |
| - } |
| 329 | + processPathItem(pathItem, $ref); |
| 330 | + } |
| 331 | + |
| 332 | + return pathItem; |
| 333 | + } |
351 | 334 |
|
| 335 | + private void processPathItem(PathItem pathItem, String $ref) { |
| 336 | + if(pathItem.readOperationsMap() != null) { |
| 337 | + final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap(); |
| 338 | + for (PathItem.HttpMethod httpMethod : operationMap.keySet()) { |
| 339 | + Operation operation = operationMap.get(httpMethod); |
| 340 | + if (operation.getResponses() != null) { |
| 341 | + final Map<String, ApiResponse> responses = operation.getResponses(); |
| 342 | + if (responses != null) { |
| 343 | + for (String responseCode : responses.keySet()) { |
| 344 | + ApiResponse response = responses.get(responseCode); |
| 345 | + if (response != null) { |
| 346 | + Schema schema = null; |
| 347 | + if (response.getContent() != null) { |
| 348 | + Map<String, MediaType> content = response.getContent(); |
| 349 | + for (String mediaName : content.keySet()) { |
| 350 | + MediaType mediaType = content.get(mediaName); |
| 351 | + if (mediaType.getSchema() != null) { |
| 352 | + schema = mediaType.getSchema(); |
| 353 | + if (schema != null) { |
| 354 | + processRefSchemaObject(mediaType.getSchema(), $ref); |
| 355 | + } |
| 356 | + if (mediaType.getExamples() != null) { |
| 357 | + processRefExamples(mediaType.getExamples(), $ref); |
352 | 358 | }
|
| 359 | + |
353 | 360 | }
|
354 | 361 | }
|
355 |
| - if (response.getLinks() != null) { |
356 |
| - processRefLinks(response.getLinks(), $ref); |
357 |
| - } |
358 |
| - if (response.getHeaders() != null) { |
359 |
| - processRefHeaders(response.getHeaders(), $ref); |
360 |
| - } |
| 362 | + } |
| 363 | + if (response.getLinks() != null) { |
| 364 | + processRefLinks(response.getLinks(), $ref); |
| 365 | + } |
| 366 | + if (response.getHeaders() != null) { |
| 367 | + processRefHeaders(response.getHeaders(), $ref); |
361 | 368 | }
|
362 | 369 | }
|
363 | 370 | }
|
364 | 371 | }
|
365 |
| - if (operation.getRequestBody() != null) { |
366 |
| - RequestBody body = operation.getRequestBody(); |
367 |
| - if (body.getContent() != null) { |
368 |
| - Schema schema; |
369 |
| - Map<String, MediaType> content = body.getContent(); |
370 |
| - for (String mediaName : content.keySet()) { |
371 |
| - MediaType mediaType = content.get(mediaName); |
372 |
| - if (mediaType.getSchema() != null) { |
373 |
| - schema = mediaType.getSchema(); |
374 |
| - if (schema != null) { |
375 |
| - processRefSchemaObject(mediaType.getSchema(), $ref); |
376 |
| - } |
| 372 | + } |
| 373 | + if (operation.getRequestBody() != null) { |
| 374 | + RequestBody body = operation.getRequestBody(); |
| 375 | + if (body.getContent() != null) { |
| 376 | + Schema schema; |
| 377 | + Map<String, MediaType> content = body.getContent(); |
| 378 | + for (String mediaName : content.keySet()) { |
| 379 | + MediaType mediaType = content.get(mediaName); |
| 380 | + if (mediaType.getSchema() != null) { |
| 381 | + schema = mediaType.getSchema(); |
| 382 | + if (schema != null) { |
| 383 | + processRefSchemaObject(mediaType.getSchema(), $ref); |
377 | 384 | }
|
378 | 385 | }
|
379 | 386 | }
|
380 | 387 | }
|
| 388 | + } |
381 | 389 |
|
382 |
| - final List<Parameter> parameters = operation.getParameters(); |
383 |
| - if (parameters != null) { |
384 |
| - parameters.stream() |
385 |
| - .filter(parameter -> parameter.getSchema() != null) |
386 |
| - .forEach(parameter -> this.processRefSchemaObject(parameter.getSchema(), $ref)); |
387 |
| - } |
| 390 | + final List<Parameter> parameters = operation.getParameters(); |
| 391 | + if (parameters != null) { |
| 392 | + parameters.stream() |
| 393 | + .filter(parameter -> parameter.getSchema() != null) |
| 394 | + .forEach(parameter -> this.processRefSchemaObject(parameter.getSchema(), $ref)); |
388 | 395 | }
|
389 | 396 | }
|
390 | 397 | }
|
391 |
| - |
392 |
| - return pathItem; |
393 | 398 | }
|
394 | 399 |
|
395 | 400 | private void processDiscriminator(Discriminator d, String file) {
|
@@ -927,6 +932,24 @@ public String processRefToExternalCallback(String $ref, RefFormat refFormat) {
|
927 | 932 | processRefToExternalCallback(file + callback.get$ref(), RefFormat.RELATIVE);
|
928 | 933 | }
|
929 | 934 | }
|
| 935 | + } else { |
| 936 | + for (String path : callback.keySet()) { |
| 937 | + PathItem pathItem = callback.get(path); |
| 938 | + if(pathItem != null) { |
| 939 | + if (pathItem.get$ref() != null) { |
| 940 | + RefFormat pathRefFormat = computeRefFormat(pathItem.get$ref()); |
| 941 | + String path$ref = pathItem.get$ref(); |
| 942 | + if (isAnExternalRefFormat(refFormat)) { |
| 943 | + pathItem = this.processRefToExternalPathItem(path$ref, pathRefFormat); |
| 944 | + } else { |
| 945 | + pathItem = cache.loadRef(pathItem.get$ref(), refFormat, PathItem.class); |
| 946 | + } |
| 947 | + callback.put(path, pathItem); |
| 948 | + } else { |
| 949 | + this.processPathItem(pathItem, $ref); |
| 950 | + } |
| 951 | + } |
| 952 | + } |
930 | 953 | }
|
931 | 954 | }
|
932 | 955 |
|
|
0 commit comments