Skip to content

Commit

Permalink
Merge pull request #44 from TransparentPath/fix/options-resolution
Browse files Browse the repository at this point in the history
Resolved issue in OPTIONS method via Core
  • Loading branch information
vishalajackus committed Mar 9, 2021
2 parents 506431a + 3e9cd80 commit 4f5444a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 8 additions & 4 deletions gateway/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ def prepare_data(self, spec: Spec, **kwargs) -> Tuple[str, str]:
path = f'/{model}/{{{pk_name}}}/'

# Check that operation is valid according to spec
operation = spec.get_op_for_request(self._in_request.method, path)
request_method = self._in_request.method
operation = spec.get_op_for_request(request_method, path)
if not operation:
raise exceptions.EndpointNotFound(f'Endpoint not found: {self._in_request.method} {path}')
if request_method == 'OPTIONS':
operation = spec.get_op_for_request('GET',path)
operation.http_method = request_method
else:
raise exceptions.EndpointNotFound(f'Endpoint not found: {self._in_request.method} {path}')
method = operation.http_method.lower()
path_name = operation.path_name

Expand Down Expand Up @@ -100,7 +105,6 @@ def get_headers(self) -> dict:
headers['content-type'] = 'application/json'
return headers


class SwaggerClient(BaseSwaggerClient):
""" Synchronous implementation of Swagger client using requests lib """

Expand Down Expand Up @@ -180,4 +184,4 @@ async def request(self, **kwargs) -> Tuple[Any, int, Dict[str, str]]:
if self.is_valid_for_cache():
self._data[url] = return_data

return return_data
return return_data
6 changes: 2 additions & 4 deletions gateway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ def put(self, request, *args, **kwargs):
def patch(self, request, *args, **kwargs):
return self.make_service_request(request, *args, **kwargs)

"""Commenting out options function to solve error which does not send response,
response for options method"""
# def options(self, request, *args, **kwargs):
# return self.make_service_request(request, *args, **kwargs)
def options(self, request, *args, **kwargs):
return self.make_service_request(request, *args, **kwargs)

def make_service_request(self, request, *args, **kwargs):
"""
Expand Down

0 comments on commit 4f5444a

Please sign in to comment.