Skip to content

Commit 56b6886

Browse files
committed
Improve docstring layout
1 parent 3d9faf6 commit 56b6886

5 files changed

Lines changed: 86 additions & 84 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "simple-openapi-client"
3-
version = "0.5.3"
3+
version = "0.5.4"
44
description = "OpenAPI Python client generator that follows the KISS principle."
55
authors = ["Gabriel Couture <gacou54@gmail.ca>"]
66
license = "BSD-3-Clause"
@@ -11,10 +11,7 @@ homepage = 'https://github.com/gacou54/openapi-client'
1111
python = "^3.8"
1212
httpx = "^0"
1313
Jinja2 = "^3.1.2"
14-
black = "^23.7.0"
15-
16-
[tool.poetry.dev-dependencies]
17-
pytest = "^7.1.2"
14+
black = "^24.4.2"
1815

1916
[tool.poetry.group.dev.dependencies]
2017
pytest = "^7.4.0"

scripts/make_orthanc_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import simple_openapi_client
22

3-
ORTHANC_API_URL = 'https://api.orthanc-server.com/orthanc-openapi.json'
3+
ORTHANC_API_URL = 'https://orthanc.uclouvain.be/api/orthanc-openapi.json'
44

55

66
def generate_client(path: str, async_mode: bool = False):
77
config = simple_openapi_client.Config(client_name='AsyncOrthanc' if async_mode else 'Orthanc')
88

99
document = simple_openapi_client.parse_openapi(ORTHANC_API_URL)
1010
document = _apply_corrections_to_documents(document)
11-
client_str = simple_openapi_client.make_client(document, config, async_mode=async_mode)
11+
client_str = simple_openapi_client.make_client(document, config, async_mode=async_mode, use_black=True)
1212

1313
with open(path, 'w') as file:
1414
file.write(client_str)

simple_openapi_client/templates/async_method.jinja

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,65 @@
2222
Tags: {{ ','.join(OPERATION.tags) }}
2323
{%- if OPERATION.externalDocs %}ExternaDocs: {{ OPERATION.externalDocs }}{% endif %}
2424

25+
{%- if PATH_PARAMETERS or REQUEST_BODY.json or REQUEST_BODY.files or REQUEST_BODY.data or QUERY_PARAMETERS or HEADERS %}
26+
2527
Parameters
2628
----------
27-
{% if PATH_PARAMETERS -%}
28-
{% for name, description in PATH_PARAMETERS.items() -%}
29+
{%- if PATH_PARAMETERS %}
30+
{%- for name, description in PATH_PARAMETERS.items() %}
2931
{{ name }}
3032
{{ description }}
31-
{% endfor -%}
32-
{% endif -%}
33-
34-
{% if REQUEST_BODY.json %}json
33+
{%- endfor %}
34+
{%- endif %}
35+
{%- if REQUEST_BODY.json %}
36+
json
3537
{%- for request_data in REQUEST_BODY.json %}
36-
{% if request_data -%}
38+
{%- if request_data %}
3739
Dictionary with the following keys:
3840
{%- for property_name, property in request_data.properties.items() %}
39-
"{{ property_name }}": {{ property['description'] }}
41+
"{{ property_name }}": {{ property['description'] }}
4042
{%- endfor %}
41-
{%- endif -%}
43+
{%- endif %}
4244
{% endfor -%}
43-
{% endif -%}
44-
45-
{% if REQUEST_BODY.files %}files
45+
{%- endif %}
46+
{%- if REQUEST_BODY.files %}
47+
files
4648
{%- for request_data in REQUEST_BODY.files %}
47-
{% if request_data -%}Files:
49+
{%- if request_data %}
50+
Files:
4851
{%- for property_name, property in request_data.properties.items() %}
4952
"{{ property_name }}": {{ property['description'] }}
5053
{%- endfor %}
51-
{%- endif -%}
54+
{%- endif %}
5255
{% endfor -%}
53-
{% endif -%}
54-
55-
{% if REQUEST_BODY.data %}
56+
{%- endif %}
57+
{%- if REQUEST_BODY.data %}
5658
data
5759
{%- for request_data in REQUEST_BODY.data %}
5860
{{ request_data.description }}
59-
{% endfor -%}
60-
{% endif -%}
61-
62-
{% if REQUEST_BODY.content %}content
63-
{%- for request_data in REQUEST_BODY.content %}
64-
- (Content-Type: "{{ request_data.content_type }}") {{ request_data.description }}
65-
{% endfor -%}
66-
{% endif -%}
67-
68-
{% if QUERY_PARAMETERS -%}
61+
{%- endfor -%}
62+
{%- endif %}
63+
{%- if REQUEST_BODY.content %}
64+
content
65+
{%- for request_data in REQUEST_BODY.content %}
66+
- (Content-Type: "{{ request_data.content_type }}") {{ request_data.description }}
67+
{%- endfor %}
68+
{%- endif %}
69+
{%- if QUERY_PARAMETERS %}
6970
params
7071
Dictionary of optional parameters:
71-
{%- for name, query in QUERY_PARAMETERS.items() %}
72-
"{{ name }}" ({{ query.type }}): {{ query.description }}
73-
{%- endfor -%}
74-
{% endif -%}
75-
76-
{% if HEADERS -%}
72+
{%- for name, query in QUERY_PARAMETERS.items() %}
73+
"{{ name }}" ({{ query.type }}): {{ query.description }}
74+
{%- endfor %}
75+
{%- endif %}
76+
{%- if HEADERS %}
7777
headers
7878
Dictionary of optional headers:
79-
{% for name, header in HEADERS.items() -%}
79+
{%- for name, header in HEADERS.items() %}
8080
"{{ name }}" ({{ header.type }}): {{ header.description }}
81-
{% endfor -%}
82-
{% endif %}
81+
{%- endfor %}
82+
{%- endif %}
83+
{%- endif %}
8384

