public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@bootlin.com>
To: Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org
Subject: Re: JSON schema and conditions
Date: Thu, 17 Jan 2019 15:35:10 +0100	[thread overview]
Message-ID: <20190117143510.3vmmxh2vc6mlp5i4@flea> (raw)
In-Reply-To: <CAL_JsqKOng2g7+3FVx5cU99C-KJpvbJyfRxJCdm1aoCBsK1Rfg@mail.gmail.com>

Hi Rob,

Thanks for you answer :)

On Wed, Jan 16, 2019 at 02:50:09PM -0600, Rob Herring wrote:
> On Wed, Jan 16, 2019 at 1:18 PM Maxime Ripard <maxime.ripard@bootlin.com> wrote:
> >
> > Hi,
> >
> > I've started playing a bit with the schemas, and one thing I cannot
> > wrap my head around at the moment is how to express things like one
> > property being required only by one compatible over a couple expressed
> > in the binding document.
> >
> > Things like a reset property only being required for one particular SoC
> > for example.
> >
> > Looking at the current examples, I could see two solutions, one where
> > we could condition a dependency on a propery value, and the other
> > where we could inherit another schema and just add more constraints.
> >
> > I haven't found a way to find either though. Is it covered currently?
> 
> There's not really a concise way of saying 'if compatible is X, then
> apply these constraints else these other constraints'. The only way
> I've figured out how to do it is with a whole other section in the
> schema:
> 
> oneOf:
>   - properties:
>       compatible:
>         contains:
>           enum: [ a-compatible-to-match ]
>       resets: true
>     required:
>       - resets
>       - compatible
> 
> This would be in addition to the main schema. I think this would
> become bloated and hard to read/maintain, so I don't think we should
> go with this approach.

Yeah, I'm with you on that one. Speaking of which, I've seen that
resets: true on a number of your patches, without getting exactly what
it's supposed to mean. Is that because you want to use the schemas
already defined for these?

> I'm hoping this gets addressed in the json-schema spec as there's
> some discussion of a '$data' keyword and data dependent schemas.

Ok

> Including/inheriting another schema can be done with "allOf: [ {$ref:
> path/to/base/schema} ]". I'm currently using this for providers such
> as clock or reset providers and for buses. This works well for
> inheriting schemas which are collections of properties. See the GIC
> conversions to json-schema I posted for an example. The main issue
> with this approach that I've found is you have to list all the
> inherited properties to make them required or if you have
> 'addtionalProperties: false' (which is desirable IMO).
> 
> If there's a lot of conditionals, there may not be much left common to
> inherit and we may just want to split each compatible into a separate
> doc. I'm also fine with leaving those constraints as comments or
> description for now. That's no worse than what we have today.
> 
> Note that so far, all the $ref values pointing to other files get
> resolved to files in the yaml-bindings repo schemas. I don't think a
> ref from the kernel tree to the kernel tree works currently. I need to
> sort that out.

Yeah, I've tried that already, and it indeed looks like it always try
to look them up on your github repo (or the local cache), but will not
try to locate it in the kernel tree.

Thanks!
Maxime

-- 
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2019-01-17 14:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 14:59 JSON schema and conditions Maxime Ripard
2019-01-16 20:50 ` Rob Herring
2019-01-17 14:35   ` Maxime Ripard [this message]
2019-01-18 17:57     ` Rob Herring
2019-01-29 21:19       ` Maxime Ripard
2019-01-29 22:25         ` Rob Herring
2019-02-04 15:45           ` Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190117143510.3vmmxh2vc6mlp5i4@flea \
    --to=maxime.ripard@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox