当前位置: 首页 > article >正文

根据json转HttpClient脚本

String json = “{\n” +
" “paths”: {\n" +
" “/dev-api/system/subjectResult/exportUserList”: {\n" +
" “post”: {\n" +
" “tags”: [\n" +
" “bd-subject-result-controller”\n" +
" ],\n" +
" “summary”: “导出对应成绩信息”,\n" +
" “operationId”: “exportUserListUsingPOST”,\n" +
" “parameters”: [\n" +
" {\n" +
" “name”: “batch”,\n" +
" “in”: “query”,\n" +
" “required”: false,\n" +
" “style”: “form”,\n" +
" “schema”: {\n" +
" “type”: “string”\n" +
" }\n" +
" },\n" +
" {\n" +
" “name”: “year”,\n" +
" “in”: “query”,\n" +
" “required”: false,\n" +
" “style”: “form”,\n" +
" “schema”: {\n" +
" “type”: “string”\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" },\n" +
" “/dev-api/system/subjectResult/test/{subjectId}”: {\n" +
" “get”: {\n" +
" “parameters”: [\n" +
" {\n" +
" “name”: “subjectId”,\n" +
" “in”: “path”,\n" +
" “description”: “subjectId”,\n" +
" “required”: true,\n" +
" “style”: “form”,\n" +
" “schema”: {\n" +
" “type”: “integer”,\n" +
" “format”: “int64”\n" +
" }\n" +
" },\n" +
" {\n" +
" “name”: “number”,\n" +
" “in”: “query”,\n" +
" “description”: “number”,\n" +
" “required”: true,\n" +
" “style”: “form”,\n" +
" “schema”: {\n" +
" “type”: “number”,\n" +
" “format”: “float”\n" +
" }\n" +
" },\n" +
" {\n" +
" “name”: “sort”,\n" +
" “in”: “query”,\n" +
" “description”: “sort”,\n" +
" “required”: true,\n" +
" “style”: “form”,\n" +
" “schema”: {\n" +
" “type”: “number”,\n" +
" “format”: “float”\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
" }\n" +
“}”;

ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(json);

StringBuilder result = new StringBuilder();

JsonNode pathsNode = rootNode.path(“paths”);
pathsNode.fieldNames().forEachRemaining(path -> {
JsonNode pathNode = pathsNode.path(path);
pathNode.fieldNames().forEachRemaining(method -> {
JsonNode methodNode = pathNode.path(method);
result.append(“### “).append(method.toUpperCase()).append(” request with dynamic variables\n”);
result.append(method.toUpperCase()).append(" http://{{host}}/{{staticurl}}“).append(path.replace(”{“, “{{”).replace(”}“, “}}”));
if (methodNode.has(“parameters”)) {
boolean firstQueryParam = true;
for (JsonNode param : methodNode.path(“parameters”)) {
String paramName = param.path(“name”).asText();
String paramIn = param.path(“in”).asText();
if (“query”.equals(paramIn)) {
if (firstQueryParam) {
result.append(”?“);
firstQueryParam = false;
} else {
result.append(”&“);
}
result.append(paramName).append(”=“).append(”{{“).append(paramName).append(”}}“);
}
}
}
result.append(”\nAccept: application/json\n\n");
});
});

System.out.println(result.toString());


http://www.kler.cn/news/358610.html

相关文章:

  • 数据为何成为资产?
  • 92. Color颜色渐变插值
  • 【JDK、Maven、Git、PostgreSQL】VSCode后端开发环境配置样例
  • 数值优化 | 图解梯度下降法与共轭梯度下降法(附案例分析与Python实现)
  • 北斗导航系统在智能交通领域的应用
  • 利用TDM在vscode中运行c语言
  • PAI 大语言模型评测平台现已支持裁判员模型评测
  • django连接mysql数据库
  • 堆结构和堆排序
  • 【iOS】YYModel
  • Element UI
  • Web安全实践
  • SQL入门
  • jupyter界面修改成中文教程
  • LabVIEW提高开发效率技巧----离线调试
  • 单片机中的BootLoader(BootLoader简介和写法)
  • Chromium html<lable>c++接口定义
  • SpringBoot 入门
  • 动态规划详解:最长公共子序列问题的高效解法
  • element-plus 官方表格排序问题