dependencies between properties of different objects

10 views
Skip to first unread message

Emil Natan

unread,
Mar 22, 2019, 6:26:51 PM3/22/19
to jsonschema - An implementation of JSON Schema for Python
Hello,

I have the following yaml files:

---
products:
  - name: product1
    contact: na...@company.com
    components:
      - name: component1
        contact: na...@company.com
      - name: component2
  - name: product2
    components:
      - name: component3
        contact: na...@company.com

---
products:
  - name: product1
    components:
      - name: component1
  - name: product2
    components:
      - name: component3
        contact: na...@company.com


I want to make sure contact is specified at least once either on project or component level. It is not  explicitly required on either level, but must exist on one of them and can be specified on both. The first yaml file should validate successfully. The second one should fail. I tried to do that using dependencies and if/then, but did not manage to make it work. Any idea if and how can it be done?
Thanks.

Dan Davis

unread,
Mar 25, 2019, 8:31:17 AM3/25/19
to Emil Natan, jsonschema - An implementation of JSON Schema for Python
Emil,

Tthis is supported by Jsonschema DRAFT 4, and maybe not by DRAFT 7 either.  I'm certain you can write could within python-jsonschema to do the validation, but if what you want is to make the requirement clear in a public schema, then you need to change your structure a bit.

What I would suggest is that you elevate "contact" to the top, so that a contact must be present in the whole package.
Then, make contact optional for each product in the list.


--
You received this message because you are subscribed to the Google Groups "jsonschema - An implementation of JSON Schema for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema+...@googlegroups.com.
To post to this group, send email to jsons...@googlegroups.com.

Dan Davis

unread,
Mar 25, 2019, 8:31:38 AM3/25/19
to Emil Natan, jsonschema - An implementation of JSON Schema for Python
I mean't this is NOT supported by DRAFT 4 schema.
Reply all
Reply to author
Forward
0 new messages