OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from copy import copy | 5 from copy import copy |
6 import logging | 6 import logging |
7 import re | 7 import re |
8 | 8 |
9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
10 from third_party.json_schema_compiler.model import PropertyType | 10 from third_party.json_schema_compiler.model import PropertyType |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 """Resolve $ref |ref| in namespace |namespace| if not None, returning None | 111 """Resolve $ref |ref| in namespace |namespace| if not None, returning None |
112 if it cannot be resolved. | 112 if it cannot be resolved. |
113 """ | 113 """ |
114 db_key = _MakeKey(namespace, ref) | 114 db_key = _MakeKey(namespace, ref) |
115 link = self._object_store.Get(db_key).Get() | 115 link = self._object_store.Get(db_key).Get() |
116 if link is None: | 116 if link is None: |
117 api_list = self._api_models.GetNames() | 117 api_list = self._api_models.GetNames() |
118 link = self._GetRefLink(ref, api_list, namespace) | 118 link = self._GetRefLink(ref, api_list, namespace) |
119 if link is None and namespace is not None: | 119 if link is None and namespace is not None: |
120 # Try to resolve the ref in the current namespace if there is one. | 120 # Try to resolve the ref in the current namespace if there is one. |
121 link = self._GetRefLink('%s.%s' % (namespace, ref), api_list, namespace) | 121 api_list = self._api_models.GetNames() |
| 122 link = self._GetRefLink('%s.%s' % (namespace, ref), |
| 123 api_list, |
| 124 namespace) |
122 if link is None: | 125 if link is None: |
123 return None | 126 return None |
124 self._object_store.Set(db_key, link) | 127 self._object_store.Set(db_key, link) |
125 | 128 |
126 if title is not None: | 129 if title is not None: |
127 link = copy(link) | 130 link = copy(link) |
128 link['text'] = title | 131 link['text'] = title |
129 | 132 |
130 return link | 133 return link |
131 | 134 |
132 def SafeGetLink(self, ref, namespace=None, title=None): | 135 def SafeGetLink(self, ref, namespace=None, title=None, path=None): |
133 """Resolve $ref |ref| in namespace |namespace|, or globally if None. If it | 136 """Resolve $ref |ref| in namespace |namespace|, or globally if None. If it |
134 cannot be resolved, pretend like it is a link to a type. | 137 cannot be resolved, pretend like it is a link to a type. |
135 """ | 138 """ |
136 ref_data = self.GetLink(ref, namespace=namespace, title=title) | 139 ref_data = self.GetLink(ref, namespace=namespace, title=title) |
137 if ref_data is not None: | 140 if ref_data is not None: |
138 return ref_data | 141 return ref_data |
139 logging.error('$ref %s could not be resolved in namespace %s.' % | 142 logging.warning('Could not resolve $ref %s in namespace %s on %s.' % |
140 (ref, namespace)) | 143 (ref, namespace, path)) |
141 type_name = ref.rsplit('.', 1)[-1] | 144 type_name = ref.rsplit('.', 1)[-1] |
142 return { | 145 return { |
143 'href': '#type-%s' % type_name, | 146 'href': '#type-%s' % type_name, |
144 'text': title or ref, | 147 'text': title or ref, |
145 'name': ref | 148 'name': ref |
146 } | 149 } |
OLD | NEW |