Skip to content

Commit

Permalink
Updated to Specmatic 1.3.38
Browse files Browse the repository at this point in the history
  • Loading branch information
StarKhan6368 committed Jul 17, 2024
1 parent ff455c4 commit f2f2e0a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json as jsonlib
import os
from datetime import UTC, datetime

Expand All @@ -17,14 +18,12 @@

@app.exception(ValidationError)
async def handle_marshmallow_validation_error(_, exc: "ValidationError"):
# NOTE:API SPEC V4 specifies that message should be a string not an object / array
errors = "\n".join([f"{field}: {", ".join(err)}" for field, err in exc.normalized_messages().items()])
return json(
{
"timestamp": datetime.now(tz=UTC).isoformat(),
"status": 400,
"error": "Bad Request",
"message": errors,
"message": jsonlib.dumps(exc.messages),
},
status=400,
)
Expand Down
2 changes: 1 addition & 1 deletion api/products/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def find_available_products(request: "Request"):
raise ServiceUnavailable("Timeout")

products = ProductService.find_products(p_type)
return json(Product.dump(products), status=200)
return json(products, status=200)


@products.route("/products", methods=["POST"])
Expand Down
4 changes: 2 additions & 2 deletions api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ProductService:
}

@staticmethod
def find_products(p_type: ProductType | None) -> list[Product]:
def find_products(p_type: ProductType | None) -> list[dict]:
resp = requests.get(
f"{app.config['API_URL']}{ProductService._API_LIST['SEARCH']}",
params={"type": p_type.value if p_type else None},
Expand All @@ -25,7 +25,7 @@ def find_products(p_type: ProductType | None) -> list[Product]:
if resp.status_code != 200:
raise SanicException("An error occurred while retrieving the products.", status_code=resp.status_code)

return Product.load_many(resp.json())
return resp.json()

@staticmethod
def create_product(product: Product) -> dict[str, int]:
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
coverage==7.5.4
coverage==7.6.0
marshmallow==3.21.3
pytest==8.2.2
python-dotenv==1.0.1
requests==2.32.3
sanic==24.6.0
setuptools==70.2.0
specmatic==1.3.34
setuptools==70.3.0
specmatic==1.3.38

0 comments on commit f2f2e0a

Please sign in to comment.