根据json转HttpClient脚本

news/2024/10/18 7:15:27/

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.ppmy.cn/news/1539931.html

相关文章

【数据结构与算法】栈和队列(下)

记录自己所学&#xff0c;无详细讲解 队列的实现--使用动态链表 1.项目目录文件 、 2.头文件 queue.h #pragma once #include <stdio.h> #include <assert.h> #include <stdlib.h> #include <stdbool.h> struct QueueNode {int data;struct Queue…

软件框架和软件架构的概念

软件框架&#xff08;Software Framework&#xff09; 和 软件架构&#xff08;Software Architecture&#xff09; 的关系在于它们分别处于系统设计和实现的不同层次&#xff0c;互为补充。架构决定了系统的整体结构和设计&#xff0c;而框架则是实现这些设计的工具和技术。下…

BMC 中的日志类型:Audit Log、SEL Log、Sys Log 与 SOL Log 的功能与区别

在现代服务器和数据中心管理中&#xff0c;BMC&#xff08;Baseboard Management Controller&#xff09;作为一种关键的管理组件&#xff0c;负责监控和管理硬件设备的状态。为了确保系统的安全性和操作的可追溯性&#xff0c;BMC 提供了多种类型的日志&#xff0c;以记录不同…

C++算法练习-day5——59.螺旋矩阵2

题目来源&#xff1a;. - 力扣&#xff08;LeetCode&#xff09; 题目思路分析 给定一个整数 n&#xff0c;要求生成一个 n x n 的矩阵&#xff0c;其中的元素按螺旋顺序排列&#xff0c;从矩阵的左上角开始&#xff0c;向右、向下、向左、向上依次填充&#xff0c;直到所有元…

PROFINET开发EtherNet/IP开发Vline板卡在称重设备行业的应用

本次分享的&#xff0c;是我们VlinePROFINET开发EtherNet/IP开发嵌入式板卡在称重行业的典型应用。 应用背景 在现代科技高度发达的时代&#xff0c;无论是科学研究、医疗诊断、制药生产还是工业制造&#xff0c;准确的测量和称重都是保证质量和效率的关键。 随着新项目实施…

JavaWeb 22.Node.js_简介和安装

有时候&#xff0c;后退原来是向前 —— 24.10.7 一、什么是Node.js Node.js 是一个于 Chrome V8 的 JavaScript 运行时环境&#xff0c;可以使 JavaScript 运行在服务器端。使用 Node.js&#xff0c;可以方便地开发服务器端应用程序&#xff0c;如 Web 应用、API、后端服务&a…

C++_Stack和Queue的使用及其模拟实现

✨✨ 欢迎大家来到小伞的大讲堂✨✨ &#x1f388;&#x1f388;养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; 所属专栏&#xff1a;C学习 小伞的主页&#xff1a;xiaosan_blog 1.stack的介绍及使用 1.1stack的介绍 stack的文档介绍 深入了解栈在数据结构中…

SpringCloudStream使用StreamBridge实现延时队列

利用RabbitMQ实现消息的延迟队列 一、安装RabbitMQ 1、安装rabbitmq 安装可以看https://blog.csdn.net/qq_38618691/article/details/118223851,进行安装。 2、安装插件 安装完毕后,exchange是不支持延迟类型的,需要手动安装插件,需要和安装的rabbitmq版本一致 https:…