Add support for "documented_in" annotation in json api schema

BUG=341275
NOTRY=true

Review URL: https://codereview.chromium.org/213673002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260306 0039d316-1c4b-4281-b951-d872f2087c98
parent ba3db738
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
"description": "Use the <code>webview</code> tag to actively load live content from the web over the network and embed it in your Chrome App. Your app can control the appearance of the <code>webview</code> and interact with the web content, initiate navigations in an embedded web page, react to error events that happen within it, and more (see <a href=\"#usage\">Usage</a>).", "description": "Use the <code>webview</code> tag to actively load live content from the web over the network and embed it in your Chrome App. Your app can control the appearance of the <code>webview</code> and interact with the web content, initiate navigations in an embedded web page, react to error events that happen within it, and more (see <a href=\"#usage\">Usage</a>).",
"documentation_options": { "documentation_options": {
"title": "<webview> Tag", "title": "<webview> Tag",
"namespace": "<webview>" "namespace": "<webview>",
"documented_in": "tags/webview"
}, },
"types": [ "types": [
{ {
......
...@@ -64,6 +64,12 @@ class _FakeAPIDataSource(object): ...@@ -64,6 +64,12 @@ class _FakeAPIDataSource(object):
return self._json[key] return self._json[key]
class _FakeNamespace(object):
def __init__(self):
self.documentation_options = {}
class _FakeAPIModels(object): class _FakeAPIModels(object):
def __init__(self, names): def __init__(self, names):
...@@ -72,6 +78,9 @@ class _FakeAPIModels(object): ...@@ -72,6 +78,9 @@ class _FakeAPIModels(object):
def GetNames(self): def GetNames(self):
return self._names return self._names
def GetModel(self, name):
return Future(value=_FakeNamespace())
class _FakeTemplateCache(object): class _FakeTemplateCache(object):
...@@ -160,15 +169,15 @@ class APIDataSourceTest(unittest.TestCase): ...@@ -160,15 +169,15 @@ class APIDataSourceTest(unittest.TestCase):
_FakeTemplateCache(), _FakeTemplateCache(),
self._features_bundle, self._features_bundle,
None).ToDict() None).ToDict()
self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'), self.assertEquals(_MakeLink('ref_test#type-type2', 'type2'),
_GetType(dict_, 'type1')['description']) _GetType(dict_, 'type1')['description'])
self.assertEquals( self.assertEquals(
'A %s, or %s' % (_MakeLink('ref_test.html#type-type3', 'type3'), 'A %s, or %s' % (_MakeLink('ref_test#type-type3', 'type3'),
_MakeLink('ref_test.html#type-type2', 'type2')), _MakeLink('ref_test#type-type2', 'type2')),
_GetType(dict_, 'type2')['description']) _GetType(dict_, 'type2')['description'])
self.assertEquals( self.assertEquals(
'%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), '%s != %s' % (_MakeLink('other#type-type2', 'other.type2'),
_MakeLink('ref_test.html#type-type2', 'type2')), _MakeLink('ref_test#type-type2', 'type2')),
_GetType(dict_, 'type3')['description']) _GetType(dict_, 'type3')['description'])
......
application: chrome-apps-doc application: chrome-apps-doc
version: 3-15-2 version: 3-16-0
runtime: python27 runtime: python27
api_version: 1 api_version: 1
threadsafe: false threadsafe: false
......
...@@ -2,4 +2,4 @@ cron: ...@@ -2,4 +2,4 @@ cron:
- description: Repopulates all cached data. - description: Repopulates all cached data.
url: /_cron url: /_cron
schedule: every 5 minutes schedule: every 5 minutes
target: 3-15-2 target: 3-16-0
...@@ -114,8 +114,10 @@ class ReferenceResolver(object): ...@@ -114,8 +114,10 @@ class ReferenceResolver(object):
category, node_name = node_info category, node_name = node_info
if namespace is not None and text.startswith('%s.' % namespace): if namespace is not None and text.startswith('%s.' % namespace):
text = text[len('%s.' % namespace):] text = text[len('%s.' % namespace):]
api_model = self._api_models.GetModel(api_name).Get()
filename = api_model.documentation_options.get('documented_in', api_name)
return { return {
'href': '%s.html#%s-%s' % (api_name, category, name.replace('.', '-')), 'href': '%s#%s-%s' % (filename, category, name.replace('.', '-')),
'text': text, 'text': text,
'name': node_name 'name': node_name
} }
...@@ -125,7 +127,7 @@ class ReferenceResolver(object): ...@@ -125,7 +127,7 @@ class ReferenceResolver(object):
# to other APIs. # to other APIs.
if ref in api_list: if ref in api_list:
return { return {
'href': '%s.html' % ref, 'href': '%s' % ref,
'text': ref, 'text': ref,
'name': ref 'name': ref
} }
......
...@@ -9,12 +9,13 @@ import sys ...@@ -9,12 +9,13 @@ import sys
import unittest import unittest
from file_system import FileNotFoundError from file_system import FileNotFoundError
from future import Future
from reference_resolver import ReferenceResolver from reference_resolver import ReferenceResolver
from test_object_store import TestObjectStore from test_object_store import TestObjectStore
from test_util import Server2Path from test_util import Server2Path
class FakeAPIDataSource(object): class _FakeAPIDataSource(object):
def __init__(self, json_data): def __init__(self, json_data):
self._json = json_data self._json = json_data
...@@ -25,15 +26,23 @@ class FakeAPIDataSource(object): ...@@ -25,15 +26,23 @@ class FakeAPIDataSource(object):
return self._json[key] return self._json[key]
class FakeAPIModels(object): class _FakeNamespace(object):
def __init__(self):
self.documentation_options = {}
class _FakeAPIModels(object):
def __init__(self, names): def __init__(self, names):
self._names = names self._names = names
def GetNames(self): def GetNames(self):
return self._names return self._names
def GetModel(self, name):
return Future(value=_FakeNamespace())
class APIDataSourceTest(unittest.TestCase): class ReferenceResolverTest(unittest.TestCase):
def setUp(self): def setUp(self):
self._base_path = Server2Path('test_data', 'test_json') self._base_path = Server2Path('test_data', 'test_json')
...@@ -43,86 +52,86 @@ class APIDataSourceTest(unittest.TestCase): ...@@ -43,86 +52,86 @@ class APIDataSourceTest(unittest.TestCase):
def testGetLink(self): def testGetLink(self):
test_data = json.loads(self._ReadLocalFile('fake_data_source.json')) test_data = json.loads(self._ReadLocalFile('fake_data_source.json'))
resolver = ReferenceResolver(FakeAPIDataSource(test_data), resolver = ReferenceResolver(_FakeAPIDataSource(test_data),
FakeAPIModels(test_data.keys()), _FakeAPIModels(test_data.keys()),
TestObjectStore('test')) TestObjectStore('test'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html', 'href': 'foo',
'text': 'foo', 'text': 'foo',
'name': 'foo' 'name': 'foo'
}, resolver.GetLink('foo', namespace='baz')) }, resolver.GetLink('foo', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html#type-foo_t1', 'href': 'foo#type-foo_t1',
'text': 'foo.foo_t1', 'text': 'foo.foo_t1',
'name': 'foo_t1' 'name': 'foo_t1'
}, resolver.GetLink('foo.foo_t1', namespace='baz')) }, resolver.GetLink('foo.foo_t1', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'baz.html#event-baz_e1', 'href': 'baz#event-baz_e1',
'text': 'baz_e1', 'text': 'baz_e1',
'name': 'baz_e1' 'name': 'baz_e1'
}, resolver.GetLink('baz.baz_e1', namespace='baz')) }, resolver.GetLink('baz.baz_e1', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'baz.html#event-baz_e1', 'href': 'baz#event-baz_e1',
'text': 'baz_e1', 'text': 'baz_e1',
'name': 'baz_e1' 'name': 'baz_e1'
}, resolver.GetLink('baz_e1', namespace='baz')) }, resolver.GetLink('baz_e1', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html#method-foo_f1', 'href': 'foo#method-foo_f1',
'text': 'foo.foo_f1', 'text': 'foo.foo_f1',
'name': 'foo_f1' 'name': 'foo_f1'
}, resolver.GetLink('foo.foo_f1', namespace='baz')) }, resolver.GetLink('foo.foo_f1', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html#property-foo_p3', 'href': 'foo#property-foo_p3',
'text': 'foo.foo_p3', 'text': 'foo.foo_p3',
'name': 'foo_p3' 'name': 'foo_p3'
}, resolver.GetLink('foo.foo_p3', namespace='baz')) }, resolver.GetLink('foo.foo_p3', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'bar.bon.html#type-bar_bon_t3', 'href': 'bar.bon#type-bar_bon_t3',
'text': 'bar.bon.bar_bon_t3', 'text': 'bar.bon.bar_bon_t3',
'name': 'bar_bon_t3' 'name': 'bar_bon_t3'
}, resolver.GetLink('bar.bon.bar_bon_t3', namespace='baz')) }, resolver.GetLink('bar.bon.bar_bon_t3', namespace='baz'))
self.assertEqual({ self.assertEqual({
'href': 'bar.bon.html#property-bar_bon_p3', 'href': 'bar.bon#property-bar_bon_p3',
'text': 'bar_bon_p3', 'text': 'bar_bon_p3',
'name': 'bar_bon_p3' 'name': 'bar_bon_p3'
}, resolver.GetLink('bar_bon_p3', namespace='bar.bon')) }, resolver.GetLink('bar_bon_p3', namespace='bar.bon'))
self.assertEqual({ self.assertEqual({
'href': 'bar.bon.html#property-bar_bon_p3', 'href': 'bar.bon#property-bar_bon_p3',
'text': 'bar_bon_p3', 'text': 'bar_bon_p3',
'name': 'bar_bon_p3' 'name': 'bar_bon_p3'
}, resolver.GetLink('bar.bon.bar_bon_p3', namespace='bar.bon')) }, resolver.GetLink('bar.bon.bar_bon_p3', namespace='bar.bon'))
self.assertEqual({ self.assertEqual({
'href': 'bar.html#event-bar_e2', 'href': 'bar#event-bar_e2',
'text': 'bar_e2', 'text': 'bar_e2',
'name': 'bar_e2' 'name': 'bar_e2'
}, resolver.GetLink('bar.bar_e2', namespace='bar')) }, resolver.GetLink('bar.bar_e2', namespace='bar'))
self.assertEqual({ self.assertEqual({
'href': 'bar.html#type-bon', 'href': 'bar#type-bon',
'text': 'bon', 'text': 'bon',
'name': 'bon' 'name': 'bon'
}, resolver.GetLink('bar.bon', namespace='bar')) }, resolver.GetLink('bar.bon', namespace='bar'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html#event-foo_t3-foo_t3_e1', 'href': 'foo#event-foo_t3-foo_t3_e1',
'text': 'foo_t3.foo_t3_e1', 'text': 'foo_t3.foo_t3_e1',
'name': 'foo_t3_e1' 'name': 'foo_t3_e1'
}, resolver.GetLink('foo_t3.foo_t3_e1', namespace='foo')) }, resolver.GetLink('foo_t3.foo_t3_e1', namespace='foo'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html#event-foo_t3-foo_t3_e1', 'href': 'foo#event-foo_t3-foo_t3_e1',
'text': 'foo_t3.foo_t3_e1', 'text': 'foo_t3.foo_t3_e1',
'name': 'foo_t3_e1' 'name': 'foo_t3_e1'
}, resolver.GetLink('foo.foo_t3.foo_t3_e1', namespace='foo')) }, resolver.GetLink('foo.foo_t3.foo_t3_e1', namespace='foo'))
self.assertEqual({ self.assertEqual({
'href': 'foo.html#event-foo_t3-foo_t3_e1', 'href': 'foo#event-foo_t3-foo_t3_e1',
'text': 'foo_t3.foo_t3_e1', 'text': 'foo_t3.foo_t3_e1',
'name': 'foo_t3_e1' 'name': 'foo_t3_e1'
}, resolver.GetLink('foo.foo_p1.foo_t3_e1', namespace='foo')) }, resolver.GetLink('foo.foo_p1.foo_t3_e1', namespace='foo'))
self.assertEqual({ self.assertEqual({
'href': 'bar.html#property-bar_t1-bar_t1_p1', 'href': 'bar#property-bar_t1-bar_t1_p1',
'text': 'bar.bar_t1.bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1',
'name': 'bar_t1_p1' 'name': 'bar_t1_p1'
}, resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo')) }, resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo'))
self.assertEqual({ self.assertEqual({
'href': 'bar.html#property-bar_t1-bar_t1_p1', 'href': 'bar#property-bar_t1-bar_t1_p1',
'text': 'bar_t1.bar_t1_p1', 'text': 'bar_t1.bar_t1_p1',
'name': 'bar_t1_p1' 'name': 'bar_t1_p1'
}, resolver.GetLink('bar_p3.bar_t1_p1', namespace='bar')) }, resolver.GetLink('bar_p3.bar_t1_p1', namespace='bar'))
...@@ -142,72 +151,72 @@ class APIDataSourceTest(unittest.TestCase): ...@@ -142,72 +151,72 @@ class APIDataSourceTest(unittest.TestCase):
None, None,
resolver.GetLink('bar_p3', namespace='foo')) resolver.GetLink('bar_p3', namespace='foo'))
self.assertEqual( self.assertEqual(
'Hello <a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 'Hello <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>',
resolver.ResolveAllLinks( resolver.ResolveAllLinks(
'Hello $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'Hello $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
namespace='bar.bon')) namespace='bar.bon'))
self.assertEqual( self.assertEqual(
'I like <a href="bar.html#property-bar_t1-bar_t1_p1">food</a>.', 'I like <a href="bar#property-bar_t1-bar_t1_p1">food</a>.',
resolver.ResolveAllLinks('I like $ref:[bar.bar_p3.bar_t1_p1 food].', resolver.ResolveAllLinks('I like $ref:[bar.bar_p3.bar_t1_p1 food].',
namespace='foo')) namespace='foo'))
self.assertEqual( self.assertEqual(
'Ref <a href="foo.html">It\'s foo!</a>', 'Ref <a href="foo">It\'s foo!</a>',
resolver.ResolveAllLinks('Ref $ref:[foo It\'s foo!]', namespace='bar')) resolver.ResolveAllLinks('Ref $ref:[foo It\'s foo!]', namespace='bar'))
self.assertEqual( self.assertEqual(
'Ref <a href="bar.html#type-bon">Bon</a>', 'Ref <a href="bar#type-bon">Bon</a>',
resolver.ResolveAllLinks('Ref $ref:[bar.bon Bon]', namespace='bar')) resolver.ResolveAllLinks('Ref $ref:[bar.bon Bon]', namespace='bar'))
# Different kinds of whitespace can be significant inside <pre> tags. # Different kinds of whitespace can be significant inside <pre> tags.
self.assertEqual( self.assertEqual(
'<pre><a href="bar.html#type-bon">bar.bon</a>({\nkey: value})', '<pre><a href="bar#type-bon">bar.bon</a>({\nkey: value})',
resolver.ResolveAllLinks('<pre>$ref:[bar.bon]({\nkey: value})', resolver.ResolveAllLinks('<pre>$ref:[bar.bon]({\nkey: value})',
namespace='baz')) namespace='baz'))
# Allow bare "$ref:foo.bar." at the end of a string. # Allow bare "$ref:foo.bar." at the end of a string.
self.assertEqual( self.assertEqual(
'<a href="bar.html#type-bon">bar.bon</a>.', '<a href="bar#type-bon">bar.bon</a>.',
resolver.ResolveAllLinks('$ref:bar.bon.', resolver.ResolveAllLinks('$ref:bar.bon.',
namespace='baz')) namespace='baz'))
# If a request is provided it should construct an appropriate relative link. # If a request is provided it should construct an appropriate relative link.
self.assertEqual( self.assertEqual(
'Hi <a href="../../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 'Hi <a href="../../bar.bon#property-bar_bon_p3">bar_bon_p3</a>, '
'<a href="../../bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="../../bar.bon#property-bar_bon_p3">Bon Bon</a>, '
'<a href="../../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', '<a href="../../bar.bon#property-bar_bon_p3">bar_bon_p3</a>',
resolver.ResolveAllLinks( resolver.ResolveAllLinks(
'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
relative_to='big/long/path/bar.html', relative_to='big/long/path/bar.html',
namespace='bar.bon')) namespace='bar.bon'))
self.assertEqual( self.assertEqual(
'Hi <a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 'Hi <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>',
resolver.ResolveAllLinks( resolver.ResolveAllLinks(
'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
relative_to='', relative_to='',
namespace='bar.bon')) namespace='bar.bon'))
self.assertEqual( self.assertEqual(
'Hi <a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 'Hi <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>',
resolver.ResolveAllLinks( resolver.ResolveAllLinks(
'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
relative_to='bar.html', relative_to='bar.html',
namespace='bar.bon')) namespace='bar.bon'))
self.assertEqual( self.assertEqual(
'Hi <a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 'Hi <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, '
'<a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>',
resolver.ResolveAllLinks( resolver.ResolveAllLinks(
'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
relative_to='foo/bar.html', relative_to='foo/bar.html',
namespace='bar.bon')) namespace='bar.bon'))
self.assertEqual( self.assertEqual(
'Hi <a href="../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 'Hi <a href="../bar.bon#property-bar_bon_p3">bar_bon_p3</a>, '
'<a href="../bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="../bar.bon#property-bar_bon_p3">Bon Bon</a>, '
'<a href="../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', '<a href="../bar.bon#property-bar_bon_p3">bar_bon_p3</a>',
resolver.ResolveAllLinks( resolver.ResolveAllLinks(
'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
relative_to='foo/baz/bar.html', relative_to='foo/baz/bar.html',
......
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