Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] JSON Schema 校验 required 字段时,字段名称获取错误 #1126

Closed
DangHT opened this issue Feb 19, 2023 · 1 comment
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@DangHT
Copy link
Contributor

DangHT commented Feb 19, 2023

问题描述

JSON Schema 校验 required 字段时,ValidateResult 返回的错误信息字段错误

环境信息

请填写以下信息:

  • OS信息: macos 13.1
  • JDK信息: jdk8
  • 版本信息:fastjson2 2.0.24

重现步骤

  1. 定义 Person Schema
{
    "$schema": "http://json-schema.org/draft/2019-09/schema#",
    "title": "Person",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "id": {
            "type": "integer"
        },
        "name": {
            "type": "string"
        },
        "age": {
            "type": "integer"
        },
        "amount": {
            "type": "number"
        }
    },
    "required": [
        "id",
        "age",
        "amount"
    ]
}
  1. 创建没有缺少 required 字段 amount 的 Person 实例,并进行校验
final File file = new File("src/test/resources/data/person.json");
final String personSchema = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
final JSONSchema jsonSchema = JSONSchema.parseSchema(personSchema);

// create the person without amount property which is required in the person schema.
final Person person = new Person();
person.setId(1);
person.setAge(22);

final ValidateResult result = jsonSchema.validate(person);
System.out.println(result.getMessage());
  1. 返回结果
required property age

期待的正确结果

required property amount

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@DangHT DangHT added the bug Something isn't working label Feb 19, 2023
@wenshao wenshao added this to the 2.0.25 milestone Feb 19, 2023
@wenshao wenshao added the fixed label Feb 20, 2023
@wenshao
Copy link
Member

wenshao commented Mar 12, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.25
问题已修复,请用新版本

@wenshao wenshao closed this as completed Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants