Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/reference_resolver.py |
| diff --git a/chrome/common/extensions/docs/server2/reference_resolver.py b/chrome/common/extensions/docs/server2/reference_resolver.py |
| index 7b3021c8fb2c51ed568d20feb080d09716b0b613..141a963d0f597e7c44884abddf05023bface21df 100644 |
| --- a/chrome/common/extensions/docs/server2/reference_resolver.py |
| +++ b/chrome/common/extensions/docs/server2/reference_resolver.py |
| @@ -107,6 +107,34 @@ class ReferenceResolver(object): |
| return None |
| + def GetRefModel(self, ref, api_list): |
|
Ken Rockot(use gerrit already)
2014/09/04 01:57:12
Please include a docstring to explain what this do
|
| + # Check nodes within each API the ref might refer to. |
| + parts = ref.split('.') |
| + for i in xrange(1, len(parts)): |
| + api_name = '.'.join(parts[:i]) |
| + if api_name not in api_list: |
| + continue |
| + try: |
| + api_model = self._api_models.GetModel(api_name).Get() |
| + except FileNotFoundError: |
| + continue |
| + name = '.'.join(parts[i:]) |
| + # Attempt to find |name| in the API. |
| + node_info = _ClassifySchemaNode(name, api_model) |
| + if node_info is None: |
| + # Check to see if this ref is a property. If it is, we want the ref to |
| + # the underlying type the property is referencing. |
| + for prop in api_model.properties.itervalues(): |
| + # If the name of this property is in the ref text, replace the |
| + # property with its type, and attempt to classify it. |
| + if prop.name in name and prop.type_.property_type == PropertyType.REF: |
| + name_as_prop_type = name.replace(prop.name, prop.type_.ref_type) |
| + node_info = _ClassifySchemaNode(name_as_prop_type, api_model) |
| + if node_info is None: |
| + continue |
| + return api_model, node_info |
| + return None, None |
| + |
| def GetLink(self, ref, namespace=None, title=None): |
| """Resolve $ref |ref| in namespace |namespace| if not None, returning None |
| if it cannot be resolved. |