Skip to content

Commit 1f77b5c

Browse files
author
Alfonso Tankia
committed
Added logic for proper parsing
1 parent 497e6f5 commit 1f77b5c

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

openapi_python_client/parser/openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Endpoint:
9494
path_parameters: List[Property] = field(default_factory=list)
9595
header_parameters: List[Property] = field(default_factory=list)
9696
responses: List[Response] = field(default_factory=list)
97-
yaml_body: Optional[Reference] = None
97+
yaml_body: Optional[Property] = None
9898
form_body_reference: Optional[Reference] = None
9999
json_body: Optional[Property] = None
100100
multipart_body_reference: Optional[Reference] = None

openapi_python_client/parser/responses.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Tuple, Union
44

55
import attr
6-
import yaml
76

87
from .. import schema as oai
98
from .errors import ParseError, PropertyError
@@ -23,7 +22,7 @@ class Response:
2322
"application/json": "response.json()",
2423
"application/octet-stream": "response.content",
2524
"text/html": "response.text",
26-
"text/yaml": "response.text",
25+
"text/yaml": "yaml.safe_load(response.text.encode('utf-8'))",
2726
}
2827

2928

openapi_python_client/templates/endpoint_macros.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ if {% if not property.required %}not isinstance({{ property_name }}, Unset) and
5656
{% endif %}
5757
{% endmacro %}
5858

59+
{% macro yaml_body(endpoint) %}
60+
{% if endpoint.yaml_body %}
61+
{% set property = endpoint.yaml_body %}
62+
{% set destination = "yaml_" + property.python_name %}
63+
{% if property.template %}
64+
{% from "property_templates/" + property.template import transform %}
65+
{{ transform(property, property.python_name, destination) }}
66+
{% endif %}
67+
{% endif %}
68+
{% endmacro %}
69+
5970
{% macro return_type(endpoint) %}
6071
{% if endpoint.responses | length == 0 %}
6172
None

openapi_python_client/templates/endpoint_module.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, List, Optional, Union, cast
22

33
import httpx
4+
import yaml
45
from attr import asdict
56

67
from ...client import AuthenticatedClient, Client
@@ -10,7 +11,7 @@ from ...types import Response
1011
{{ relative }}
1112
{% endfor %}
1213

13-
{% from "endpoint_macros.pyi" import header_params, query_params, json_body, return_type, arguments, client, kwargs, parse_response %}
14+
{% from "endpoint_macros.pyi" import header_params, query_params, json_body, yaml_body, return_type, arguments, client, kwargs, parse_response %}
1415

1516
{% set return_string = return_type(endpoint) %}
1617
{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "None" %}
@@ -33,6 +34,8 @@ def _get_kwargs(
3334

3435
{{ json_body(endpoint) | indent(4) }}
3536

37+
{{ yaml_body(endpoint) | indent(4) }}
38+
3639
return {
3740
"url": url,
3841
"headers": headers,

0 commit comments

Comments
 (0)