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

It will match 2 schemas if the field is null when $ref definitions schema #244

Open
ke-liang opened this issue Nov 2, 2017 · 0 comments

Comments

@ke-liang
Copy link

ke-liang commented Nov 2, 2017

Hello,
I use the rest-assured and encounter the issue about json-schema-validator, could you please help me resolve this issue below?

  1. define a definitionsSchema.json like below
    { "$schema": "http://json-schema.org/draft-04/schema#", "title": "BasicChargeAndOrderSchema", "description": "定义一些用于校验 charge/order 的基本 schema", "balanceBonus": { "properties": { "id": { "type": "string", "pattern": "^65[0-9]{22}$" } } }, "recharge": { "properties": { "balance_bonus": { "oneOf": [ { "type": "object", "$ref": "#/balanceBonus" }, { "type": "null" } ] } } } }
    2.define rechargeCreateSchema.json that will be used to validate the json file
    { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Recharge创建", "description": "此 schema 用于校验 recharge 的创建", "type": "object", "allOf": [ { "$ref": "definitionsSchema.json#/recharge" } ] }
    3.validator the json below
    { "balance_bonus": null }
    Actual Result: failed! because it ["matched":2,"nrSchemas":2]

Response body doesn't match expectation.
Expected: The content to match the given JSON schema.
error: instance failed to match all required schemas (matched only 0 out of 1)
level: "error"
schema: {"loadingURI":"file:/schemas/rechargeCreateSchema.json#","pointer":""}
instance: {"pointer":""}
domain: "validation"
keyword: "allOf"
matched: 0
nrSchemas: 1
reports: {"/allOf/0":[{"level":"error","schema":{"loadingURI":"file://schemas/definitionsSchema.json#","pointer":"/recharge/properties/balance_bonus"},"instance":{"pointer":"/balance_bonus"},"domain":"validation","keyword":"oneOf","message":"instance failed to match exactly one schema (matched 2 out of 2)","matched":2,"nrSchemas":2,"reports":{"/recharge/properties/balance_bonus/oneOf/0":[],"/recharge/properties/balance_bonus/oneOf/1":[]}}]}

Other info:
If the "balance_bonus" is not null, that's ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant