Recipes phase 5
This commit is contained in:
+69
-1
@@ -65,6 +65,34 @@ HYDRATION_SETTINGS = {'type': 'object', 'properties': {
|
||||
'hydration_beverage_rules': {'type': 'object', 'description':
|
||||
'Optional beverage type rules with enabled and factor (0 to 1) keys.'},
|
||||
}}
|
||||
RECIPE = {'type': 'object', 'properties': {
|
||||
'title': {'type': 'string', 'maxLength': 180},
|
||||
'description': {'type': 'string'}, 'instructions_markdown': {'type': 'string'},
|
||||
'notes_markdown': {'type': 'string'}, 'category': {'type': 'string'},
|
||||
'tags': {'type': 'array', 'items': {'type': 'string'}},
|
||||
'default_servings': {'type': 'string', 'description': 'Positive decimal'},
|
||||
'yield_amount': {'type': ['string', 'null']},
|
||||
'yield_unit': {'type': ['string', 'null'], 'enum': ['g', 'ml', None]},
|
||||
'preparation_minutes': {'type': 'integer', 'minimum': 0},
|
||||
'cooking_minutes': {'type': 'integer', 'minimum': 0},
|
||||
'status': {'type': 'string', 'enum': ['draft', 'published']},
|
||||
'is_favourite': {'type': 'boolean'},
|
||||
}}
|
||||
RECIPE_INGREDIENT = {'type': 'object', 'properties': {
|
||||
'name': {'type': 'string'}, 'quantity': {'type': 'string', 'description': 'Positive decimal'},
|
||||
'unit': {'type': 'string', 'enum': ['g', 'kg', 'ml', 'L', 'pieces', 'tsp', 'tbsp', 'portions']},
|
||||
'amount_per_unit': {'type': ['string', 'null']},
|
||||
'amount_per_unit_unit': {'type': ['string', 'null'], 'enum': ['g', 'ml', None]},
|
||||
'inventory_product_id': {'type': ['string', 'null'], 'format': 'uuid'},
|
||||
'nutrition_product_id': {'type': ['string', 'null'], 'format': 'uuid'},
|
||||
'preparation_note': {'type': 'string'}, 'is_optional': {'type': 'boolean'},
|
||||
'display_order': {'type': 'integer', 'minimum': 0},
|
||||
}}
|
||||
RECIPE_ANALYSIS = {'type': 'object', 'properties': {
|
||||
'servings': {'type': 'string', 'description': 'Prepared servings; defaults to the recipe'},
|
||||
'include_optional': {'type': 'boolean'},
|
||||
'substitutions': {'type': 'object', 'additionalProperties': {'type': 'string'}},
|
||||
}}
|
||||
|
||||
|
||||
@require_GET
|
||||
@@ -114,16 +142,52 @@ def schema(request):
|
||||
'get': operation('Read hydration settings', 'food:read'),
|
||||
'patch': operation('Update hydration settings', 'food:write', HYDRATION_SETTINGS),
|
||||
},
|
||||
'/recipes/': {'get': operation('Search own recipes by query, category, and limit', 'food:read')},
|
||||
'/recipes/create/': {'post': operation('Create own recipe with optional Idempotency-Key', 'food:write', RECIPE)},
|
||||
'/recipes/{id}/': {
|
||||
'get': operation('Read own recipe with ingredients, subrecipes, and variations', 'food:read'),
|
||||
'patch': operation('Update own recipe', 'food:write', RECIPE),
|
||||
'delete': operation('Delete own recipe when no parent recipe uses it', 'food:write'),
|
||||
},
|
||||
'/recipes/{id}/variations/': {'post': operation('Copy own recipe as an independent variation', 'food:write',
|
||||
{'type': 'object', 'properties': {'title': {'type': 'string'}}})},
|
||||
'/recipes/{id}/ingredients/': {'post': operation('Add ingredient to own recipe', 'food:write', RECIPE_INGREDIENT)},
|
||||
'/recipes/{id}/ingredients/{item_id}/': {
|
||||
'patch': operation('Update own recipe ingredient', 'food:write', RECIPE_INGREDIENT),
|
||||
'delete': operation('Remove own recipe ingredient', 'food:write'),
|
||||
},
|
||||
'/recipes/{id}/subrecipes/': {'post': operation('Attach an owned component recipe', 'food:write',
|
||||
{'type': 'object', 'required': ['component_id'], 'properties': {
|
||||
'component_id': {'type': 'string', 'format': 'uuid'}, 'quantity': {'type': 'string'},
|
||||
'unit': {'type': 'string'}, 'note': {'type': 'string'},
|
||||
'display_order': {'type': 'integer'}}})},
|
||||
'/recipes/{id}/subrecipes/{item_id}/': {'delete': operation('Detach a component recipe', 'food:write')},
|
||||
'/recipes/{id}/stock/preview/': {'post': operation('Preview inventory and issue confirmation when stock is ready',
|
||||
'inventory:read', RECIPE_ANALYSIS)},
|
||||
'/recipes/{id}/stock/confirm/': {'post': operation('Deduct inventory using the exact preview confirmation',
|
||||
'inventory:write', {'type': 'object', 'required': ['confirmation'], 'properties': {
|
||||
'confirmation': {'type': 'string'}}})},
|
||||
'/recipes/stock-use/{id}/undo/': {'post': operation('Undo a safe recipe inventory deduction', 'inventory:write')},
|
||||
'/recipes/{id}/log/': {'post': operation('Log consumed recipe servings without deducting stock; requires Idempotency-Key',
|
||||
'food:write', {'type': 'object', 'required': ['consumed_servings', 'meal'],
|
||||
'properties': {**RECIPE_ANALYSIS['properties'],
|
||||
'consumed_servings': {'type': 'string'},
|
||||
'meal': {'type': 'string', 'enum': ['breakfast', 'lunch', 'dinner', 'snacks']},
|
||||
'date': {'type': 'string', 'format': 'date'}, 'time': {'type': 'string', 'format': 'time'}}})},
|
||||
},
|
||||
}
|
||||
for path, methods in document['paths'].items():
|
||||
if '{id}' in path:
|
||||
methods['parameters'] = [{'name': 'id', 'in': 'path', 'required': True,
|
||||
'schema': {'type': 'string', 'format': 'uuid'}}]
|
||||
if '{item_id}' in path:
|
||||
methods.setdefault('parameters', []).append({'name': 'item_id', 'in': 'path', 'required': True,
|
||||
'schema': {'type': 'integer', 'minimum': 1}})
|
||||
if 'post' in methods:
|
||||
methods['post']['responses']['201'] = methods['post']['responses'].pop('200')
|
||||
for path in ('/kitchen/consumption/preview/', '/kitchen/consumption/',
|
||||
'/kitchen/consumption/{id}/undo/'):
|
||||
'/kitchen/consumption/{id}/undo/', '/recipes/{id}/stock/preview/',
|
||||
'/recipes/{id}/stock/confirm/', '/recipes/stock-use/{id}/undo/'):
|
||||
document['paths'][path]['post']['responses']['200'] = document['paths'][path]['post']['responses'].pop('201')
|
||||
document['paths']['/food/today/']['get']['parameters'] = [{
|
||||
'name': 'date', 'in': 'query', 'required': False,
|
||||
@@ -145,6 +209,10 @@ def schema(request):
|
||||
'name': 'Idempotency-Key', 'in': 'header', 'required': True,
|
||||
'schema': {'type': 'string', 'maxLength': 128},
|
||||
}]
|
||||
document['paths']['/recipes/{id}/log/']['post']['parameters'] = [{
|
||||
'name': 'Idempotency-Key', 'in': 'header', 'required': True,
|
||||
'schema': {'type': 'string', 'maxLength': 128},
|
||||
}]
|
||||
document['paths']['/food/attachments/{id}/file/']['get']['responses']['200'] = {
|
||||
'description': 'Owned image bytes',
|
||||
'content': {mime: {'schema': {'type': 'string', 'format': 'binary'}}
|
||||
|
||||
Reference in New Issue
Block a user