"Metadata"
:
{
"ServiceId"
:
"serviceID"
,
"InterfaceName"
:
"接口名称"
,
"Uri"
:
"http:/example/theUrl"
,
"RequestType"
:
"json/wsdl"
,
"RequestProtocol"
:
"http"
,
"InterfaceDescription"
:
"测试"
"Request"
:
{
"$schema"
:
"http://json-scma.org/theurl"
,
"type"
:
"object"
,
"required"
:
true
,
"properties"
:
{
"ReqBody"
:
{
"type"
:
"object"
,
"required"
:
true
,
"properties"
:
{
"paramA"
:
{
"description"
:
"参数1"
,
"type"
:
"string"
,
"required"
:
true
"paramb"
:
{
"description"
:
"参数2"
,
"type"
:
"string"
,
"required"
:
false
"name"
:
{
"description"
:
"姓名"
,
"type"
:
"string"
,
"required"
:
true
"Response"
:
{
"$schema"
:
"http://json-s/chema"
,
"type"
:
"object"
,
"required"
:
true
,
"properties"
:
{
"RspBody"
:
{
"type"
:
"object"
,
"required"
:
true
,
"properties"
:
{
"paramA"
:
{
"description"
:
"参数1"
,
"type"
:
"string"
,
"required"
:
true
"paramc"
:
{
"description"
:
"参数3"
,
"type"
:
"string"
,
"required"
:
false
"Id"
:
{
"description"
:
"id"
,
"type"
:
"string"
,
"required"
:
true
"items"
:
{
"dessription"
:
"ssds"
,
"type"
:
"array"
,
"properties"
:
{
"arrayName"
:
[
{
"arrayParam"
:
"param"
,
"arrayParam22"
:
"31"
-
首先需要导入所有需要统计的json文件到一个对象数组中,以便后续进行对数据的遍历。
let fs = require('fs')
let dir = fs.readdirSync("./")
let newData = []
for (const iterator of dir) {
let dataElement = require('./' + iterator)
newData.push(dataElement)
- 设置input和output对象作为记录所有参数及其出现次数的全局变量
let input ={}, output ={}
-
获取到所有需要的数据就要对其进行处理。已知所有json文件都具有Request和Response部分,将其作为判断是否进行后续分析处理的入口,以此排除掉文件夹中可能出现的不属于json格式的数据。Request和Response部分的数据格式基本相同,因此可以使用类似的方法进行处理。
-
首先获取其内部实际存储参数名和类型的子对象,即Request.properties.ReqBody.properties部分,若其不是array类型,则其内部没有子对象,是一个string或number类型的普通参数。
-
那么遍历input对象,比较参数名是否已在input对象中。若input中没有该参数名则添加该参数名,value初值设置为1,若input中已有该参数名这则将其value值在原来的基础上加一。
-
若其是array类型,说明仍有子对象,需要进一步遍历。尤其数据格式可知子对象在value.items.properties
中,对其进行上述类似处理即可
-
对于Response对象的处理与Request的处理类似
function getParam(data) {
if (data.Request && data.Response) {
let req = data.Request.properties.ReqBody.properties
let res = data.Response.properties.RspBody.properties
for (const [key, value] of Object.entries(req)) {
if (value.type !== 'array') {
let flag = false
for (const [key1, value1] of Object.entries(input)) {
if (key1 === key) {
flag = true
break
if (flag) {
input[key] = input[key] + 1
} else {
input[key] = 1
} else {
for
(const [key1, value1] of Object.entries(value.items.properties)) {
for (const [key2, value2] of Object.entries(input)) {
if (key2 === key1) {
flag = true
break
if (flag) {
input[key1] = input[key1] + 1
} else {
input[key1] = 1
for (const [key, value] of Object.entries(res)) {
let flag = false
if (value.type !== 'array') {
for (const [key1, value1] of Object.entries(output)) {
if (key1 === key) {
flag = true
break
if (flag) {
output[key] = output[key] + 1
} else {
output[key] = 1
} else {
for (const [key1, value1] of Object.entries(value.items.properties)) {
for (const [key2, value2] of Object.entries(output)) {
if (key2 === key1) {
flag = true
break
if (flag) {
output[key1] = output[key1] + 1
} else {
output[key1] = 1
- 将数据导出到excel文件中
let XLSX = require('js-xlsx')
function geneExcel(input1, output1) {