-
Notifications
You must be signed in to change notification settings - Fork 411
Selecting a server or setting a custom endpoint #657
Comments
Yup - not really sure just yet. Thanks for digging into all this so much! I've a bit pushed for time right now so might not be reviewing apistar tickets for the next few days, but I'll get back onto it in due course. |
I just ran into this too. According to the spec for the paths object, the path should be appended to the server object's url
but |
+1 I tried to avoid this by stripping leading doc['paths'] = {
path.lstrip('/'): path_item_obj
for path, path_item_obj in doc['paths'].items()
}
apistar.Client(doc) This is because properties of |
The required leading slash is a requirement from OpenAPI itself (see the Paths Object specs). Here is the workaround we used: from urllib.parse import urlsplit
class MyClient(apistar.Client):
def __init__(self, *args, base_url=None, **kwargs):
# Let APIStar do its parsing
super().__init__(*args, **kwargs)
# Strip scheme, hostname and absolute path from all link URLs
for link_info in self.document.walk_links():
original_url = urlsplit(link_info.link.url)
new_url = ('', '', *original_url[2:])
link_info.link.url = urlunsplit(new_url).lstrip('/')
if base_url:
# Ensure the base URL ends with a slash to prevent issues:
# urljoin('http://a/b', 'c') → http://a/c
# urljoin('http://a/b/', 'c') → http://a/b/c
if not base_url.endswith('/'):
base_url += '/'
self.document.base_url = base_url This goes through every parsed link in the |
OpenAPI 3 allows for multiple Server Objects to be defined on a single document; however, it is not currently possible to select which server is wanted with the APIStar client, nor it is to set a custom base URL, except with setting the URL on the schema document itself and updating every
Link
URL.I guess adding a
base_url=...
keyword argument toapistar.Client
isn't hard, but how should one select an existing server from the schema, or list them? Currently, the URL from the first server is used: https://github.com/encode/apistar/blob/master/apistar/schemas/openapi.py#L357The text was updated successfully, but these errors were encountered: