δΊ 2013/11/5 21:25, Eric Blake ει:
On 11/04/2013 05:37 PM, Wenchao Xia wrote:
It will check whether the values specfied are wrotten correctly when
s/specfied/specified/
s/wrotten/written/
discriminator is a pre-defined enum type, which help check whether the
schema is in good form.
It is allowed that, not every value in enum is used, so do not check
s/that,/that/
that case.
Why do you allow partial coverage? That feels like an accident waiting
to happen. Does the user get a sane error message if they request an
enum value that wasn't mapped to a union branch? I think it would be
wiser to mandate that if the discriminator is an enum, then the union
must cover all values of the enum.
abort() will be called in qapi-visit.c, it is OK for output visitor,
but bad for input visitor since user input may trigger it. I think
change abort() to error_set() could solve the problem, then we allow
map part of enum value.
+
+# Return the descriminator enum define, if discriminator is specified in
s/descriminator/discriminator/
+# @expr and it is a pre-defined enum type
+def descriminator_find_enum_define(expr):
s/descriminator/discriminator/ - and fix all callers
+ discriminator = expr.get('discriminator')
+ base = expr.get('base')
+
+ # Only support discriminator when base present
+ if not (discriminator and base):
+ return None
+
+ base_fields = find_base_fields(base)
+
+ if not base_fields:
+ sys.stderr.write("Base '%s' is not a valid type\n"
+ % base)
+ sys.exit(1)
+
+ descriminator_type = base_fields.get(discriminator)
s/descriminator/discriminator/