summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 06:38:29 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 06:38:29 +0000
commite685143bd7d15b048b7ca9cb4ec0240827842266 (patch)
tree74f100269c45c656a554a794d4e63749b91fe026
parent7a29680b81b983ac1da1b5fdbe3ad096bad7015a (diff)
downloadchromium_src-e685143bd7d15b048b7ca9cb4ec0240827842266.zip
chromium_src-e685143bd7d15b048b7ca9cb4ec0240827842266.tar.gz
chromium_src-e685143bd7d15b048b7ca9cb4ec0240827842266.tar.bz2
Revert 231982 "Docserver: Display enum value descriptions in API..."
"JsonSchemaTest.TestEnum" started failing on Windows bot after this change. > 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 > > Review URL: https://codereview.chromium.org/39113003 TBR=sammc@chromium.org Review URL: https://codereview.chromium.org/47403003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232016 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/docs/server2/api_data_source.py6
-rw-r--r--chrome/common/extensions/docs/server2/app.yaml2
-rw-r--r--chrome/common/extensions/docs/server2/cron.yaml2
-rw-r--r--chrome/common/extensions/docs/templates/private/enum_descriptions.html16
-rw-r--r--chrome/common/extensions/docs/templates/private/property.html1
-rw-r--r--chrome/common/extensions/docs/templates/private/type.html1
-rw-r--r--chrome/renderer/resources/extensions/json_schema.js9
-rw-r--r--chrome/test/data/extensions/json_schema_test.js7
-rw-r--r--components/json_schema/json_schema_validator.cc25
-rw-r--r--components/json_schema/json_schema_validator_unittest.cc10
-rw-r--r--components/test/data/json_schema/enum_schema.json2
-rw-r--r--tools/json_schema_compiler/cc_generator.py8
-rw-r--r--tools/json_schema_compiler/cpp_type_generator.py2
-rw-r--r--tools/json_schema_compiler/idl_schema.py8
-rwxr-xr-xtools/json_schema_compiler/idl_schema_test.py10
-rw-r--r--tools/json_schema_compiler/model.py16
-rw-r--r--tools/json_schema_compiler/test/idl_basics.idl1
17 files changed, 22 insertions, 104 deletions
diff --git a/chrome/common/extensions/docs/server2/api_data_source.py b/chrome/common/extensions/docs/server2/api_data_source.py
index e1655d1..a8147e9 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -326,9 +326,9 @@ class _JSCModel(object):
elif type_.property_type == model.PropertyType.ARRAY:
dst_dict['array'] = self._GenerateType(type_.item_type)
elif type_.property_type == model.PropertyType.ENUM:
- dst_dict['enum_values'] = [
- {'name': value.name, 'description': value.description}
- for value in type_.enum_values]
+ dst_dict['enum_values'] = []
+ for enum_value in type_.enum_values:
+ dst_dict['enum_values'].append({'name': enum_value})
if len(dst_dict['enum_values']) > 0:
dst_dict['enum_values'][-1]['last'] = True
elif type_.instance_of is not None:
diff --git a/chrome/common/extensions/docs/server2/app.yaml b/chrome/common/extensions/docs/server2/app.yaml
index c31cc06..da6d5fe5 100644
--- a/chrome/common/extensions/docs/server2/app.yaml
+++ b/chrome/common/extensions/docs/server2/app.yaml
@@ -1,5 +1,5 @@
application: chrome-apps-doc
-version: 2-33-0
+version: 2-32-10
runtime: python27
api_version: 1
threadsafe: false
diff --git a/chrome/common/extensions/docs/server2/cron.yaml b/chrome/common/extensions/docs/server2/cron.yaml
index c77e536..d8c9f9e 100644
--- a/chrome/common/extensions/docs/server2/cron.yaml
+++ b/chrome/common/extensions/docs/server2/cron.yaml
@@ -2,4 +2,4 @@ cron:
- description: Repopulates all cached data.
url: /_cron
schedule: every 5 minutes
- target: 2-33-0
+ target: 2-32-10
diff --git a/chrome/common/extensions/docs/templates/private/enum_descriptions.html b/chrome/common/extensions/docs/templates/private/enum_descriptions.html
deleted file mode 100644
index f67e23e..0000000
--- a/chrome/common/extensions/docs/templates/private/enum_descriptions.html
+++ /dev/null
@@ -1,16 +0,0 @@
-{{?values}}
-<dl>
- {{#values}}
- {{?description}}
- <dd>
- <dl>
- <dt>{{name}}</dt>
- <dd>
- {{description}}
- </dd>
- </dl>
- </dd>
- {{/description}}
- {{/values}}
-</dl>
-{{/values}}
diff --git a/chrome/common/extensions/docs/templates/private/property.html b/chrome/common/extensions/docs/templates/private/property.html
index d7eef71..782a402 100644
--- a/chrome/common/extensions/docs/templates/private/property.html
+++ b/chrome/common/extensions/docs/templates/private/property.html
@@ -10,7 +10,6 @@
{{?description}}<dd>
{{{description}}}
</dd>{{/description}}
-{{+partials.enum_descriptions values:enum_values}}
{{?array.is_object}}
<h4>Properties of each item</h4>
{{+partials.type @:array}}
diff --git a/chrome/common/extensions/docs/templates/private/type.html b/chrome/common/extensions/docs/templates/private/type.html
index f99dad8..250a22c 100644
--- a/chrome/common/extensions/docs/templates/private/type.html
+++ b/chrome/common/extensions/docs/templates/private/type.html
@@ -19,7 +19,6 @@
{{?description}}
<dd>{{{description}}}</dd>
{{/description}}
- {{+partials.enum_descriptions values:enum_values}}
{{?properties}}
{{+partials.type_item title:strings.properties
display_name:display_name
diff --git a/chrome/renderer/resources/extensions/json_schema.js b/chrome/renderer/resources/extensions/json_schema.js
index 3c6f394..4b8996a 100644
--- a/chrome/renderer/resources/extensions/json_schema.js
+++ b/chrome/renderer/resources/extensions/json_schema.js
@@ -53,10 +53,6 @@ function isOptionalValue(value) {
return typeof(value) === 'undefined' || value === null;
}
-function enumToString(enumValue) {
- return enumValue.name || enumValue;
-}
-
/**
* Validates an instance against a schema and accumulates errors. Usage:
*
@@ -321,12 +317,11 @@ JSONSchemaValidator.prototype.validateChoices =
*/
JSONSchemaValidator.prototype.validateEnum = function(instance, schema, path) {
for (var i = 0; i < schema.enum.length; i++) {
- if (instance === enumToString(schema.enum[i]))
+ if (instance === schema.enum[i])
return true;
}
- this.addError(path, "invalidEnum",
- [schema.enum.map(enumToString).join(", ")]);
+ this.addError(path, "invalidEnum", [schema.enum.join(", ")]);
return false;
};
diff --git a/chrome/test/data/extensions/json_schema_test.js b/chrome/test/data/extensions/json_schema_test.js
index cf61c8b..efbd16e 100644
--- a/chrome/test/data/extensions/json_schema_test.js
+++ b/chrome/test/data/extensions/json_schema_test.js
@@ -138,17 +138,16 @@ function testComplex() {
function testEnum() {
var schema = {
- enum: [{"name": "foo"}, 42, false]
+ enum: ["foo", 42, false]
};
assertValid("", "foo", schema);
assertValid("", 42, schema);
assertValid("", false, schema);
- var enum_values = ["foo", 42, false];
assertNotValid("", "42", schema, [formatError("invalidEnum",
- [enum_values.join(", ")])]);
+ [schema.enum.join(", ")])]);
assertNotValid("", null, schema, [formatError("invalidEnum",
- [enum_values.join(", ")])]);
+ [schema.enum.join(", ")])]);
}
function testChoices() {
diff --git a/components/json_schema/json_schema_validator.cc b/components/json_schema/json_schema_validator.cc
index 3cc9e2b..3816a76 100644
--- a/components/json_schema/json_schema_validator.cc
+++ b/components/json_schema/json_schema_validator.cc
@@ -53,18 +53,6 @@ bool CompareToString(const ExpectedType& entry, const std::string& key) {
return entry.key < key;
}
-// If |value| is a dictionary, returns the "name" attribute of |value| or NULL
-// if |value| does not contain a "name" attribute. Otherwise, returns |value|.
-const base::Value* ExtractNameFromDictionary(const base::Value* value) {
- const base::DictionaryValue* value_dict = NULL;
- const base::Value* name_value = NULL;
- if (value->GetAsDictionary(&value_dict)) {
- value_dict->Get("name", &name_value);
- return name_value;
- }
- return value;
-}
-
bool IsValidSchema(const base::DictionaryValue* dict, std::string* error) {
// This array must be sorted, so that std::lower_bound can perform a
// binary search.
@@ -207,13 +195,6 @@ bool IsValidSchema(const base::DictionaryValue* dict, std::string* error) {
for (size_t i = 0; i < list_value->GetSize(); ++i) {
const base::Value* value = NULL;
list_value->Get(i, &value);
- // Sometimes the enum declaration is a dictionary with the enum value
- // under "name".
- value = ExtractNameFromDictionary(value);
- if (!value) {
- *error = "Invalid value in enum attribute";
- return false;
- }
switch (value->GetType()) {
case base::Value::TYPE_NULL:
case base::Value::TYPE_BOOLEAN:
@@ -498,12 +479,6 @@ void JSONSchemaValidator::ValidateEnum(const base::Value* instance,
for (size_t i = 0; i < choices->GetSize(); ++i) {
const base::Value* choice = NULL;
CHECK(choices->Get(i, &choice));
- // Sometimes the enum declaration is a dictionary with the enum value under
- // "name".
- choice = ExtractNameFromDictionary(choice);
- if (!choice) {
- NOTREACHED();
- }
switch (choice->GetType()) {
case base::Value::TYPE_NULL:
case base::Value::TYPE_BOOLEAN:
diff --git a/components/json_schema/json_schema_validator_unittest.cc b/components/json_schema/json_schema_validator_unittest.cc
index 6372032..4844ed1 100644
--- a/components/json_schema/json_schema_validator_unittest.cc
+++ b/components/json_schema/json_schema_validator_unittest.cc
@@ -77,16 +77,10 @@ TEST(JSONSchemaValidator, IsValidSchema) {
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": \"string\","
- " \"enum\": [ {} ]" // "enum" dict values must contain "name".
+ " \"enum\": [ {} ]," // "enum" must contain simple values.
"}", &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
- " \"type\": \"string\","
- " \"enum\": [ { \"name\": {} } ]" // "enum" name must be a simple value.
- "}",
- &error));
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
- "{"
" \"type\": \"array\","
" \"items\": [ 123 ]," // "items" must contain a schema or schemas.
"}", &error));
@@ -112,7 +106,7 @@ TEST(JSONSchemaValidator, IsValidSchema) {
" },"
" \"enum-property\": {"
" \"type\": \"integer\","
- " \"enum\": [0, 1, {\"name\": 10}, 100]"
+ " \"enum\": [0, 1, 10, 100]"
" },"
" \"items-property\": {"
" \"type\": \"array\","
diff --git a/components/test/data/json_schema/enum_schema.json b/components/test/data/json_schema/enum_schema.json
index efb68de..ae0c12a 100644
--- a/components/test/data/json_schema/enum_schema.json
+++ b/components/test/data/json_schema/enum_schema.json
@@ -1,3 +1,3 @@
{
- "enum": ["foo", 42, {"name": false, "description": "a false value"}]
+ "enum": ["foo", 42, false]
}
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index 371c60d..9935e1c 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -784,9 +784,7 @@ class _Generator(object):
self._type_helper.GetEnumNoneValue(type_)))
.Concat(self._GenerateError(
'\"\'%%(key)s\': expected \\"' +
- '\\" or \\"'.join(
- enum_value.name
- for enum_value in self._type_helper.FollowRef(type_).enum_values) +
+ '\\" or \\"'.join(self._type_helper.FollowRef(type_).enum_values) +
'\\", got \\"" + %s + "\\""' % enum_as_string))
.Append('return %s;' % failure_value)
.Eblock('}')
@@ -822,7 +820,7 @@ class _Generator(object):
c.Sblock('switch (enum_param) {')
for enum_value in self._type_helper.FollowRef(type_).enum_values:
(c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value))
- .Append(' return "%s";' % enum_value.name))
+ .Append(' return "%s";' % enum_value))
(c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_))
.Append(' return "";')
.Eblock('}')
@@ -850,7 +848,7 @@ class _Generator(object):
# This is broken up into all ifs with no else ifs because we get
# "fatal error C1061: compiler limit : blocks nested too deeply"
# on Windows.
- (c.Append('if (enum_string == "%s")' % enum_value.name)
+ (c.Append('if (enum_string == "%s")' % enum_value)
.Append(' return %s;' %
self._type_helper.GetEnumValue(type_, enum_value)))
(c.Append('return %s;' % self._type_helper.GetEnumNoneValue(type_))
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
index d485b46..4c0306d 100644
--- a/tools/json_schema_compiler/cpp_type_generator.py
+++ b/tools/json_schema_compiler/cpp_type_generator.py
@@ -65,7 +65,7 @@ class CppTypeGenerator(object):
e.g VAR_STRING
"""
value = '%s_%s' % (self.FollowRef(type_).unix_name.upper(),
- cpp_util.Classname(enum_value.name.upper()))
+ cpp_util.Classname(enum_value.upper()))
# To avoid collisions with built-in OS_* preprocessor definitions, we add a
# trailing slash to enum names that start with OS_.
if value.startswith("OS_"):
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py
index 238fb05..e33f8f0 100644
--- a/tools/json_schema_compiler/idl_schema.py
+++ b/tools/json_schema_compiler/idl_schema.py
@@ -292,13 +292,7 @@ class Enum(object):
enum = []
for node in self.node.children:
if node.cls == 'EnumItem':
- enum_value = {'name': node.GetName()}
- for child in node.children:
- if child.cls == 'Comment':
- enum_value['description'] = ProcessComment(child.GetName())[0]
- else:
- raise ValueError('Did not process %s %s' % (child.cls, child))
- enum.append(enum_value)
+ enum.append(node.GetName())
elif node.cls == 'Comment':
self.description = ProcessComment(node.GetName())[0]
else:
diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py
index 0840058..e0c987e 100755
--- a/tools/json_schema_compiler/idl_schema_test.py
+++ b/tools/json_schema_compiler/idl_schema_test.py
@@ -77,9 +77,7 @@ class IdlSchemaTest(unittest.TestCase):
def testEnum(self):
schema = self.idl_basics
- expected = {'enum': [{'name': 'name1', 'description': 'comment1'},
- {'name': 'name2'}],
- 'description': 'Enum description',
+ expected = {'enum': ['name1', 'name2'], 'description': 'Enum description',
'type': 'string', 'id': 'EnumType'}
self.assertEquals(expected, getType(schema, expected['id']))
@@ -164,12 +162,10 @@ class IdlSchemaTest(unittest.TestCase):
schema = idl_schema.Load('test/idl_reserved_words.idl')[0]
foo_type = getType(schema, 'Foo')
- self.assertEquals([{'name': 'float'}, {'name': 'DOMString'}],
- foo_type['enum'])
+ self.assertEquals(['float', 'DOMString'], foo_type['enum'])
enum_type = getType(schema, 'enum')
- self.assertEquals([{'name': 'callback'}, {'name': 'namespace'}],
- enum_type['enum'])
+ self.assertEquals(['callback', 'namespace'], enum_type['enum'])
dictionary = getType(schema, 'dictionary')
self.assertEquals('integer', dictionary['properties']['long']['type'])
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 3de975c..7507ae7 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 = [EnumValue(value) for value in json['enum']]
+ self.enum_values = [value for value in json['enum']]
elif json_type == 'any':
self.property_type = PropertyType.ANY
elif json_type == 'binary':
@@ -343,20 +343,6 @@ 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.
diff --git a/tools/json_schema_compiler/test/idl_basics.idl b/tools/json_schema_compiler/test/idl_basics.idl
index 05b09c5..08d369c 100644
--- a/tools/json_schema_compiler/test/idl_basics.idl
+++ b/tools/json_schema_compiler/test/idl_basics.idl
@@ -7,7 +7,6 @@
[internal] namespace idl_basics {
// Enum description
enum EnumType {
- // comment1
name1,
name2
};