mozilla_schema_generator.utils
1# -*- coding: utf-8 -*- 2 3# This Source Code Form is subject to the terms of the Mozilla Public 4# License, v. 2.0. If a copy of the MPL was not distributed with this 5# file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 8from itertools import chain 9from typing import Any, Tuple 10 11 12def _get(_dict: dict, key: Tuple[str]) -> Any: 13 """ 14 Retrieved the nested `key` from a dict. 15 """ 16 if key: 17 return _get(_dict[key[0]], key[1:]) 18 return _dict 19 20 21def prepend_properties(key: Tuple[str]) -> Tuple[str]: 22 """ 23 Add a "properties" before each element of `key`. 24 This allows the field to be retrieved in a JSON schema 25 26 ex: 27 ``` 28 >> key = ("hello", "world") 29 >> _prepend_propertes(key) 30 ("properties", "hello", "properties", "world) 31 ``` 32 """ 33 return tuple(chain.from_iterable(zip(("properties" for k in key), key)))
def
prepend_properties(key: Tuple[str]) -> Tuple[str]:
22def prepend_properties(key: Tuple[str]) -> Tuple[str]: 23 """ 24 Add a "properties" before each element of `key`. 25 This allows the field to be retrieved in a JSON schema 26 27 ex: 28 ``` 29 >> key = ("hello", "world") 30 >> _prepend_propertes(key) 31 ("properties", "hello", "properties", "world) 32 ``` 33 """ 34 return tuple(chain.from_iterable(zip(("properties" for k in key), key)))
Add a "properties" before each element of key
.
This allows the field to be retrieved in a JSON schema
ex:
>> key = ("hello", "world")
>> _prepend_propertes(key)
("properties", "hello", "properties", "world)