From: Jakub Kicinski <kuba@kernel.org>
To: Rob Herring <robh@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
pabeni@redhat.com, johannes@sipsolutions.net,
stephen@networkplumber.org, ecree.xilinx@gmail.com,
sdf@google.com, f.fainelli@gmail.com, fw@strlen.de,
linux-doc@vger.kernel.org, razor@blackwall.org,
nicolas.dichtel@6wind.com
Subject: Re: [PATCH net-next v3 2/8] netlink: add schemas for YAML specs
Date: Thu, 19 Jan 2023 13:49:22 -0800 [thread overview]
Message-ID: <20230119134922.3fa24ed2@kernel.org> (raw)
In-Reply-To: <CAL_JsqKk5RT6PmRSrq=YK7AvzCbcVkxasykJqe1df=3g-=kD7A@mail.gmail.com>
On Thu, 19 Jan 2023 08:07:31 -0600 Rob Herring wrote:
> On Wed, Jan 18, 2023 at 6:36 PM Jakub Kicinski <kuba@kernel.org> wrote:
> >
> > Add schemas for Netlink spec files. As described in the docs
> > we have 4 "protocols" or compatibility levels, and each one
> > comes with its own schema, but the more general / legacy
> > schemas are superset of more modern ones: genetlink is
> > the smallest followed by genetlink-c and genetlink-legacy.
> > There is no schema for raw netlink, yet, I haven't found the time..
> >
> > I don't know enough jsonschema to do inheritance or something
> > but the repetition is not too bad. I hope.
>
> Generally you put common schemas under '$defs' and the then reference
> them with '$ref'.
>
> $defs:
> some-prop-type:
> type: integer
> minimum: 0
>
> properties:
> foo:
> $ref: '#/$defs/some-prop-type'
> bar:
> $ref: '#/$defs/some-prop-type'
Thanks! Is it possible to move the common definitions to a separate
file? I tried to create a file called defs.yaml and change the ref to:
$ref: "defs.yaml#/$defs/len-or-define"
But:
File "/usr/lib/python3.11/site-packages/jsonschema/validators.py", line 257, in iter_errors
for error in errors:
File "/usr/lib/python3.11/site-packages/jsonschema/_validators.py", line 294, in ref
scope, resolved = validator.resolver.resolve(ref)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/jsonschema/validators.py", line 856, in resolve
return url, self._remote_cache(url)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/jsonschema/validators.py", line 870, in resolve_from_url
raise exceptions.RefResolutionError(exc)
jsonschema.exceptions.RefResolutionError: Expecting value: line 1 column 1 (char 0)
> If you have objects with common sets of properties, you can do the
> same thing, but then you need 'unevaluatedProperties' if you want to
> define a base set of properties and add to them. We do that frequently
> in DT schemas. Unlike typical inheritance, you can't override the
> 'base' schema. It's an AND operation.
This is hard to comprehend :o Most of the time I seem to need only the
ability to add a custom "description" to the object, so for example:
$defs:
len-or-define:
oneOf:
-
type: string
pattern: ^[0-9A-Za-z_-]*( - 1)?$
-
type: integer
minimum: 0
Then:
min-len:
description: Min length for a binary attribute.
$ref: '#/$defs/len-or-define'
And that seems to work. Should I be using unevaluatedProperties somehow
as well here?
> > + description: |
> > + Name used when referring to this space in other definitions, not used outside of YAML.
> > + type: string
> > + # Strictly speaking 'name-prefix' and 'subset-of' should be mutually exclusive.
>
> If one is required:
>
> oneOf:
> - required: [ name-prefix ]
> - required: [ subset-of ]
>
> Or if both are optional:
>
> dependencies:
> name-prefix:
> not:
> required: [ subset-of ]
> subset-of:
> not:
> required: [ name-prefix ]
Nice, let me try this.
> > + min-len:
> > + description: Min length for a binary attribute.
> > + oneOf:
> > + - type: string
> > + pattern: ^[0-9A-Za-z_-]*( - 1)?$
> > + - type: integer
>
> How can a length be a string?
For readability in C I wanted to allow using a define for the length.
Then the name of the define goes here, and the value can be fetched
from the "definitions" section of the spec.
> Anyways, this is something you could pull out into a $defs entry and
> reference. It will also work without the oneOf because 'pattern' will
> just be ignored for an integer. That's one gotcha with json-schema. If
> a keyword doesn't apply to the instance, it is silently ignored. (That
> includes unknown keywords such as ones with typos. Fun!). 'oneOf' will
> give you pretty crappy error messages, so it's good to avoid when
> possible.
Oh, interesting. Changed to:
$defs:
len-or-define:
type: [ string, integer ]
pattern: ^[0-9A-Za-z_-]*( - 1)?$
minimum: 0
next prev parent reply other threads:[~2023-01-20 5:29 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 0:36 [PATCH net-next v3 0/8] Netlink protocol specs Jakub Kicinski
2023-01-19 0:36 ` [PATCH net-next v3 1/8] docs: add more netlink docs (incl. spec docs) Jakub Kicinski
2023-01-19 15:48 ` Vladimir Oltean
2023-01-19 20:29 ` Johannes Berg
2023-01-20 0:23 ` Jacob Keller
2023-01-20 9:10 ` Johannes Berg
2023-01-20 18:35 ` Keller, Jacob E
2023-01-20 2:13 ` Jakub Kicinski
2023-01-20 9:15 ` Johannes Berg
2023-01-20 17:23 ` Jakub Kicinski
2023-01-19 0:36 ` [PATCH net-next v3 2/8] netlink: add schemas for YAML specs Jakub Kicinski
2023-01-19 14:07 ` Rob Herring
2023-01-19 21:49 ` Jakub Kicinski [this message]
2023-01-19 22:24 ` Jakub Kicinski
2023-01-19 23:02 ` Rob Herring
2023-01-20 0:08 ` Jakub Kicinski
2023-01-20 14:43 ` Rob Herring
2023-01-19 0:36 ` [PATCH net-next v3 3/8] net: add basic C code generators for Netlink Jakub Kicinski
2023-01-19 20:53 ` Johannes Berg
2023-01-20 1:53 ` Jakub Kicinski
2023-01-20 9:17 ` Johannes Berg
2023-01-19 0:36 ` [PATCH net-next v3 4/8] netlink: add a proto specification for FOU Jakub Kicinski
2023-01-19 0:36 ` [PATCH net-next v3 5/8] net: fou: regenerate the uAPI from the spec Jakub Kicinski
2023-01-19 0:36 ` [PATCH net-next v3 6/8] net: fou: rename the source for linking Jakub Kicinski
2023-01-19 0:36 ` [PATCH net-next v3 7/8] net: fou: use policy and operation tables generated from the spec Jakub Kicinski
2023-01-19 20:56 ` Johannes Berg
2023-01-20 0:18 ` Jacob Keller
2023-01-20 1:04 ` Jakub Kicinski
2023-01-19 0:36 ` [PATCH net-next v3 8/8] tools: ynl: add a completely generic client Jakub Kicinski
2023-01-20 0:50 ` Jacob Keller
2023-01-19 17:07 ` [PATCH net-next v3 0/8] Netlink protocol specs Stanislav Fomichev
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=20230119134922.3fa24ed2@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=fw@strlen.de \
--cc=johannes@sipsolutions.net \
--cc=linux-doc@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=robh@kernel.org \
--cc=sdf@google.com \
--cc=stephen@networkplumber.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;
as well as URLs for NNTP newsgroup(s).