8485
Returns
8586
-------

simple_openapi_client/templates/method.jinja

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,65 @@
2222
Tags: {{ ','.join(OPERATION.tags) }}
2323
{%- if OPERATION.externalDocs %}ExternaDocs: {{ OPERATION.externalDocs }}{% endif %}
2424

25+
{%- if PATH_PARAMETERS or REQUEST_BODY.json or REQUEST_BODY.files or REQUEST_BODY.data or QUERY_PARAMETERS or HEADERS %}
26+
2527
Parameters
2628
----------
27-
{% if PATH_PARAMETERS -%}
28-
{% for name, description in PATH_PARAMETERS.items() -%}
29+
{%- if PATH_PARAMETERS %}
30+
{%- for name, description in PATH_PARAMETERS.items() %}
2931
{{ name }}
3032
{{ description }}
31-
{% endfor -%}
32-
{% endif -%}
33-
34-
{% if REQUEST_BODY.json %}json
33+
{%- endfor %}
34+
{%- endif %}
35+
{%- if REQUEST_BODY.json %}
36+
json
3537
{%- for request_data in REQUEST_BODY.json %}
36-
{% if request_data -%}
38+
{%- if request_data %}
3739
Dictionary with the following keys:
3840
{%- for property_name, property in request_data.properties.items() %}
39-
"{{ property_name }}": {{ property['description'] }}
41+
"{{ property_name }}": {{ property['description'] }}
4042
{%- endfor %}
41-
{%- endif -%}
43+
{%- endif %}
4244
{% endfor -%}
43-
{% endif -%}
44-
45-
{% if REQUEST_BODY.files %}files
45+
{%- endif %}
46+
{%- if REQUEST_BODY.files %}
47+
files
4648
{%- for request_data in REQUEST_BODY.files %}
47-
{% if request_data -%}Files:
49+
{%- if request_data %}
50+
Files:
4851
{%- for property_name, property in request_data.properties.items() %}
4952
"{{ property_name }}": {{ property['description'] }}
5053
{%- endfor %}
51-
{%- endif -%}
54+
{%- endif %}
5255
{% endfor -%}
53-
{% endif -%}
54-
55-
{% if REQUEST_BODY.data %}
56+
{%- endif %}
57+
{%- if REQUEST_BODY.data %}
5658
data
5759
{%- for request_data in REQUEST_BODY.data %}
5860
{{ request_data.description }}
59-
{% endfor -%}
60-
{% endif -%}
61-
62-
{% if REQUEST_BODY.content %}content
63-
{%- for request_data in REQUEST_BODY.content %}
64-
- (Content-Type: "{{ request_data.content_type }}") {{ request_data.description }}
65-
{% endfor -%}
66-
{% endif -%}
67-
68-
{% if QUERY_PARAMETERS -%}
61+
{%- endfor -%}
62+
{%- endif %}
63+
{%- if REQUEST_BODY.content %}
64+
content
65+
{%- for request_data in REQUEST_BODY.content %}
66+
- (Content-Type: "{{ request_data.content_type }}") {{ request_data.description }}
67+
{%- endfor %}
68+
{%- endif %}
69+
{%- if QUERY_PARAMETERS %}
6970
params
7071
Dictionary of optional parameters:
71-
{%- for name, query in QUERY_PARAMETERS.items() %}
72-
"{{ name }}" ({{ query.type }}): {{ query.description }}
73-
{%- endfor -%}
74-
{% endif -%}
75-
76-
{% if HEADERS -%}
72+
{%- for name, query in QUERY_PARAMETERS.items() %}
73+
"{{ name }}" ({{ query.type }}): {{ query.description }}
74+
{%- endfor %}
75+
{%- endif %}
76+
{%- if HEADERS %}
7777
headers
7878
Dictionary of optional headers:
79-
{% for name, header in HEADERS.items() -%}
79+
{%- for name, header in HEADERS.items() %}
8080
"{{ name }}" ({{ header.type }}): {{ header.description }}
81-
{% endfor -%}
82-
{% endif %}
81+
{%- endfor %}
82+
{%- endif %}
83+
{%- endif %}
8384

