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

根据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.lryc.cn/news/462416.html

相关文章:

  • 如何将LiDAR坐标系下的3D点投影到相机2D图像上
  • JAVA就业笔记6——第二阶段(3)
  • 02.04、分割链表
  • Excel 中根据患者的就诊时间标记病例为“初诊”或“复诊”
  • 遇到“mfc100u.dll丢失”的系统错误要怎么处理?科学修复mfc100u.dll
  • [Linux] 逐层深入理解文件系统 (1)—— 进程操作文件
  • RT-Thread 互斥量的概念
  • 6.计算机网络_UDP
  • Windows应急响蓝安服面试
  • PCL 点云配准-4PCS算法(粗配准)
  • 12、论文阅读:利用生成对抗网络实现无监督深度图像增强
  • Axure重要元件三——中继器表单制作
  • DMAIC赋能智能家居:解锁未来生活新篇章!
  • 代码随想录算法训练营第二天| 209.长度最小的子数组 59.螺旋矩阵II 区间和 开发商购买土地
  • mysql隐藏索引
  • etcd入门到实战
  • Build an Android project and get a `.apk` file on a Debian 11 command line
  • 解读 Java 经典巨著《Effective Java》90条编程法则,第4条:通过私有构造器强化不可实例化的能力
  • Vivado HLS学习
  • 一款AutoXJS现代化美观的日志模块AxpLogger
  • 成都睿明智科技有限公司共创抖音电商新篇章
  • Spark的安装配置及集群搭建
  • 网络编程基础-IO模型深入理解
  • go 语言学习路线图(一)
  • 前端自动化部署,Netlify免费满足你
  • Linux的开发工具gcc Makefile gdb的学习
  • 基于SSM出租车管理系统的设计
  • iPhone照片内存怎么清理,参考这些方法
  • 【Triton教程】向量相加
  • 关于CSS中毛玻璃和滤镜使用总结