Skip to content

Commit

Permalink
Extract base_path (if present) from url.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichar1 committed Jan 31, 2018
1 parent dcc5d2d commit d7e2c43
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pyramid_jsonapi/metadata/OpenAPI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def openapi_spec(self, request=None): # pylint:disable=unused-argument
OpenAPI template document.
"""

return self.generate_openapi()
return self.generate_openapi(request=request)

@functools.lru_cache()
def generate_pkg_metadata(self):
Expand Down Expand Up @@ -201,7 +201,7 @@ def recurse_replace_in_value(self, obj, old, new):
return new_obj

@functools.lru_cache()
def generate_openapi(self):
def generate_openapi(self, request=None):
"""Generate openapi documentation."""

# OpenAPI 'template'
Expand All @@ -228,6 +228,15 @@ def generate_openapi(self):
}

ep_data = self.api.endpoint_data

# Split the route_path using the metadata_pattern.
# any prefixes are then prefixed to path_name later
# This handles hosting from a sub-directory.
base_path = None
if request:
path_pattern = ep_data.rp_constructor.metadata_pattern('OpenAPI')
base_path, _ = request.current_route_path().split(path_pattern, 1)

paths = {}
# Iterate through all view_classes, getting name (for path)
for model, view_class in self.api.view_classes.items():
Expand All @@ -239,7 +248,8 @@ def generate_openapi(self):
name,
ep_data.route_pattern_to_suffix(
opts.get('route_pattern', {})
)
),
base=base_path or '/',
)
paths[path_name] = {}
for method in opts['http_methods']:
Expand Down

0 comments on commit d7e2c43

Please sign in to comment.