31 lines
922 B
Python
31 lines
922 B
Python
from grocy.request import Request
|
|
from grocy.conf import Configuration
|
|
import logging
|
|
|
|
SCHEMA_URL_TEMPLATE = '{domain}/api/openapi/specification'
|
|
SCHEMA_MODEL_MAP = {
|
|
'products': 'Product',
|
|
'product_details': 'ProductDetailsResponse',
|
|
'stock': 'StockEntry',
|
|
'product_groups': 'ProductGroup',
|
|
'locations': 'Location',
|
|
'quantity_units': 'QuantityUnit',
|
|
'recipe_fulfillment': 'RecipeFulfillmentResponse',
|
|
'recipe_pos_fulfillment': 'RecipePosFulfillmentResponse'
|
|
}
|
|
|
|
|
|
def get_schema(name):
|
|
logger = logging.getLogger('schema')
|
|
try:
|
|
cfg = Configuration()
|
|
cfg.load()
|
|
url = SCHEMA_URL_TEMPLATE.format(domain=cfg.domain)
|
|
request = Request('get', url)
|
|
response = request.send()
|
|
schema_name = SCHEMA_MODEL_MAP[name]
|
|
return response['components']['schemas'][schema_name]
|
|
except Exception as e:
|
|
logger.error(e)
|
|
raise e
|