Skip to content

Commit

Permalink
Handle list passed as a request body
Browse files Browse the repository at this point in the history
  • Loading branch information
JamalZeynalov committed Jan 6, 2023
1 parent 530a5bc commit fe1f4be
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 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.12",
version="2.2.13",
author="Jamal Zeinalov",
author_email="[email protected]",
description='Python adapter for "swagger-coverage" tool',
Expand Down
64 changes: 45 additions & 19 deletions swagger_coverage_py/results_writers/base_schemas_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,53 @@ def _get_body_params(self):
"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)
if isinstance(request_body, dict):
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)
}
}
}
elif isinstance(request_body, list):
items_type = types.get(type(request_body[0]).__name__, "object")
request_body: dict = {
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": items_type
},
},
"example": json.loads(self._response.request.body)
}
}
}
else:
request_body: dict = {
"content": {
"application/json": {
"schema": {
"type": "string",
},
"example": urllib.parse.unquote(str(self._response.request.body))
}
}
}
}
else:
request_body = None

Expand Down

0 comments on commit fe1f4be

Please sign in to comment.