|
31 | 31 | import com.fasterxml.jackson.core.JsonProcessingException;
|
32 | 32 | import io.swagger.v3.oas.annotations.Operation;
|
33 | 33 | import org.apache.commons.lang3.StringUtils;
|
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
34 | 36 | import org.springdoc.core.AbstractRequestService;
|
35 | 37 | import org.springdoc.core.ActuatorProvider;
|
36 | 38 | import org.springdoc.core.GenericResponseService;
|
|
63 | 65 | @RestController
|
64 | 66 | public class OpenApiWebMvcResource extends OpenApiResource {
|
65 | 67 |
|
| 68 | + /** |
| 69 | + * The constant LOGGER. |
| 70 | + */ |
| 71 | + private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiWebMvcResource.class); |
66 | 72 | /**
|
67 | 73 | * Instantiates a new Open api web mvc resource.
|
68 | 74 | *
|
@@ -142,12 +148,16 @@ public String openapiYaml(HttpServletRequest request, @Value(DEFAULT_API_DOCS_UR
|
142 | 148 | @Override
|
143 | 149 | protected String getServerUrl(HttpServletRequest request, String apiDocsUrl) {
|
144 | 150 | String requestUrl = decode(request.getRequestURL().toString());
|
145 |
| - Map<String, Predicate<Class<?>>> paths = ((RequestMappingHandlerMapping) requestMappingHandlerMapping).getPathPrefixes(); |
146 | 151 | final String[] prefix = { StringUtils.EMPTY };
|
147 |
| - paths.forEach((path, classPredicate) -> { |
148 |
| - if (classPredicate.test(this.getClass())) |
149 |
| - prefix[0] = path; |
150 |
| - }); |
| 152 | + try { |
| 153 | + Map<String, Predicate<Class<?>>> paths = ((RequestMappingHandlerMapping) requestMappingHandlerMapping).getPathPrefixes(); |
| 154 | + paths.forEach((path, classPredicate) -> { |
| 155 | + if (classPredicate.test(this.getClass())) |
| 156 | + prefix[0] = path; |
| 157 | + }); |
| 158 | + } catch (NoSuchMethodError exc){ |
| 159 | + LOGGER.warn(" Ignoring Path Prefix. Unable to find getPathPrefixes method using requestMappingHandlerMapping.: {}", exc.getMessage()); |
| 160 | + } |
151 | 161 | return requestUrl.substring(0, requestUrl.length() - apiDocsUrl.length()- prefix[0].length());
|
152 | 162 | }
|
153 | 163 |
|
|
0 commit comments