Commit 44591cc2 authored by Sam Thorogood's avatar Sam Thorogood Committed by Chromium LUCI CQ

Add nodoc property to model types.

This will later be used by a TSDoc generator.

See https://github.com/GoogleChrome/developer.chrome.com/issues/61 for more context.

Bug: N/A
Change-Id: Id62ca4b340297b3e89705ba03d3fb5cd7caff093
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596901
Commit-Queue: Sam Thorogood <thorogood@google.com>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839536}
parent c7d00ca7
...@@ -127,6 +127,7 @@ class Namespace(object): ...@@ -127,6 +127,7 @@ class Namespace(object):
'on the API summary page.' % self.name) 'on the API summary page.' % self.name)
json['description'] = '' json['description'] = ''
self.description = json['description'] self.description = json['description']
self.nodoc = json.get('nodoc', False)
self.deprecated = json.get('deprecated', None) self.deprecated = json.get('deprecated', None)
self.unix_name = UnixName(self.name) self.unix_name = UnixName(self.name)
self.source_file = source_file self.source_file = source_file
...@@ -217,6 +218,7 @@ class Type(object): ...@@ -217,6 +218,7 @@ class Type(object):
self.unix_name = UnixName(self.name) self.unix_name = UnixName(self.name)
self.description = json.get('description', None) self.description = json.get('description', None)
self.jsexterns = json.get('jsexterns', None) self.jsexterns = json.get('jsexterns', None)
self.nodoc = json.get('nodoc', False)
# Copy the Origin and override the |from_manifest_keys| value as necessary. # Copy the Origin and override the |from_manifest_keys| value as necessary.
# We need to do this to ensure types reference by manifest types have the # We need to do this to ensure types reference by manifest types have the
...@@ -364,6 +366,7 @@ class Function(object): ...@@ -364,6 +366,7 @@ class Function(object):
self.supports_listeners = options.get('supportsListeners', True) self.supports_listeners = options.get('supportsListeners', True)
self.supports_rules = options.get('supportsRules', False) self.supports_rules = options.get('supportsRules', False)
self.supports_dom = options.get('supportsDom', False) self.supports_dom = options.get('supportsDom', False)
self.nodoc = json.get('nodoc', False)
def GeneratePropertyFromParam(p): def GeneratePropertyFromParam(p):
return Property(self, p['name'], p, namespace, origin) return Property(self, p['name'], p, namespace, origin)
...@@ -479,6 +482,7 @@ class Property(object): ...@@ -479,6 +482,7 @@ class Property(object):
self.optional = json.get('optional', None) self.optional = json.get('optional', None)
self.instance_of = json.get('isInstanceOf', None) self.instance_of = json.get('isInstanceOf', None)
self.deprecated = json.get('deprecated') self.deprecated = json.get('deprecated')
self.nodoc = json.get('nodoc', False)
# HACK: only support very specific value types. # HACK: only support very specific value types.
is_allowed_value = ( is_allowed_value = (
......
...@@ -40,9 +40,17 @@ class ModelTest(unittest.TestCase): ...@@ -40,9 +40,17 @@ class ModelTest(unittest.TestCase):
'path/to/idl_namespace_non_specific_platforms.idl') 'path/to/idl_namespace_non_specific_platforms.idl')
self.idl_namespace_non_specific_platforms = self.model.namespaces.get( self.idl_namespace_non_specific_platforms = self.model.namespaces.get(
'idl_namespace_non_specific_platforms') 'idl_namespace_non_specific_platforms')
self.nodoc_json = CachedLoad('test/namespace_nodoc.json')
self.model.AddNamespace(self.nodoc_json[0],
'path/to/namespace_nodoc.json')
self.nodoc = self.model.namespaces.get('nodoc')
self.fakeapi_json = CachedLoad('test/namespace_fakeapi.json')
self.model.AddNamespace(self.fakeapi_json[0],
'path/to/namespace_fakeapi.json')
self.fakeapi = self.model.namespaces.get('fakeapi')
def testNamespaces(self): def testNamespaces(self):
self.assertEquals(6, len(self.model.namespaces)) self.assertEquals(8, len(self.model.namespaces))
self.assertTrue(self.permissions) self.assertTrue(self.permissions)
def testHasFunctions(self): def testHasFunctions(self):
...@@ -144,5 +152,26 @@ class ModelTest(unittest.TestCase): ...@@ -144,5 +152,26 @@ class ModelTest(unittest.TestCase):
self.assertEqual(None, self.assertEqual(None,
self.idl_namespace_non_specific_platforms.platforms) self.idl_namespace_non_specific_platforms.platforms)
def testHasNoDoc(self):
fakeapi_NoDocType = self.fakeapi.types['NoDocType']
self.assertTrue(fakeapi_NoDocType.nodoc)
fakeapi_FakeType = self.fakeapi.types['FakeType']
selected_property = fakeapi_FakeType.properties['nodocProperty']
self.assertTrue(selected_property.nodoc)
nodocMethod_method = self.fakeapi.functions['nodocMethod']
self.assertTrue(nodocMethod_method.nodoc)
onFooNoDoc_event = self.fakeapi.events['onFooNoDoc']
self.assertTrue(onFooNoDoc_event.nodoc)
onFoo_event = self.fakeapi.events['onFoo']
self.assertFalse(onFoo_event.nodoc)
self.assertTrue(self.nodoc.nodoc, 'Namespace should also be marked nodoc')
nodoc_ValidType = self.nodoc.types['ValidType']
self.assertFalse(nodoc_ValidType.nodoc)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
[
{
"namespace": "fakeapi",
"description": "The fakeapi API.",
"functions": [
{
"name": "get",
"type": "function",
"description": "Retrieves details about the specified FakeType.",
"parameters": [
{
"type": "integer",
"name": "fakeId",
"minimum": 0
},
{
"type": "function",
"name": "callback",
"parameters": [
{"name": "fakeType", "$ref": "FakeType"}
]
}
]
},
{
"name": "nodocMethod",
"type": "function",
"nodoc": true
}
],
"events": [
{
"name": "onFoo",
"type": "function"
},
{
"name": "onFooNoDoc",
"nodoc": true,
"type": "function"
}
],
"types": [
{
"id": "FakeType",
"type": "object",
"properties": {
"nodocProperty": {
"type": "string",
"nodoc": true
},
"any": {
"type": "any",
"description": "This is a fake type within the fakeapi API."
}
}
},
{
"id": "NoDocType",
"type": "object",
"description": "This type is marked as nodoc.",
"nodoc": true,
"properties": {
"property": {
"type": "boolean"
}
}
}
]
}
]
[
{
"namespace": "nodoc",
"description": "The nodoc API. This exists to demonstrate nodoc on the namespace itself.",
"nodoc": true,
"types": [
{
"id": "ValidType",
"type": "object",
"properties": {
"any": {
"type": "any",
"description": "This is a valid type but since the namespace isn't documented..."
}
}
}
]
}
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment