Skip to content

Commit

Permalink
[ENG-1067] Improve ergonomics of accessing response values in Python (#…
Browse files Browse the repository at this point in the history
…331)

* point to pydantic for return in prstv2

* update generated docs for Python for pydantic response values

* Add "Raw HTTP Response" to Python

* "Raw HTTP Response" section in README

* regenerate integration test SDKs
  • Loading branch information
dphuang2 authored Nov 3, 2023
1 parent 9564793 commit 61ad440
Show file tree
Hide file tree
Showing 23 changed files with 533 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{#with operations}}
{{#each operation}}
{{#if @first}}
{{> api_doc_example}}
{{> api_doc_example pydantic=prstv2}}
{{/if}}
{{/each}}
{{/with}}
Expand Down Expand Up @@ -47,7 +47,7 @@ import asyncio
{{> api_doc_example_setup}}

async def main():
{{> api_doc_example_execute async=true}}
{{> api_doc_example_execute pydantic=prstv2 async=true}}

asyncio.run(main())
{{/if}}
Expand All @@ -58,6 +58,28 @@ asyncio.run(main())
{{/with}}
{{/if}}
```
{{#if prstv2}}

## Raw HTTP Response

To access raw HTTP response values, use the `.raw` namespace.

```python
{{#with apiInfo}}
{{#each apis}}
{{#if @first}}
{{#with operations}}
{{#each operation}}
{{#if @first}}
{{> api_doc_example raw=true}}
{{/if}}
{{/each}}
{{/with}}
{{/if}}
{{/each}}
{{/with}}
```
{{/if}}

{{#if readmeSupportingDescriptionSnippet}}

Expand Down Expand Up @@ -121,7 +143,11 @@ asyncio.run(main())
{{#with returnModel}}
#### 🔄 Return

{{#if prstv2}}
[{{{name}}}](./{{packageName}}/pydantic/{{classFilename}}.py)
{{else}}
[{{{name}}}](./{{packageName}}/type/{{classFilename}}.py)
{{/if}}

{{/with}}
#### 🌐 Endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ try:
{{> api_doc_example_execute_call}}
{{#if returnModel}}
{{#with returnModel}}
{{#if pydantic}}
print({{operationId}}_response)
{{else}}
pprint({{operationId}}_response.body)
{{#each vars}}
pprint({{operationId}}_response.body["{{{name}}}"])
{{/each}}
{{/if}}
{{/with}}
{{/if}}
{{#unless pydantic}}
{{#if returnType}}
pprint({{operationId}}_response.headers)
pprint({{operationId}}_response.status)
pprint({{operationId}}_response.round_trip_time)
{{/if}}
{{/unless}}
except ApiException as e:
print("Exception when calling {{classname}}.{{operationId}}: %s\n" % e)
pprint(e.body)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#if vendorExtensions.x-konfig-top-level-operation}}{{#if async}}a{{/if}}{{vendorExtensions.x-konfig-top-level-operation}}{{/if}}{{#unless vendorExtensions.x-konfig-top-level-operation}}{{> api_class_name}}.{{#if async}}a{{/if}}{{operationId}}{{/unless}}
{{#if vendorExtensions.x-konfig-top-level-operation}}{{#if async}}a{{/if}}{{vendorExtensions.x-konfig-top-level-operation}}{{/if}}{{#unless vendorExtensions.x-konfig-top-level-operation}}{{> api_class_name}}.{{#if raw}}raw.{{/if}}{{#if async}}a{{/if}}{{operationId}}{{/unless}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

|Language|Version|Package Manager|Documentation|Source|
|-|-|-|-|-|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-free-form-object-response/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/blob/main/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-free-form-object-response/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ A simple API based for testing python-pydantic-free-form-object-response.


[![PyPI](https://img.shields.io/badge/PyPI-v1.0.0-blue)](https://pypi.org/project/python-pydantic-free-form-object-response/1.0.0)
[![GitHub last commit](https://img.shields.io/github/last-commit/konfig-dev/konfig.svg)](https://github.com/konfig-dev/konfig/commits)
[![README.md](https://img.shields.io/badge/README-Click%20Here-green)](https://github.com/konfig-dev/konfig/tree/main/python#readme)
[![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](http://example.com/support)

Expand All @@ -16,6 +15,7 @@ A simple API based for testing python-pydantic-free-form-object-response.
- [Installing](#installing)
- [Getting Started](#getting-started)
- [Async](#async)
- [Raw HTTP Response](#raw-http-response)
- [Reference](#reference)
* [`pythonpydanticfreeformobjectresponse.test.fetch`](#pythonpydanticfreeformobjectresponsetestfetch)

Expand Down Expand Up @@ -49,9 +49,6 @@ try:
fetch_response = pythonpydanticfreeformobjectresponse.test.fetch(
input_parameter="inputParameter_example",
)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
Expand Down Expand Up @@ -84,9 +81,6 @@ async def main():
fetch_response = await pythonpydanticfreeformobjectresponse.test.afetch(
input_parameter="inputParameter_example",
)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
Expand All @@ -99,6 +93,38 @@ async def main():
asyncio.run(main())
```

## Raw HTTP Response

To access raw HTTP response values, use the `.raw` namespace.

```python
from pprint import pprint
from python_pydantic_free_form_object_response import (
PythonPydanticFreeFormObjectResponse,
ApiException,
)

pythonpydanticfreeformobjectresponse = PythonPydanticFreeFormObjectResponse(
api_key="YOUR_API_KEY",
)

try:
# Fetches a JSON value based on input parameter
fetch_response = pythonpydanticfreeformobjectresponse.test.raw.fetch(
input_parameter="inputParameter_example",
)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
```


## Reference
### `pythonpydanticfreeformobjectresponse.test.fetch`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

|Language|Version|Package Manager|Documentation|Source|
|-|-|-|-|-|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-list-in-union/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/blob/main/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-list-in-union/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ A simple API based for testing python-pydantic-list-in-union.


[![PyPI](https://img.shields.io/badge/PyPI-v1.0.0-blue)](https://pypi.org/project/python-pydantic-list-in-union/1.0.0)
[![GitHub last commit](https://img.shields.io/github/last-commit/konfig-dev/konfig.svg)](https://github.com/konfig-dev/konfig/commits)
[![README.md](https://img.shields.io/badge/README-Click%20Here-green)](https://github.com/konfig-dev/konfig/tree/main/python#readme)
[![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](http://example.com/support)

Expand All @@ -16,6 +15,7 @@ A simple API based for testing python-pydantic-list-in-union.
- [Installing](#installing)
- [Getting Started](#getting-started)
- [Async](#async)
- [Raw HTTP Response](#raw-http-response)
- [Reference](#reference)
* [`pythonpydanticlistinunion.test.fetch`](#pythonpydanticlistinuniontestfetch)

Expand Down Expand Up @@ -44,10 +44,7 @@ pythonpydanticlistinunion = PythonPydanticListInUnion(
try:
# Fetches a JSON value based on input parameter
fetch_response = pythonpydanticlistinunion.test.fetch()
pprint(fetch_response.body)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
print(fetch_response)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
Expand Down Expand Up @@ -75,10 +72,7 @@ async def main():
try:
# Fetches a JSON value based on input parameter
fetch_response = await pythonpydanticlistinunion.test.afetch()
pprint(fetch_response.body)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
print(fetch_response)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
Expand All @@ -91,6 +85,34 @@ async def main():
asyncio.run(main())
```

## Raw HTTP Response

To access raw HTTP response values, use the `.raw` namespace.

```python
from pprint import pprint
from python_pydantic_list_in_union import PythonPydanticListInUnion, ApiException

pythonpydanticlistinunion = PythonPydanticListInUnion(
api_key="YOUR_API_KEY",
)

try:
# Fetches a JSON value based on input parameter
fetch_response = pythonpydanticlistinunion.test.raw.fetch()
pprint(fetch_response.body)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
```


## Reference
### `pythonpydanticlistinunion.test.fetch`
Expand All @@ -105,7 +127,7 @@ fetch_response = pythonpydanticlistinunion.test.fetch()

#### 🔄 Return

[Response](./python_pydantic_list_in_union/type/response.py)
[Response](./python_pydantic_list_in_union/pydantic/response.py)

#### 🌐 Endpoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

|Language|Version|Package Manager|Documentation|Source|
|-|-|-|-|-|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-list-response/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/blob/main/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-list-response/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ A simple API based for testing python-pydantic-list-response.


[![PyPI](https://img.shields.io/badge/PyPI-v1.0.0-blue)](https://pypi.org/project/python-pydantic-list-response/1.0.0)
[![GitHub last commit](https://img.shields.io/github/last-commit/konfig-dev/konfig.svg)](https://github.com/konfig-dev/konfig/commits)
[![README.md](https://img.shields.io/badge/README-Click%20Here-green)](https://github.com/konfig-dev/konfig/tree/main/python#readme)
[![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](http://example.com/support)

Expand All @@ -16,6 +15,7 @@ A simple API based for testing python-pydantic-list-response.
- [Installing](#installing)
- [Getting Started](#getting-started)
- [Async](#async)
- [Raw HTTP Response](#raw-http-response)
- [Reference](#reference)
* [`pythonpydanticlistresponse.test.fetch`](#pythonpydanticlistresponsetestfetch)

Expand Down Expand Up @@ -44,10 +44,7 @@ pythonpydanticlistresponse = PythonPydanticListResponse(
try:
# Fetches a JSON value based on input parameter
fetch_response = pythonpydanticlistresponse.test.fetch()
pprint(fetch_response.body)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
print(fetch_response)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
Expand Down Expand Up @@ -75,10 +72,7 @@ async def main():
try:
# Fetches a JSON value based on input parameter
fetch_response = await pythonpydanticlistresponse.test.afetch()
pprint(fetch_response.body)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
print(fetch_response)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
Expand All @@ -91,6 +85,34 @@ async def main():
asyncio.run(main())
```

## Raw HTTP Response

To access raw HTTP response values, use the `.raw` namespace.

```python
from pprint import pprint
from python_pydantic_list_response import PythonPydanticListResponse, ApiException

pythonpydanticlistresponse = PythonPydanticListResponse(
api_key="YOUR_API_KEY",
)

try:
# Fetches a JSON value based on input parameter
fetch_response = pythonpydanticlistresponse.test.raw.fetch()
pprint(fetch_response.body)
pprint(fetch_response.headers)
pprint(fetch_response.status)
pprint(fetch_response.round_trip_time)
except ApiException as e:
print("Exception when calling TestApi.fetch: %s\n" % e)
pprint(e.body)
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
```


## Reference
### `pythonpydanticlistresponse.test.fetch`
Expand All @@ -105,7 +127,7 @@ fetch_response = pythonpydanticlistresponse.test.fetch()

#### 🔄 Return

[TestFetchResponse](./python_pydantic_list_response/type/test_fetch_response.py)
[TestFetchResponse](./python_pydantic_list_response/pydantic/test_fetch_response.py)

#### 🌐 Endpoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

|Language|Version|Package Manager|Documentation|Source|
|-|-|-|-|-|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-recursively-convert-to-models/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/blob/main/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
|Python|1.0.0|[PyPI](https://pypi.org/project/python-pydantic-recursively-convert-to-models/1.0.0)|[Documentation](https://github.com/konfig-dev/konfig/tree/main/python/README.md)|[Source](https://github.com/konfig-dev/konfig/tree/main/python)|
Loading

0 comments on commit 61ad440

Please sign in to comment.