| 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 """Utilies for the processing of schema python structures. | 4 """Utilies for the processing of schema python structures. |
| 5 """ | 5 """ |
| 6 | 6 |
| 7 from model import PropertyType |
| 8 |
| 9 def IsLocalReference(prop, namespace): |
| 10 return ((prop.type_ == PropertyType.REF) and |
| 11 ((not '.' in prop.ref_type) or |
| 12 prop.ref_type.startswith(namespace + '.'))) |
| 13 |
| 7 def StripSchemaNamespace(s): | 14 def StripSchemaNamespace(s): |
| 8 last_dot = s.rfind('.') | 15 last_dot = s.rfind('.') |
| 9 if not last_dot == -1: | 16 if not last_dot == -1: |
| 10 return s[last_dot + 1:] | 17 return s[last_dot + 1:] |
| 11 return s | 18 return s |
| 12 | 19 |
| 13 def PrefixSchemasWithNamespace(schemas): | 20 def PrefixSchemasWithNamespace(schemas): |
| 14 for s in schemas: | 21 for s in schemas: |
| 15 _PrefixWithNamespace(s.get("namespace"), s) | 22 _PrefixWithNamespace(s.get("namespace"), s) |
| 16 | 23 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 def _PrefixWithNamespace(namespace, schema): | 35 def _PrefixWithNamespace(namespace, schema): |
| 29 if type(schema) == dict: | 36 if type(schema) == dict: |
| 30 if "types" in schema: | 37 if "types" in schema: |
| 31 _PrefixTypesWithNamespace(namespace, schema.get("types")) | 38 _PrefixTypesWithNamespace(namespace, schema.get("types")) |
| 32 _MaybePrefixFieldWithNamespace(namespace, schema, "$ref") | 39 _MaybePrefixFieldWithNamespace(namespace, schema, "$ref") |
| 33 for s in schema: | 40 for s in schema: |
| 34 _PrefixWithNamespace(namespace, schema[s]) | 41 _PrefixWithNamespace(namespace, schema[s]) |
| 35 elif type(schema) == list: | 42 elif type(schema) == list: |
| 36 for s in schema: | 43 for s in schema: |
| 37 _PrefixWithNamespace(namespace, s) | 44 _PrefixWithNamespace(namespace, s) |
| OLD | NEW |