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

dependentSchemas and dependentRequired keywords not implemented #321

Closed
gjvoosten opened this issue Aug 17, 2020 · 9 comments
Closed

dependentSchemas and dependentRequired keywords not implemented #321

gjvoosten opened this issue Aug 17, 2020 · 9 comments

Comments

@gjvoosten
Copy link

From JSON Schema 2019-09, the new keywords dependentSchemas and dependentRequired (replacing dependencies) are not implemented; see https://json-schema.org/draft/2019-09/release-notes.html#semi-incompatible-changes

@stevehu
Copy link
Contributor

stevehu commented Aug 17, 2020

@gjvoosten Thanks a lot for raising it up. Several keywords are not implemented as our team is not using them at the moment. They are in the pipeline though when we have time. If would be great if you and others can take the time to get them implemented.

@kmalski
Copy link
Contributor

kmalski commented Nov 8, 2021

Hi, I have created pull request resolving this issue #479.

@stevehu
Copy link
Contributor

stevehu commented Nov 9, 2021

@gjvoosten, the implementation provided by @kmalski has merged to the master branch already. Once several other pending issues are resolved, we will have a new release. Meanwhile, you can test the new keyword with the master branch code. Thanks @kmalski for your help.

@gjvoosten
Copy link
Author

Hi @stevehu, apologies for the delay in getting back to you. Release 1.0.64 works regarding the way we use dependentSchemas. [But note that we'd also like to use unevaluatedProperties which is part of issue #276 .]

@stevehu
Copy link
Contributor

stevehu commented Nov 17, 2021

@gjvoosten Yes. You are right. That is another keyword we need to implement. Let's see if someone can help. Thanks for the reminder.

@rustermi
Copy link
Contributor

@stevehu is there a list of keywords not yet implemented?

Besides, should dependentRequired work now? Because for me (1.0.66), this test fails:

package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class DependentRequiredTest {
    private ObjectMapper mapper = new ObjectMapper();

    @Test
    public void attributeADependentRequiresB() throws Exception {
        JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
        JsonSchema schema = factory.getSchema("{" +
                "  \"$id\": \"https://example.com/testingErrorCodes.schema.json\"," +
                "  \"$schema\": \"http://json-schema.org/draft-07/schema#\"," +
                "  \"type\": \"object\"," +
                "  \"properties\": {" +
                "    \"a\": {" +
                "      \"type\": \"number\"" +
                "    }," +
                "    \"b\": {" +
                "      \"type\": \"number\"" +
                "    }" +
                "  }," +
                "  \"dependentRequired\": {" +
                "    \"a\": [\"b\"]" +
                "  }" +
                "}");
        JsonNode json = mapper.readTree("{\"a\": 5}");
        Set<ValidationMessage> validationMessages = schema.validate(json);
        assertEquals(1, validationMessages.size());
    }
}

It tries to match the object { "a": 5 } (which is missing "b") against a minimum schema:

{
  "$id": "https://example.com/testingErrorCodes.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "a": {
      "type": "number"
    },
    "b": {
      "type": "number"
    }
  },
  "dependentRequired": {
    "a": ["b"]
  }
}

@stevehu
Copy link
Contributor

stevehu commented Feb 15, 2022

@rustermi The keyword is implemented and passed the official test suite. I am not very familiar with the keyword as I haven't used it yet. I am wondering if you could create a test case and debug it into the validator to see why it fails. Thanks.

@rustermi
Copy link
Contributor

We currently don't use the keyword either. When we do, I will follow your proposal.

@stevehu
Copy link
Contributor

stevehu commented Mar 17, 2022

@rustermi Thanks for your response. I will close this issue for now and will reopen it if needed.

@stevehu stevehu closed this as completed Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants