Re: [Json] Another problematic JSON Schema use-case

Austin William Wright <aaa@bzfx.net> Tue, 24 May 2016 01:30 UTC

Return-Path: <aaa@bzfx.net>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0A13812DBB4 for <json@ietfa.amsl.com>; Mon, 23 May 2016 18:30:33 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.7
X-Spam-Level:
X-Spam-Status: No, score=-2.7 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=bzfx.net
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 88vyfBSyZ1Ie for <json@ietfa.amsl.com>; Mon, 23 May 2016 18:30:31 -0700 (PDT)
Received: from mail-qg0-x22f.google.com (mail-qg0-x22f.google.com [IPv6:2607:f8b0:400d:c04::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id DE25212DC17 for <json@ietf.org>; Mon, 23 May 2016 18:30:30 -0700 (PDT)
Received: by mail-qg0-x22f.google.com with SMTP id f92so1144012qgf.0 for <json@ietf.org>; Mon, 23 May 2016 18:30:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bzfx.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5hoHYNEUI8RfKTcJET11XI7dNVFiHhR1vlxh9+E1uDY=; b=oezSIFp0WcqgKxG6HdNkYGXAEEYfVwPEy97aldRpdp/10y7EQHzz5D/eI8IEtuJui6 DFlX9ArmZqgLK/QsQAU8pyj0q4rsSICIDFC0GNaZiaurkAoXqYGlorfJOE/ll6zdhqaL 2beh1fvnzoCYtLBXP+ztHSfQ3lfrpMqPd7n/Y=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5hoHYNEUI8RfKTcJET11XI7dNVFiHhR1vlxh9+E1uDY=; b=MV3lC83J2pzy1tHzlm/ElM8l1D/4CLGu4SHIkxPwTyNMDLsz2ugCvW3lfXZfzv4He6 pWVwR7p/TArYKgRt+SDhDfoTLstEhcOjwuxA2wF2qMBwzFlZElnqW9Wg1jVJUultAqTX 95oVH719X6pPuo47yQcIPFvm75wd+qQ2imxltqyZbQW5la2caa7cAqA9Klosd7MbcOGY wiRZbMdCU0q2WLAMQWrHUW/bFclFkZlV/pzdRmhUZSsJVRVvzC3A6Ew27QawfzhZeQH9 vZQmsz53xVPQkuhfvHS3I11EszeRmpZE8JHOi/6NJKJfVPjT4vEURrMdWWhSaoJCFljW vUog==
X-Gm-Message-State: ALyK8tIwkDxHm4rw0K8lHCnndxeAwj4Y/87fH22ZFMEdgpPW5Q6fH/3TsaCM3ZbXkjkHiTamd9qt9n9oc0W4bA==
X-Received: by 10.140.92.37 with SMTP id a34mr987126qge.88.1464053429858; Mon, 23 May 2016 18:30:29 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.55.80.85 with HTTP; Mon, 23 May 2016 18:30:15 -0700 (PDT)
In-Reply-To: <CAHBU6ivd5JJ7Hx_JtNPSnW40jXzEF1Yr7=rwuZzGnFrRoMphbg@mail.gmail.com>
References: <CAHBU6ivd5JJ7Hx_JtNPSnW40jXzEF1Yr7=rwuZzGnFrRoMphbg@mail.gmail.com>
From: Austin William Wright <aaa@bzfx.net>
Date: Mon, 23 May 2016 18:30:15 -0700
Message-ID: <CANkuk-WppF4WgeZc5OX2-tozmCd+eYtPwFgmDtoiJHxwdSjDzw@mail.gmail.com>
To: Tim Bray <tbray@textuality.com>
Content-Type: multipart/alternative; boundary="001a1139baf29e8d1a05338c80a8"
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/WwWz2syvDLljU3FDtY20MXIITfg>
Cc: "json@ietf.org" <json@ietf.org>
Subject: Re: [Json] Another problematic JSON Schema use-case
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 24 May 2016 01:30:33 -0000

This is a problem that I tried working on a year or two ago, but couldn't
find any good resolution to.

Let's create a JSON Schema for the described problem (slightly
modified/expanded for illustration below):

{
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {"Type":{"enum":["Animal", "Vegetable", "Mineral"]}},
"required": ["Type"],
"oneOf": [
{
"properties": {
"Type":{"enum":["Animal"]},
"Thermoregulation":{"enum":["Endotherm", "Ectotherm"]}
},
"required": ["Thermoregulation"]
},
{
"properties": {
"Type":{"enum":["Vegetable"]},
"Organic":{"type":"number"}
},
"required": ["Organic"]
},
{
"properties": {
"Type":{"enum":["Mineral"]},
"Organic":{"type":"boolean"}
},
"required": ["Organic"]
}
]
}
}

Here's a valid instance for illustration:

{
"o1": {
"Type": "Animal",
"Thermoregulation": "Endotherm",
"Species": "Felis catus",
"Label": "cat"
},
"o2": {
"Type": "Mineral",
"Organic": false,
"Label": "Quartz"
}
}

This, however, is an invalid instance:

{
"o3": {
"Type": "Vegetable",
"Endotherm": true,
"Label": "Silver"
}
}

What sort of error would be appropriate here? (E.g. Is this a typo for the
"Type" property? Or is this just missing a required "Organic" property?)

When I run it through my validator, I get this error:

(1 of 1) instance.o3 is not exactly one from <http://example.org/Animal>,<
http://example.org/Vegetable>,<http://example.org/Mineral>

And within all three schemas, exactly one constraint fails. So which one do
we suggest errors for? Changing 'Vegetable' to 'Animal', and changing
'Endotherm' to 'Organic' are all equally reasonable (to a computer)
one-word fixes.

In general, JSON Schema and many other schemas are designed to ensure
things are valid. They're not well engineered to help people fix things
when they're invalid.

A similar problem is that localizing error strings. There's a few
suggestions to add custom error strings to JSON Schema, but then we have
the problem that they're not localized. If we allow multiple strings (one
per localization), then we have to update the schema every time we add a
locale, which means changing the file even though nothing about the schema
has changed.

I just created <
https://github.com/json-schema-org/json-schema-spec/issues/31> to look at
this problem as it relates to JSON Schema.

Cheers,

Austin Wright.


On Sun, May 22, 2016 at 11:15 AM, Tim Bray <tbray@textuality.com> wrote:

> See https://www.tbray.org/ongoing/When/201x/2016/05/22/Json-Schema-Gripe
>
>
>
> _______________________________________________
> json mailing list
> json@ietf.org
> https://www.ietf.org/mailman/listinfo/json
>
>