我们可以在Wiremock中自定义映射文件名吗?

Ana*_*til 5 wiremock wiremock-record wiremock-standalone

我正在使用 JAVA DSL 通过 Wiremock 录制应用程序,我们可以选择自定义映射文件名吗?而不是获取从wiremock生成的文件名..

示例:searchpanel_arrivalairport_th-72f9b8b7-076f-4102-b6a8-aa38710fde1b.json(使用java生成的wiremock)我期望上面的文件名具有我想要的命名约定,例如

seacrpanel_airport_LGW.json

小智 0

可以通过自定义 StubMappingJsonRecorder 来添加自定义文件名。

我添加了 CustomStubMappingJsonRecorder 并重写 writeToMappingAndBodyFile 方法。

 if(fileName!=null && !fileName.equals("")){
      mappingFileName=fileName+"-mapping.json";
      bodyFileName=fileName+"-body.json";
    }else {
      mappingFileName = UniqueFilenameGenerator.generate(request.getUrl(), 
      "mapping", filed);
       bodyFileName = UniqueFilenameGenerator.generate(request.getUrl(), "body", 
         fileId, ContentTypes.determineFileExtension(request.getUrl(), 
         response.getHeaders().getContentTypeHeader(), body));
        }
Run Code Online (Sandbox Code Playgroud)