Skip to content

Commit

Permalink
Fix body parameters coverage calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
JamalZeynalov committed Jan 5, 2023
1 parent bc27268 commit 530a5bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="swagger-coverage",
version="2.2.11",
version="2.2.12",
author="Jamal Zeinalov",
author_email="[email protected]",
description='Python adapter for "swagger-coverage" tool',
Expand Down
29 changes: 28 additions & 1 deletion swagger_coverage_py/results_writers/base_schemas_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,37 @@ def _get_path_params(self) -> list:
return params_

def _get_body_params(self):
if isinstance(self._response.request.body, dict):
try:
request_body = json.loads(self._response.request.body)
except Exception:
request_body = None

if request_body:
types = {
"object": "object",
"str": "string",
"int": "number",
"float": "number",
"bool": "boolean",
"list": "array",
}
properties = {}
for k, v in request_body.items():
value_type = types.get(type(v).__name__, "object")
if value_type == "string":
value = urllib.parse.unquote(str(v))
else:
value = v

properties[k] = {k: value, "type": value_type}

request_body: dict = {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": properties
},
"example": json.loads(self._response.request.body)
}
}
Expand Down

0 comments on commit 530a5bc

Please sign in to comment.