Remove local repo & json-schema-validator-i18n-support
This commit is contained in:
@@ -1,273 +0,0 @@
|
||||
/**
|
||||
* context 上下文便捷操作函数
|
||||
*
|
||||
*/
|
||||
var common = {
|
||||
/* *********** private function begin *********** */
|
||||
|
||||
/**
|
||||
* 获取上下文中客户端请求对象
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
*/
|
||||
getInputReq: function (ctx){
|
||||
if(!ctx || !ctx['input'] || !ctx['input']['request']){
|
||||
return {};
|
||||
}
|
||||
return ctx['input']['request']
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取上下文步骤中请求接口的请求对象
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名称 【必填】
|
||||
* @param {*} requestName 请求名称 【必填】
|
||||
*/
|
||||
getStepReq: function (ctx, stepName, requestName){
|
||||
if(!ctx || !stepName || !requestName){
|
||||
return {};
|
||||
}
|
||||
if(!ctx[stepName] || !ctx[stepName]['requests'] || !ctx[stepName]['requests'][requestName] ||
|
||||
!ctx[stepName]['requests'][requestName]['request']){
|
||||
return {};
|
||||
}
|
||||
return ctx[stepName]['requests'][requestName]['request'];
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取上下文步骤中请求接口的响应对象
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名称 【必填】
|
||||
* @param {*} requestName 请求名称 【必填】
|
||||
*/
|
||||
getStepResp: function (ctx, stepName, requestName){
|
||||
if(!ctx || !stepName || !requestName){
|
||||
return {};
|
||||
}
|
||||
if(!ctx[stepName] || !ctx[stepName]['requests'] || !ctx[stepName]['requests'][requestName] ||
|
||||
!ctx[stepName]['requests'][requestName]['response']){
|
||||
return {};
|
||||
}
|
||||
return ctx[stepName]['requests'][requestName]['response'];
|
||||
},
|
||||
|
||||
/* *********** private function end *********** */
|
||||
|
||||
/* *********** input begin ************ */
|
||||
|
||||
/**
|
||||
* 获取客户端请求头
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} headerName 请求头字段名 【选填】,不传时返回所有请求头
|
||||
*/
|
||||
getInputReqHeader: function (ctx, headerName){
|
||||
var req = this.getInputReq(ctx);
|
||||
var headers = req['headers'] || {};
|
||||
return headerName ? headers[headerName.toUpperCase()] : headers;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取客户端URL请求参数(query string)
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} paramName URL参数名 【选填】,不传时返回所有请求参数
|
||||
*/
|
||||
getInputReqParam: function (ctx, paramName){
|
||||
var req = this.getInputReq(ctx);
|
||||
var params = req['params'] || {};
|
||||
return paramName ? params[paramName] : params;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取客户端请求体
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} field 字段名 【选填】,不传时返回整个请求体
|
||||
*/
|
||||
getInputReqBody: function (ctx, field){
|
||||
var req = this.getInputReq(ctx);
|
||||
var body = req['body'] || {};
|
||||
return field ? body[field] : body;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取返回给客户端的响应头
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} headerName 响应头字段名 【选填】,不传时返回所有响应头
|
||||
*/
|
||||
getInputRespHeader: function (ctx, headerName){
|
||||
var req = this.getInputReq(ctx);
|
||||
var headers = req['headers'] || {};
|
||||
return headerName ? headers[headerName.toUpperCase()] : headers;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取返回给客户端的响应体
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} field 字段名 【选填】,不传时返回整个响应体
|
||||
*/
|
||||
getInputRespBody: function (ctx, field){
|
||||
var req = this.getInputReq(ctx);
|
||||
var body = req['body'] || {};
|
||||
return field ? body[field] : body;
|
||||
},
|
||||
|
||||
/* *********** input begin ************ */
|
||||
|
||||
/* *********** step request begin ************ */
|
||||
|
||||
/**
|
||||
* 获取步骤中调用的接口的请求头
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
* @param {*} requestName 请求的接口名 【必填】
|
||||
* @param {*} headerName 请求头字段名 【选填】,不传时返回所有请求头
|
||||
*/
|
||||
getStepReqHeader: function (ctx, stepName, requestName, headerName){
|
||||
var req = this.getStepReq(ctx, stepName, requestName);
|
||||
var headers = req['headers'] || {};
|
||||
return headerName ? headers[headerName.toUpperCase()] : headers;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取步骤中调用的接口的URL参数
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
* @param {*} requestName 请求的接口名 【必填】
|
||||
* @param {*} paramName URL参数名 【选填】,不传时返回所有URL参数
|
||||
*/
|
||||
getStepReqParam: function (ctx, stepName, requestName, paramName){
|
||||
var req = this.getStepReq(ctx, stepName, requestName);
|
||||
var params = req['params'] || {};
|
||||
return paramName ? params[paramName] : params;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取步骤中调用的接口的请求体
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
* @param {*} requestName 请求的接口名 【必填】
|
||||
* @param {*} field 字段名 【选填】,不传时返回整个请求体
|
||||
*/
|
||||
getStepReqBody: function (ctx, stepName, requestName, field){
|
||||
var req = this.getStepReq(ctx, stepName, requestName);
|
||||
var body = req['body'] || {};
|
||||
return field ? body[field] : body;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取步骤中调用的接口的响应头
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
* @param {*} requestName 请求的接口名 【必填】
|
||||
* @param {*} headerName 响应头字段名 【选填】,不传时返回所有响应头
|
||||
*/
|
||||
getStepRespHeader: function (ctx, stepName, requestName, headerName){
|
||||
var resp = this.getStepResp(ctx, stepName, requestName);
|
||||
var headers = resp['headers'] || {};
|
||||
return headerName ? headers[headerName.toUpperCase()] : headers;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取步骤中调用的接口的响应体
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
* @param {*} requestName 请求的接口名 【必填】
|
||||
* @param {*} field 字段名 【选填】,不传时返回整个响应体
|
||||
*/
|
||||
getStepRespBody: function (ctx, stepName, requestName, field){
|
||||
var resp = this.getStepResp(ctx, stepName, requestName);
|
||||
var body = resp['body'] || {};
|
||||
return field ? body[field] : body;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取步骤结果
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
* @param {*} field 字段名 【选填】,不传时返回整个步骤结果对象
|
||||
*/
|
||||
getStepResult: function (ctx, stepName, field){
|
||||
if(!ctx || !stepName || !ctx[stepName]){
|
||||
return {};
|
||||
}
|
||||
var result = ctx[stepName]['result'] || {};
|
||||
return field ? result[field] : result;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取步骤循环结果
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
*/
|
||||
getStepCircle: function (ctx, stepName){
|
||||
if(!ctx || !stepName || !ctx[stepName]){
|
||||
return null;
|
||||
}
|
||||
// 返回循环结果数组
|
||||
return ctx[stepName]['circle'];
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取请求的循环结果
|
||||
* @param {*} ctx 上下文 【必填】
|
||||
* @param {*} stepName 步骤名【必填】
|
||||
*/
|
||||
getRequestCircle: function (ctx, stepName, requestName){
|
||||
if(!ctx || !stepName || !requestName){
|
||||
return null;
|
||||
}
|
||||
if(!ctx[stepName] || !ctx[stepName]['requests'] || !ctx[stepName]['requests'][requestName] ||
|
||||
!ctx[stepName]['requests'][requestName]['request']){
|
||||
return null;
|
||||
}
|
||||
// 返回循环结果数组
|
||||
return ctx[stepName]['requests'][requestName]['circle'];
|
||||
}
|
||||
|
||||
/* *********** step request end ************ */
|
||||
|
||||
,/**
|
||||
** 乘法函数,用来得到精确的乘法结果
|
||||
** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
|
||||
** 调用:accMul(arg1,arg2)
|
||||
** 返回值:arg1乘以 arg2的精确结果
|
||||
**/
|
||||
accMul:function (arg1, arg2) {
|
||||
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
|
||||
try {
|
||||
m += s1.split(".")[1].length;
|
||||
} catch (e) {
|
||||
}
|
||||
try {
|
||||
m += s2.split(".")[1].length;
|
||||
} catch (e) {
|
||||
}
|
||||
return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
|
||||
/ Math.pow(10, m);
|
||||
},
|
||||
|
||||
/**
|
||||
** 除法函数,用来得到精确的除法结果
|
||||
** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
|
||||
** 调用:accDiv(arg1,arg2)
|
||||
** 返回值:arg1除以arg2的精确结果
|
||||
**/
|
||||
accDiv:function (arg1, arg2) {
|
||||
var t1 = 0, t2 = 0, r1, r2;
|
||||
try {
|
||||
t1 = arg1.toString().split(".")[1].length;
|
||||
} catch (e) {
|
||||
}
|
||||
try {
|
||||
t2 = arg2.toString().split(".")[1].length;
|
||||
} catch (e) {
|
||||
}
|
||||
with (Math) {
|
||||
r1 = Number(arg1.toString().replace(".", ""));
|
||||
r2 = Number(arg2.toString().replace(".", ""));
|
||||
return (r1 / r2) * pow(10, t2 - t1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -57,12 +57,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
<version>1.0.39_6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- import fizz-input-mysql -->
|
||||
<!-- <dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
@@ -106,13 +100,6 @@
|
||||
</profile>-->
|
||||
</profiles>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo</id>
|
||||
<url>file://${project.basedir}/../repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -120,12 +107,6 @@
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@@ -41,12 +41,6 @@
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
<version>1.0.39_6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jruby.joni</groupId>
|
||||
<artifactId>joni</artifactId>
|
||||
@@ -136,46 +130,12 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo</id>
|
||||
<url>file://${project.basedir}/../repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.networknt:json-schema-validator-i18n-support</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.networknt</pattern>
|
||||
<shadedPattern>com.fizzgate.repackaged.com.networknt</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 the original author or authors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.fizzgate.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.networknt.schema.JsonSchema;
|
||||
import com.networknt.schema.JsonSchemaFactory;
|
||||
import com.networknt.schema.SchemaValidatorsConfig;
|
||||
import com.networknt.schema.SpecVersion;
|
||||
import com.networknt.schema.ValidationMessage;
|
||||
import com.networknt.schema.ValidatorTypeCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* JSON Schema工具类
|
||||
* @author zhongjie
|
||||
*/
|
||||
public class JsonSchemaUtils {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JsonSchemaUtils.class);
|
||||
static {
|
||||
try {
|
||||
// 替换验证信息提示
|
||||
Field messageFormatField = ValidatorTypeCode.class.getDeclaredField("messageFormat");
|
||||
//忽略属性的访问权限
|
||||
messageFormatField.setAccessible(true);
|
||||
messageFormatField.set(ValidatorTypeCode.ADDITIONAL_PROPERTIES, new MessageFormat(
|
||||
"{1}在schema中没有定义并且schema不允许指定外的字段"));
|
||||
messageFormatField.set(ValidatorTypeCode.ALL_OF, new MessageFormat("should be valid to all the schemas {1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.ANY_OF, new MessageFormat("should be valid to any of the schemas {1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.CROSS_EDITS, new MessageFormat("has an error with 'cross edits'"));
|
||||
messageFormatField.set(ValidatorTypeCode.DEPENDENCIES, new MessageFormat("has an error with dependencies {1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.EDITS, new MessageFormat("has an error with 'edits'"));
|
||||
messageFormatField.set(ValidatorTypeCode.ENUM, new MessageFormat("值不在限定{1}内"));
|
||||
messageFormatField.set(ValidatorTypeCode.FORMAT, new MessageFormat("不符合{1}格式{2}"));
|
||||
messageFormatField.set(ValidatorTypeCode.ITEMS, new MessageFormat("在索引[{1}]处为找到验证器"));
|
||||
messageFormatField.set(ValidatorTypeCode.MAXIMUM, new MessageFormat("给定值应当小于等于{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.MAX_ITEMS, new MessageFormat("数组至多含有{1}个元素"));
|
||||
messageFormatField.set(ValidatorTypeCode.MAX_LENGTH, new MessageFormat("长度应当最多{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.MAX_PROPERTIES, new MessageFormat("对象最多有{1}个字段"));
|
||||
messageFormatField.set(ValidatorTypeCode.MINIMUM, new MessageFormat("给定值应当大于等于{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.MIN_ITEMS, new MessageFormat("数组至少含有{1}个元素"));
|
||||
messageFormatField.set(ValidatorTypeCode.MIN_LENGTH, new MessageFormat("长度应当最少{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.MIN_PROPERTIES, new MessageFormat("{0}:对象最少有{1}个字段"));
|
||||
messageFormatField.set(ValidatorTypeCode.MULTIPLE_OF, new MessageFormat("数值类型应当是{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.NOT_ALLOWED, new MessageFormat("{1}不允许出现在数据中"));
|
||||
messageFormatField.set(ValidatorTypeCode.NOT, new MessageFormat("should not be valid to the schema {1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.ONE_OF, new MessageFormat("should be valid to one and only one of the schemas {1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.PATTERN_PROPERTIES, new MessageFormat("has some error with 'pattern properties'"));
|
||||
messageFormatField.set(ValidatorTypeCode.PATTERN, new MessageFormat("应当符合格式\"{1}\""));
|
||||
messageFormatField.set(ValidatorTypeCode.PROPERTIES, new MessageFormat("对象字段存在错误"));
|
||||
messageFormatField.set(ValidatorTypeCode.READ_ONLY, new MessageFormat("is a readonly field, it cannot be changed"));
|
||||
messageFormatField.set(ValidatorTypeCode.REF, new MessageFormat("has an error with 'refs'"));
|
||||
messageFormatField.set(ValidatorTypeCode.REQUIRED, new MessageFormat("{1}字段不能为空"));
|
||||
messageFormatField.set(ValidatorTypeCode.TYPE, new MessageFormat("预期类型是{2},但实际是{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.UNION_TYPE, new MessageFormat("预期类型是{2},但实际是{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.UNIQUE_ITEMS, new MessageFormat("数组元素唯一性冲突"));
|
||||
messageFormatField.set(ValidatorTypeCode.DATETIME, new MessageFormat("{1}不是一个有效的{2}"));
|
||||
messageFormatField.set(ValidatorTypeCode.UUID, new MessageFormat("{1}不是一个有效的{2}"));
|
||||
messageFormatField.set(ValidatorTypeCode.ID, new MessageFormat("{1} is an invalid segment for URI {2}"));
|
||||
messageFormatField.set(ValidatorTypeCode.EXCLUSIVE_MAXIMUM, new MessageFormat("给定值应当小于{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.EXCLUSIVE_MINIMUM, new MessageFormat("给定值应当大于{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.FALSE, new MessageFormat("Boolean schema false is not valid"));
|
||||
messageFormatField.set(ValidatorTypeCode.CONST, new MessageFormat("值应当是一个常量{1}"));
|
||||
messageFormatField.set(ValidatorTypeCode.CONTAINS, new MessageFormat("没有包含元素能够通过验证:{1}"));
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("替换ValidatorTypeCode.messageFormat异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private JsonSchemaUtils() {}
|
||||
|
||||
/**
|
||||
* 验证JSON字符串是否符合JSON Schema要求
|
||||
* @param jsonSchema JSON Schema
|
||||
* @param inputJson JSON字符串
|
||||
* @return null:验证通过,List:报错信息列表
|
||||
*/
|
||||
public static List<String> validate(String jsonSchema, String inputJson) {
|
||||
return internalValidate(jsonSchema, inputJson, Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证JSON字符串是否符合JSON Schema要求,允许数字\布尔类型 是字符串格式
|
||||
* @param jsonSchema JSON Schema
|
||||
* @param inputJson JSON字符串
|
||||
* @return null:验证通过,List:报错信息列表
|
||||
*/
|
||||
public static List<String> validateAllowValueStr(String jsonSchema, String inputJson) {
|
||||
return internalValidate(jsonSchema, inputJson, Boolean.TRUE);
|
||||
}
|
||||
|
||||
private static List<String> internalValidate(String jsonSchema, String inputJson, boolean typeLoose) {
|
||||
CheckJsonResult checkJsonResult = checkJson(jsonSchema, inputJson, typeLoose);
|
||||
if (checkJsonResult.errorList != null) {
|
||||
return checkJsonResult.errorList;
|
||||
}
|
||||
|
||||
Set<ValidationMessage> validationMessageSet = checkJsonResult.schema.validate(checkJsonResult.json);
|
||||
if (CollectionUtils.isEmpty(validationMessageSet)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return validationMessageSet.stream().map(validationMessage -> {
|
||||
String message = validationMessage.getMessage();
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
return validationMessage.getCode();
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static CheckJsonResult checkJson(String jsonSchema, String inputJson, boolean typeLoose) {
|
||||
CheckJsonResult checkJsonResult = new CheckJsonResult();
|
||||
try {
|
||||
checkJsonResult.schema = getJsonSchemaFromStringContent(jsonSchema, typeLoose);
|
||||
} catch (Exception e) {
|
||||
checkJsonResult.errorList = new ArrayList<>(1);
|
||||
checkJsonResult.errorList.add(String.format("JSON Schema格式错误,提示信息[%s]", e.getMessage()));
|
||||
return checkJsonResult;
|
||||
}
|
||||
|
||||
try {
|
||||
checkJsonResult.json = getJsonNodeFromStringContent(inputJson);
|
||||
} catch (Exception e) {
|
||||
checkJsonResult.errorList = new ArrayList<>(1);
|
||||
checkJsonResult.errorList.add(String.format("待验证JSON格式错误,提示信息[%s]", e.getMessage()));
|
||||
return checkJsonResult;
|
||||
}
|
||||
|
||||
return checkJsonResult;
|
||||
}
|
||||
|
||||
private static class CheckJsonResult {
|
||||
JsonSchema schema;
|
||||
JsonNode json;
|
||||
List<String> errorList;
|
||||
}
|
||||
|
||||
private static final JsonSchemaFactory JSON_SCHEMA_FACTORY = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
|
||||
private static final SchemaValidatorsConfig CONFIG_WITH_TYPE_LOOSE;
|
||||
private static final SchemaValidatorsConfig CONFIG_WITHOUT_TYPE_LOOSE;
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
static {
|
||||
CONFIG_WITH_TYPE_LOOSE = new SchemaValidatorsConfig();
|
||||
CONFIG_WITH_TYPE_LOOSE.setTypeLoose(Boolean.TRUE);
|
||||
CONFIG_WITHOUT_TYPE_LOOSE = new SchemaValidatorsConfig();
|
||||
CONFIG_WITHOUT_TYPE_LOOSE.setTypeLoose(Boolean.FALSE);
|
||||
}
|
||||
private static JsonSchema getJsonSchemaFromStringContent(String schemaContent, boolean typeLoose) {
|
||||
SchemaValidatorsConfig config = typeLoose ? CONFIG_WITH_TYPE_LOOSE : CONFIG_WITHOUT_TYPE_LOOSE;
|
||||
return JSON_SCHEMA_FACTORY.getSchema(schemaContent, config);
|
||||
}
|
||||
|
||||
private static JsonNode getJsonNodeFromStringContent(String content) throws Exception {
|
||||
return OBJECT_MAPPER.readTree(content);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 the original author or authors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.fizzgate.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.fizzgate.schema.util.I18nUtils;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class JsonSchemaUtilsTest {
|
||||
|
||||
@Test
|
||||
void validateRequiredPropertyWithoutAssignedTitleAndTitleEn() {
|
||||
I18nUtils.setContextLocale(new Locale("zh"));
|
||||
try {
|
||||
List<String> validateList = JsonSchemaUtils.validate(
|
||||
"{\n" +
|
||||
" \"properties\": {\n" +
|
||||
" \"library\": {\n" +
|
||||
" \"type\": \"object\",\n" +
|
||||
" \"required\": [\n" +
|
||||
" \"person\"\n" +
|
||||
" ],\n" +
|
||||
" \"properties\": {\n" +
|
||||
" \"person\": {\n" +
|
||||
" \"type\": \"string\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"required\": [\n" +
|
||||
" \"library\"\n" +
|
||||
" ],\n" +
|
||||
" \"type\": [\n" +
|
||||
" \"object\",\n" +
|
||||
" \"null\"\n" +
|
||||
" ]\n" +
|
||||
"}",
|
||||
"{\n" +
|
||||
" \"library\":{\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
assertNotNull(validateList);
|
||||
assertEquals(1, validateList.size());
|
||||
assertEquals("person不能为空", validateList.get(0));
|
||||
} finally {
|
||||
I18nUtils.removeContextLocale();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,22 +34,9 @@
|
||||
<artifactId>disruptor</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
<version>1.0.39_6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -328,10 +315,6 @@
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo</id>
|
||||
<url>file://${project.basedir}/../repo</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<name>SonaType Snapshots</name>
|
||||
|
||||
@@ -19,12 +19,6 @@
|
||||
<dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.fizzgate.plugin.grayrelease;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fizzgate.aggregate.web.filter.AggregateFilter;
|
||||
import com.fizzgate.aggregate.web.loader.ConfigLoader;
|
||||
import com.fizzgate.filter.FilterResult;
|
||||
import com.fizzgate.plugin.FizzPluginFilterChain;
|
||||
import com.fizzgate.plugin.auth.ApiConfig;
|
||||
@@ -141,7 +143,7 @@ public class GrayReleasePluginTests {
|
||||
|
||||
@Test
|
||||
public void aggregateBackendTest() {
|
||||
AggregateFilter aggregateFilter = new AggregateFilter();
|
||||
AggregateFilter aggregateFilter = new AggregateFilter(null, null, null);
|
||||
ConfigLoader configLoader = mock(ConfigLoader.class);
|
||||
when(
|
||||
configLoader.matchAggregateResource("GET", "/_proxytest/bservice/bpath/xxx")
|
||||
|
||||
@@ -245,12 +245,6 @@
|
||||
<dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -98,12 +98,6 @@
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
Binary file not shown.
@@ -1,76 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
<version>1.0.39_6</version>
|
||||
<description>POM was created from install:install-file</description>
|
||||
<name>JsonSchemaValidator</name>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.testversion>1.8</java.testversion>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<version.jackson>2.10.0</version.jackson>
|
||||
<version.slf4j>1.7.25</version.slf4j>
|
||||
<version.common-lang3>3.5</version.common-lang3>
|
||||
<version.joni>2.1.31</version.joni>
|
||||
<version.logback>1.2.3</version.logback>
|
||||
<version.junit>4.12</version.junit>
|
||||
<version.mockito>2.7.21</version.mockito>
|
||||
<version.hamcrest>1.3</version.hamcrest>
|
||||
<version.undertow>2.0.29.Final</version.undertow>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${version.jackson}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${version.slf4j}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${version.common-lang3}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jruby.joni</groupId>
|
||||
<artifactId>joni</artifactId>
|
||||
<version>${version.joni}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${version.logback}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${version.junit}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${version.mockito}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>${version.hamcrest}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.undertow</groupId>
|
||||
<artifactId>undertow-core</artifactId>
|
||||
<version>${version.undertow}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<groupId>com.networknt</groupId>
|
||||
<artifactId>json-schema-validator-i18n-support</artifactId>
|
||||
<versioning>
|
||||
<release>1.0.39_6</release>
|
||||
<versions>
|
||||
<version>1.0.39_6</version>
|
||||
</versions>
|
||||
<lastUpdated>20210430081305</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
||||
Reference in New Issue
Block a user