summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/model.py
diff options
context:
space:
mode:
authorsammc@chromium.org <sammc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 05:27:27 +0000
committersammc@chromium.org <sammc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 05:27:27 +0000
commit7f138d4ae1a77eb21fa168639249abf6ac88a30f (patch)
treef96fb0a7c04230ff275077e565df4ceaaca8b59d /tools/json_schema_compiler/model.py
parentf89afc12a8a47abaebce4948ffe1656e06680a39 (diff)
downloadchromium_src-7f138d4ae1a77eb21fa168639249abf6ac88a30f.zip
chromium_src-7f138d4ae1a77eb21fa168639249abf6ac88a30f.tar.gz
chromium_src-7f138d4ae1a77eb21fa168639249abf6ac88a30f.tar.bz2
Docserver: Display enum value descriptions in API docs.
This modifies the json schema to allow both primitive types and dictionaries with properties "name" and optional "description" for enum values. BUG=310454 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=231982 Review URL: https://codereview.chromium.org/39113003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232297 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/model.py')
-rw-r--r--tools/json_schema_compiler/model.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 7507ae7..3de975c 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -141,7 +141,7 @@ class Type(object):
self.ref_type = json['$ref']
elif 'enum' in json and json_type == 'string':
self.property_type = PropertyType.ENUM
- self.enum_values = [value for value in json['enum']]
+ self.enum_values = [EnumValue(value) for value in json['enum']]
elif json_type == 'any':
self.property_type = PropertyType.ANY
elif json_type == 'binary':
@@ -343,6 +343,20 @@ class Property(object):
unix_name = property(GetUnixName, SetUnixName)
+class EnumValue(object):
+ """A single value from an enum.
+ Properties:
+ - |name| name of the property as in the json.
+ - |description| a description of the property (if provided)
+ """
+ def __init__(self, json):
+ if isinstance(json, dict):
+ self.name = json['name']
+ self.description = json.get('description')
+ else:
+ self.name = json
+ self.description = None
+
class _Enum(object):
"""Superclass for enum types with a "name" field, setting up repr/eq/ne.
Enums need to do this so that equality/non-equality work over pickling.