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

schema's "required" keyword cannot handle duplicated properties #608

Closed
eyjian opened this issue Apr 19, 2016 · 0 comments
Closed

schema's "required" keyword cannot handle duplicated properties #608

eyjian opened this issue Apr 19, 2016 · 0 comments
Labels

Comments

@eyjian
Copy link

eyjian commented Apr 19, 2016

对于下列代码,Rapidjson Schema不能正常工作。aaa和bbb两者均是required,但document中设置两个aaa,不设bbb,不报错。但如果将其中一个aaa换成其它的,比如注释中的a则会报required错。

#include <rapidjson/document.h>
#include <rapidjson/schema.h>
#include <rapidjson/stringbuffer.h>

int main()
{
        std::string str = "{\"aaa\":111,\"aaa\":222}"; // "\{\"aaa\":111,\"a\":222}"
#if 0
        std::string schema_str = "{\"type\":\"object\",\"properties\":{\"aaa\":{\"type\":\"integer\"},\"bbb\":{\"type\":\"string\"}},\"required\":[\"aaa\",\"bbb\"]}";
#else
        std::string schema_str = "{\"type\":\"object\",\"properties\":{\"aaa\":{\"type\":\"integer\"},\"bbb\":{\"type\":\"integer\"}},\"required\":[\"aaa\",\"bbb\"]}";
#endif
        printf("%s\n", str.c_str());
        printf("%s\n", schema_str.c_str());

        rapidjson::Document doc;
        rapidjson::Document schema_doc;

        schema_doc.Parse(schema_str.c_str());
        doc.Parse(str.c_str());

        rapidjson::SchemaDocument schema(schema_doc);
        rapidjson::SchemaValidator validator(schema);
        if (doc.Accept(validator))
        {
                printf("data ok\n");
        }
        else
        {
                rapidjson::StringBuffer sb;
                validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);

                printf("Invalid schema: %s\n", sb.GetString());
                printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());

                sb.Clear();
                validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
                printf("Invalid document: %s\n", sb.GetString());
        }

        return 0;
}
@miloyip miloyip added the bug label Apr 19, 2016
@miloyip miloyip changed the title schema不能处理重复的property schema's "required' 不能处理重复的property Apr 19, 2016
@miloyip miloyip changed the title schema's "required' 不能处理重复的property schema's "required" keyword cannot handle duplicated properties Apr 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants