forked from ulaval-rs/openapi-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option return the raw response when using the generated client
- Loading branch information
Showing
9 changed files
with
325 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,7 @@ | |
!tests/ | ||
!tests/** | ||
|
||
!scripts/ | ||
!scripts/** | ||
|
||
*.pyc |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "simple-openapi-client" | ||
version = "0.3.1" | ||
version = "0.4.0" | ||
description = "OpenAPI Python client generator that follows the KISS principle." | ||
authors = ["Gabriel Couture <[email protected]>"] | ||
license = "BSD-3-Clause" | ||
|
@@ -11,11 +11,15 @@ homepage = 'https://github.com/gacou54/openapi-client' | |
python = "^3.8" | ||
httpx = "^0.24.1" | ||
Jinja2 = "^3.1.2" | ||
black = "^22.6.0" | ||
black = "^23.7.0" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^7.1.2" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "^7.4.0" | ||
pytest-asyncio = "^0.21.1" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import simple_openapi_client | ||
|
||
ORTHANC_API_URL = 'https://api.orthanc-server.com/orthanc-openapi.json' | ||
|
||
|
||
def generate_client(path: str, async_mode: bool = False): | ||
config = simple_openapi_client.Config(client_name='AsyncOrthanc' if async_mode else 'Orthanc') | ||
|
||
document = simple_openapi_client.parse_openapi(ORTHANC_API_URL) | ||
document = _apply_corrections_to_documents(document) | ||
client_str = simple_openapi_client.make_client(document, config, async_mode=async_mode) | ||
|
||
with open(path, 'w') as file: | ||
file.write(client_str) | ||
|
||
|
||
def _apply_corrections_to_documents(document): | ||
"""Correcting Orthanc OpenAPI specs""" | ||
to_change = [] | ||
|
||
for route, path in document.paths.items(): | ||
if path.operations is not None: | ||
for operation_name, operation in path.operations.items(): | ||
if operation.parameters is None: | ||
continue | ||
|
||
for param in operation.parameters: | ||
if param.name == '...': | ||
param.name = 'tags_path' | ||
|
||
to_change.append({ | ||
'old_route': route, | ||
'new_route': route + '/{tags_path}', | ||
}) | ||
|
||
for change in to_change: | ||
document.paths[change['new_route']] = document.paths.pop(change['old_route']) | ||
|
||
return document | ||
|
||
|
||
if __name__ == '__main__': | ||
generate_client('./client.py', async_mode=False) | ||
generate_client('./async_client.py', async_mode=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.