swagger 如何获取并显示json中2个元素的差异[已关闭]

gk7wooem  于 2023-01-02  发布在  其他
关注(0)|答案(1)|浏览(91)
    • 已关闭**。此问题需要超过focused。当前不接受答案。
    • 想要改进此问题吗?**更新此问题,使其仅关注editing this post的一个问题。

昨天关门了。
Improve this question
用jolt如何得到并显示json中2个元素的差异

    • 注意:json有2个元素: * 第一次第二次*。它们是由于空气污染指数的虚高而造成的。

我有一个输入

{
    "first": {
        "openapi": "3.0.1",
        "info": {
            "title": "api",
            "description": "API",
            "version": "2022-Dec-1"
        },
        "servers": [
            {
                "url": "https://the-api-1.com/api/",
                "description": "Generated server url"
            }
        ],
        "paths": {
            "/partners/{id}": {
                "get": {
                    "tags": [
                        "Partner Data"
                    ],
                    "summary": "Partner Data",
                    "operationId": "getPartnerData",
                    "parameters": [
                        {
                            "name": "id",
                            "in": "path",
                            "required": true,
                            "schema": {
                                "type": "integer",
                                "format": "int64"
                            }
                        }
                    ],
                    "responses": {
                        "200": {
                            "description": "Partner Data",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/PartnerDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                },
                "put": {
                    "tags": [
                        "Partner Data"
                    ],
                    "summary": "Update existing Partner Data",
                    "operationId": "updatePartnerData",
                    "parameters": [
                        {
                            "name": "id",
                            "in": "path",
                            "required": true,
                            "schema": {
                                "type": "integer",
                                "format": "int64"
                            }
                        }
                    ],
                    "requestBody": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PartnerDTO"
                                }
                            }
                        },
                        "required": true
                    },
                    "responses": {
                        "200": {
                            "description": "Returns Partner Data",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/PartnerDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "/customers/total-removal": {
                "post": {
                    "tags": [
                        "Customer Data"
                    ],
                    "summary": "Customer Data",
                    "operationId": "getCustomers",
                    "requestBody": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/customerDTO"
                                }
                            }
                        },
                        "required": true
                    },
                    "responses": {
                        "200": {
                            "description": "Returns CustomerDTO",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/customerDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "/adresses/": {
                "post": {
                    "tags": [
                        "addresses"
                    ],
                    "summary": "addresses",
                    "operationId": "getAdresses",
                    "requestBody": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/AdressDTO"
                                }
                            }
                        },
                        "required": true
                    },
                    "responses": {
                        "200": {
                            "description": "Returns adressDTO",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/AdressDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "components": {
            "schemas": {
                "partnerDTO": {
                    "required": [
                        "version"
                    ],
                    "type": "object",
                    "properties": {
                        "version": {
                            "type": "integer",
                            "description": "version",
                            "format": "int32"
                        },
                        "owner": {
                            "type": "boolean",
                            "description": "owner",
                            "default": false
                        }
                    }
                },
                "ErrorDto": {
                    "type": "object",
                    "properties": {
                        "type": {
                            "type": "string",
                            "description": "The type of the error Bad Request"
                        },
                        "title": {
                            "type": "string",
                            "description": "Short description of the error reason.<br>e.g. Request Body Error"
                        },
                        "detail": {
                            "type": "string",
                            "description": "Detail about the exception.<br>e.g. Required request body is missing"
                        },
                        "additionalDetails": {
                            "type": "array",
                            "description": "Optional list of additional details about the error.",
                            "items": {
                                "type": "string",
                                "description": "Optional list of additional details about the error."
                            }
                        }
                    },
                    "example": {
                        "type": "Bad Request",
                        "title": "Validation Error",
                        "detail": "Validation failed for parameter 'XDto'.",
                        "additionalDetails": [
                            "field: 'XId' - invalid value: 'null' - error message: 'must not be null'",
                            "field: 'XCode' - invalid value: 'ABCDEF' - error message: 'size must be between 1 and 5'"
                        ]
                    }
                },
                "CustomerDto": {
                    "required": [
                        "PartnerId",
                        "PartnerRoleIdentifier",
                        "division",
                        "PartnerIdType",
                        "PartnerIdentificationNumber"
                    ],
                    "type": "object",
                    "properties": {
                        "PartnerIdentificationNumber": {
                            "type": "string",
                            "description": "Partner identification number"
                        },
                        "partnerIdType": {
                            "type": "string",
                            "description": "Partner ID type",
                            "enum": [
                                "BDEW",
                                "GLN",
                                "DVGW"
                            ]
                        },
                        "owner": {
                            "type": "boolean",
                            "description": "business owner",
                            "default": false
                        },
                        "PartnerId": {
                            "type": "integer",
                            "description": "ID of the business partner",
                            "format": "int64"
                        },
                        "PartnerRoleIdentifier": {
                            "type": "string",
                            "description": "Identifier of the business partner role"
                        },
                        "division": {
                            "type": "string",
                            "description": "Division",
                            "enum": [
                                "division1",
                                "division2",
                                "division3",
                                "other"
                            ]
                        }
                    }
                }
            }
        }
    },
    "second": {
        "openapi": "3.0.1",
        "info": {
            "title": "api",
            "description": "API",
            "version": "2022-Dec-1"
        },
        "servers": [
            {
                "url": "https://the-api-2.com/api/",
                "description": "Generated server url"
            }
        ],
        "paths": {
            "/partners/{id}": {
                "get": {
                    "tags": [
                        "Partner Data"
                    ],
                    "summary": "Partner Data",
                    "operationId": "getPartnerData",
                    "parameters": [
                        {
                            "name": "id",
                            "in": "path",
                            "required": true,
                            "schema": {
                                "type": "integer",
                                "format": "int32"
                            }
                        }
                    ],
                    "responses": {
                        "200": {
                            "description": "Partner Data",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/PartnerDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                },
                "put": {
                    "tags": [
                        "Partner Data"
                    ],
                    "summary": "Update existing Partner Data",
                    "operationId": "updatePartnerData",
                    "parameters": [
                        {
                            "name": "id",
                            "in": "path",
                            "required": true,
                            "schema": {
                                "type": "integer",
                                "format": "int64"
                            }
                        }
                    ],
                    "requestBody": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PartnerDTO"
                                }
                            }
                        },
                        "required": true
                    },
                    "responses": {
                        "200": {
                            "description": "Returns Partner Data",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/PartnerDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "/customers/total-removal": {
                "post": {
                    "tags": [
                        "Customer Data"
                    ],
                    "summary": "Customer Data",
                    "operationId": "getCustomers",
                    "requestBody": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/customerDTO"
                                }
                            }
                        },
                        "required": true
                    },
                    "responses": {
                        "200": {
                            "description": "Returns CustomerDTO",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/customerDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "/adresses/": {
                "post": {
                    "tags": [
                        "addresses"
                    ],
                    "summary": "addresses",
                    "operationId": "getAdresses",
                    "requestBody": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/AdressDTO"
                                }
                            }
                        },
                        "required": true
                    },
                    "responses": {
                        "200": {
                            "description": "Returns adressDTO",
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/AdressDTO"
                                    }
                                }
                            }
                        },
                        "401": {
                            "description": "Unauthorized",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "403": {
                            "description": "Forbidden",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "4XX": {
                            "description": "Client Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        },
                        "5XX": {
                            "description": "Server Error",
                            "content": {
                                "application/problem+json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ErrorDto"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "components": {
            "schemas": {
                "partnerDTO": {
                    "required": [
                        "version"
                    ],
                    "type": "object",
                    "properties": {
                        "version": {
                            "type": "integer",
                            "description": "version",
                            "format": "int32"
                        },
                        "owner": {
                            "type": "boolean",
                            "description": "owner",
                            "default": false
                        }
                    }
                },
                "ErrorDto": {
                    "type": "object",
                    "properties": {
                        "type": {
                            "type": "string",
                            "description": "The type of the error Bad Request"
                        },
                        "title": {
                            "type": "string",
                            "description": "Short description of the error reason.<br>e.g. Request Body Error"
                        },
                        "detail": {
                            "type": "string",
                            "description": "Detail about the exception.<br>e.g. Required request body is missing"
                        },
                        "additionalDetails": {
                            "type": "array",
                            "description": "Optional list of additional details about the error.",
                            "items": {
                                "type": "string",
                                "description": "Optional list of additional details about the error."
                            }
                        }
                    },
                    "example": {
                        "type": "Bad Request",
                        "title": "Validation Error",
                        "detail": "Validation failed for parameter 'XDto'.",
                        "additionalDetails": [
                            "field: 'XId' - invalid value: 'null' - error message: 'must not be null'",
                            "field: 'XCode' - invalid value: 'ABCDEF' - error message: 'size must be between 1 and 5'"
                        ]
                    }
                },
                "CustomerDto": {
                    "required": [
                        "PartnerId",
                        "PartnerRoleIdentifier",
                        "division",
                        "PartnerIdType",
                        "PartnerIdentificationNumber"
                    ],
                    "type": "object",
                    "properties": {
                        "PartnerIdentificationNumber": {
                            "type": "string",
                            "description": "Partner identification number"
                        },
                        "partnerIdType": {
                            "type": "string",
                            "description": "Partner ID type",
                            "enum": [
                                "BDEW",
                                "GLN",
                                "DVGW"
                            ]
                        },
                        "owner": {
                            "type": "boolean",
                            "description": "business owner",
                            "default": false
                        },
                        "PartnerId": {
                            "type": "integer",
                            "description": "ID of the business partner",
                            "format": "int64"
                        },
                        "PartnerRoleIdentifier": {
                            "type": "string",
                            "description": "Identifier of the business partner role"
                        },
                        "division": {
                            "type": "string",
                            "description": "Division",
                            "enum": [
                                "division1",
                                "division2",
                                "division3",
                                "other"
                            ]
                        }
                    }
                }
            }
        }
    }
}

我需要一个输出:

{
  "diffirences": [
    {
      "path" : "first.servers[0].url",
      "first" : "https://the-api-1.com/api/",
      "second" : "https://the-api-2.com/api/"
    },
    {
      "path" : "first.paths[\"/partners/{id}\"].get.parameters[0].schema.format",
      "first" : "int64",
      "second" : "int32"
    }
  ]
}

我需要一个震动脚本来解决这个问题,结果显示2个元素的差异第一第二。差异将写在一个数组的json像上面。

jw5wzhpr

jw5wzhpr1#

可以使用此等级库:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "servers": {
          "0": {
            "url": "diffirences[0].&3"
          }
        },
        "paths": {
          "*": {
            "get": {
              "parameters": {
                "0": {
                  "schema": {
                    "format": "diffirences[1].&7"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "[0]": {
          "path": "first.servers[0].url"
        },
        "[1]": {
          "path": "first.paths[\"/partners/{id}\"].get.parameters[0].schema.format"
        }
      }
    }
  }
]

相关问题