From: Ian Campbell Subject: Re: [PATCH V4 11/24] libxl/gentypes.py: include discriminator in JSON output Date: Wed, 7 May 2014 11:45:11 +0100 Message-ID: <1399459511.11832.5.camel@kazak.uk.xensource.com> References: <1398949101-23320-1-git-send-email-wei.liu2@citrix.com> <1398949101-23320-12-git-send-email-wei.liu2@citrix.com> <1399381429.3014.124.camel@kazak.uk.xensource.com> <20140506130913.GG17067@zion.uk.xensource.com> <1399456826.3014.239.camel@kazak.uk.xensource.com> <20140507103544.GC17067@zion.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20140507103544.GC17067@zion.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Wed, 2014-05-07 at 11:35 +0100, Wei Liu wrote: > On Wed, May 07, 2014 at 11:00:26AM +0100, Ian Campbell wrote: > > On Tue, 2014-05-06 at 14:09 +0100, Wei Liu wrote: > > > On Tue, May 06, 2014 at 02:03:49PM +0100, Ian Campbell wrote: > > > > On Thu, 2014-05-01 at 13:58 +0100, Wei Liu wrote: > > > > > Parser relies on the discriminator to go to correct branch. > > > > > > > > > > Signed-off-by: Wei Liu > > > > > > > > Acked-by: Ian Campbell > > > > > > > > But, an idea: What about calling the field which refers to the union by > > > > it's discriminated name, i.e. "u.pv": { map of things } instead of > > > > "type": "pv", "u" { map of things } ? > > > > > But that breaks API, doesn't it? > > > > Doh, yes. > > > > > If we can safely assume that there's no > > > existing user of this JSON API, changing it won't be hard. > > > > Is it even possible to sanely use things as they are? The existence of > > this patch would seem to suggest not? > > > > There's actual a horrible way to hack around current implementation: if > you calculate the intersection of those fields in "pv" and "hvm" you can > actually discriminate things. Not sure if a sane person would do it > though! I think it is a pretty safe bet noone is doing this! (or at least they probably have no illusions about it being sane!) > However I would rather stay on the safe side. I'm leaning towards we change this, although rather than "u.pv" as I suggested earlier I think "type.pv" (so "discriminator field name"."enum name") would be better. Ian.