8485
Returns
8586
-------

tests/test_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
import simple_openapi_client
66

7-
OPENAPI_URL = 'https://api.orthanc-server.com/orthanc-openapi.json'
7+
8+
ORTHANC_DEMO_URL = 'https://orthanc.uclouvain.be/demo'
9+
10+
OPENAPI_URL = 'https://orthanc.uclouvain.be/api/orthanc-openapi.json'
811
CLIENT_PATH = 'generated_client.py'
912
CLIENT_MODULE = 'generated_client'
1013

@@ -66,7 +69,7 @@ def _apply_corrections_to_documents(document):
6669

6770
def test_client(generate_client):
6871
client_class = getattr(__import__(CLIENT_MODULE), CLIENT_NAME)
69-
client = client_class(url='https://demo.orthanc-server.com')
72+
client = client_class(url=ORTHANC_DEMO_URL)
7073

7174
result = client.get_system()
7275

@@ -75,7 +78,7 @@ def test_client(generate_client):
7578
assert 'DicomAet' in result
7679
assert 'DicomPort' in result
7780

78-
with client_class(url='https://demo.orthanc-server.com') as client:
81+
with client_class(url=ORTHANC_DEMO_URL) as client:
7982
result = client.get_system()
8083

8184
assert isinstance(result, dict)
@@ -87,7 +90,7 @@ def test_client(generate_client):
8790
@pytest.mark.asyncio
8891
async def test_async_client(generate_client):
8992
async_client_class = getattr(__import__(ASYNC_CLIENT_MODULE), CLIENT_NAME)
90-
async_client = async_client_class(url='https://demo.orthanc-server.com')
93+
async_client = async_client_class(url=ORTHANC_DEMO_URL)
9194

9295
result = await async_client.get_system()
9396

@@ -96,7 +99,7 @@ async def test_async_client(generate_client):
9699
assert 'DicomAet' in result
97100
assert 'DicomPort' in result
98101

99-
async with async_client_class(url='https://demo.orthanc-server.com') as async_client:
102+
async with async_client_class(url=ORTHANC_DEMO_URL) as async_client:
100103
result = await async_client.get_system()
101104

102105
assert isinstance(result, dict)

0 commit comments

Comments
 (0)