Skip to content

Commit 7ae7a7b

Browse files
committed
Disable enum validation of responses so that additional enum values do not break clients.
1 parent 748cee6 commit 7ae7a7b

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"python.pythonPath": "/opt/conda/bin/python",
3-
"jupyter.jupyterServerType": "local"
3+
"jupyter.jupyterServerType": "local",
4+
"python.testing.unittestEnabled": false,
5+
"python.testing.pytestEnabled": true
46
}

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ async with canopy.Session(authentication_data, proxy=canopy.ProxyConfiguration('
153153

154154
# Updating the OpenAPI Client
155155

156+
This needs to be tidied up, improved, and automated.
157+
156158
You can use the Dockerfile in this repository to create a docker image to generate the new API stubs:
157159

158160
```sh
@@ -185,7 +187,8 @@ cp -r gen/canopy/openapi_asyncio repo/canopy
185187

186188
Note: The `openapi_asyncio/rest.py` file will need to be manually modified to support proxy servers after generation.
187189
Note: The `openapi_asyncio/client_api.py` and `openapi/client_api.py` files will need to be manually modified to
188-
support numpy array serialization after generation.
190+
support numpy array serialization after generation, and disabling of client side validation when deserializing
191+
responses (so that adding to enums in the API doesn't break clients).
189192

190193
## Documentation for OpenAPI Generated Client
191194

canopy/openapi/api_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import tempfile
2222
import numpy as np
23+
import copy
2324

2425
# python 2 and python 3 compatibility library
2526
import six
@@ -82,6 +83,9 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
8283
self.user_agent = 'OpenAPI-Generator/1.0.0/python'
8384
self.client_side_validation = configuration.client_side_validation
8485

86+
self.local_vars_configuration = copy.deepcopy(configuration)
87+
self.local_vars_configuration.client_side_validation = False
88+
8589
def __enter__(self):
8690
return self
8791

@@ -630,7 +634,10 @@ def __deserialize_model(self, data, klass):
630634
'get_real_child_model'):
631635
return data
632636

633-
kwargs = {}
637+
kwargs = {
638+
'local_vars_configuration': self.local_vars_configuration
639+
}
640+
634641
if (data is not None and
635642
klass.openapi_types is not None and
636643
isinstance(data, (list, dict))):

canopy/openapi_asyncio/api_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import tempfile
2222
import numpy as np
23+
import copy
2324

2425
# python 2 and python 3 compatibility library
2526
import six
@@ -82,6 +83,9 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
8283
self.user_agent = 'OpenAPI-Generator/1.0.0/python'
8384
self.client_side_validation = configuration.client_side_validation
8485

86+
self.local_vars_configuration = copy.deepcopy(configuration)
87+
self.local_vars_configuration.client_side_validation = False
88+
8589
async def __aenter__(self):
8690
return self
8791

@@ -631,7 +635,9 @@ def __deserialize_model(self, data, klass):
631635
'get_real_child_model'):
632636
return data
633637

634-
kwargs = {}
638+
kwargs = {
639+
'local_vars_configuration': self.local_vars_configuration
640+
}
635641
if (data is not None and
636642
klass.openapi_types is not None and
637643
isinstance(data, (list, dict))):

liccheck.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Authorized and unauthorized licenses in LOWER CASE
2+
[Licenses]
3+
authorized_licenses:
4+
5+
unauthorized_licenses:
6+
gpl v3
7+
8+
[Authorized Packages]
9+
# Python software license (see http://zesty.ca/python/uuid.README.txt)
10+
uuid: 1.30

print_packages_and_licenses.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pkg_resources
2+
import prettytable
3+
import csv
4+
5+
def get_pkg_license(pkg):
6+
try:
7+
lines = pkg.get_metadata_lines('METADATA')
8+
except:
9+
lines = pkg.get_metadata_lines('PKG-INFO')
10+
11+
for line in lines:
12+
if line.startswith('License:'):
13+
return line[9:]
14+
return '(Licence not found)'
15+
16+
def print_packages_and_licenses():
17+
t = prettytable.PrettyTable(['Package', 'License'])
18+
with open('requirements.txt', 'r') as f:
19+
for line in f:
20+
package_name = line.strip()
21+
pkgs = pkg_resources.require(package_name)
22+
print(package_name)
23+
pkg = pkgs[0]
24+
t.add_row((str(pkg), get_pkg_license(pkg)))
25+
# for pkg in sorted(pkg_resources.working_set, key=lambda x: str(x).lower()):
26+
# t.add_row((str(pkg), get_pkg_license(pkg)))
27+
print(t)
28+
29+
if __name__ == "__main__":
30+
print_packages_and_licenses()

0 commit comments

Comments
 (0)