@Override
   public String getFileName(String baseRepositoryURL, Map<String, List<String>> headers) {
      if (headers != null) {
         for (String key : headers.keySet()) {
            if (key != null && key.equalsIgnoreCase(GITLAB_FILE_NAME_HEADER)) {
               return headers.get(key).get(0);
            }
         }
      }

      // If not present, extract from raw URL.
      String lastPath = baseRepositoryURL.substring(baseRepositoryURL.lastIndexOf("/") + 1);
      if (lastPath.startsWith("raw?ref=") || lastPath.indexOf('.') == -1) {
         String[] pathElements = baseRepositoryURL.split("/");
         int i = pathElements.length;
         while (i > 0) {
            String path = pathElements[i - 1];
            if (path.contains(".") && path.contains(ENCODED_FILE_SEPARATOR)) {
               return path.substring(path.indexOf(ENCODED_FILE_SEPARATOR) + ENCODED_FILE_SEPARATOR.length());
            }
            i--;
         }
      }
      return null;
   }
@Test
   void testGetFileName() {
      GitLabReferenceURLBuilder builder = new GitLabReferenceURLBuilder();

      assertEquals("API_Pastry_1.0.0-openapi.yaml", builder.getFileName(BASE_URL, null));

      Map<String, List<String>> headers = Map.of("X-Gitlab-File-Name", List.of("FooBar.yaml"));
      assertEquals("FooBar.yaml", builder.getFileName(BASE_URL, headers));

      headers = Map.of("x-gitlab-file-name", List.of("FooBar.yaml"));
      assertEquals("FooBar.yaml", builder.getFileName(BASE_URL, headers));
   }