diff --git a/CHANGELOG.md b/CHANGELOG.md index 54ad820ec..6225fb36d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes - Fixed spacing and generation of properties of type `Union` in generated models (#241 - Thanks @packyg!). +- Fixed usage instructions in generated README.md (#247 - Thanks @theFong!). ## 0.6.2 - 2020-11-03 diff --git a/end_to_end_tests/golden-record-custom/README.md b/end_to_end_tests/golden-record-custom/README.md index dcc70600f..836d52d62 100644 --- a/end_to_end_tests/golden-record-custom/README.md +++ b/end_to_end_tests/golden-record-custom/README.md @@ -23,8 +23,11 @@ Now call your endpoint and use your models: ```python from custom_e2e.models import MyDataModel from custom_e2e.api.my_tag import get_my_data_model +from custom_e2e.types import Response -my_data: MyDataModel = get_my_data_model(client=client) +my_data: MyDataModel = get_my_data_model.sync(client=client) +# or if you need more info (e.g. status_code) +response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) ``` Or do the same thing with an async version: @@ -32,19 +35,22 @@ Or do the same thing with an async version: ```python from custom_e2e.models import MyDataModel from custom_e2e.async_api.my_tag import get_my_data_model +from custom_e2e.types import Response -my_data: MyDataModel = await get_my_data_model(client=client) +my_data: MyDataModel = await get_my_data_model.asyncio(client=client) +response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) ``` Things to know: -1. Every path/method combo becomes a Python function with type annotations. +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but the async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` by async instead of blocking + 1. All path/query params, and bodies become method arguments. 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) -1. Any endpoint which did not have a tag will be in `custom_e2e.api.default` -1. If the API returns a response code that was not declared in the OpenAPI document, a - `custom_e2e.api.errors.ApiResponseError` wil be raised - with the `response` attribute set to the `httpx.Response` that was received. - +1. Any endpoint which did not have a tag will be in `custom_e2e.api.default` ## Building / publishing this Client This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: diff --git a/end_to_end_tests/golden-record/README.md b/end_to_end_tests/golden-record/README.md index fbbe00c2f..1f9c3a6ee 100644 --- a/end_to_end_tests/golden-record/README.md +++ b/end_to_end_tests/golden-record/README.md @@ -23,8 +23,11 @@ Now call your endpoint and use your models: ```python from my_test_api_client.models import MyDataModel from my_test_api_client.api.my_tag import get_my_data_model +from my_test_api_client.types import Response -my_data: MyDataModel = get_my_data_model(client=client) +my_data: MyDataModel = get_my_data_model.sync(client=client) +# or if you need more info (e.g. status_code) +response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) ``` Or do the same thing with an async version: @@ -32,19 +35,22 @@ Or do the same thing with an async version: ```python from my_test_api_client.models import MyDataModel from my_test_api_client.async_api.my_tag import get_my_data_model +from my_test_api_client.types import Response -my_data: MyDataModel = await get_my_data_model(client=client) +my_data: MyDataModel = await get_my_data_model.asyncio(client=client) +response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) ``` Things to know: -1. Every path/method combo becomes a Python function with type annotations. +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but the async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` by async instead of blocking + 1. All path/query params, and bodies become method arguments. 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) -1. Any endpoint which did not have a tag will be in `my_test_api_client.api.default` -1. If the API returns a response code that was not declared in the OpenAPI document, a - `my_test_api_client.api.errors.ApiResponseError` wil be raised - with the `response` attribute set to the `httpx.Response` that was received. - +1. Any endpoint which did not have a tag will be in `my_test_api_client.api.default` ## Building / publishing this Client This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: diff --git a/openapi_python_client/templates/README.md b/openapi_python_client/templates/README.md index 5272e3fd1..767bf9de0 100644 --- a/openapi_python_client/templates/README.md +++ b/openapi_python_client/templates/README.md @@ -23,8 +23,11 @@ Now call your endpoint and use your models: ```python from {{ package_name }}.models import MyDataModel from {{ package_name }}.api.my_tag import get_my_data_model +from {{ package_name }}.types import Response -my_data: MyDataModel = get_my_data_model(client=client) +my_data: MyDataModel = get_my_data_model.sync(client=client) +# or if you need more info (e.g. status_code) +response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) ``` Or do the same thing with an async version: @@ -32,19 +35,22 @@ Or do the same thing with an async version: ```python from {{ package_name }}.models import MyDataModel from {{ package_name }}.async_api.my_tag import get_my_data_model +from {{ package_name }}.types import Response -my_data: MyDataModel = await get_my_data_model(client=client) +my_data: MyDataModel = await get_my_data_model.asyncio(client=client) +response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) ``` Things to know: -1. Every path/method combo becomes a Python function with type annotations. +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but the async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` by async instead of blocking + 1. All path/query params, and bodies become method arguments. 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) -1. Any endpoint which did not have a tag will be in `{{ package_name }}.api.default` -1. If the API returns a response code that was not declared in the OpenAPI document, a - `{{ package_name }}.api.errors.ApiResponseError` wil be raised - with the `response` attribute set to the `httpx.Response` that was received. - +1. Any endpoint which did not have a tag will be in `{{ package_name }}.api.default` ## Building / publishing this Client This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: