Skip to content

Commit

Permalink
Swagger-UI (PoC) implement get_body_content (replacement for ajaxGetB…
Browse files Browse the repository at this point in the history
…odyContent)
  • Loading branch information
zmsdev committed Jun 29, 2023
1 parent 44f3dc3 commit 91ebff0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Products/zms/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ class RestApiController(object):
def __init__(self, context, TraversalRequest):
self.context = context
self.method = TraversalRequest['REQUEST_METHOD']
for id in TraversalRequest['path_to_handle'][1:]:
self.ids = TraversalRequest['path_to_handle'][1:]
while self.ids:
id = self.ids[0]
context = getattr(self.context, id, None)
if context is None:
break
self.context = getattr(self.context, id)
self.ids.remove(id)

def __bobo_traverse__(self, TraversalRequest, name):
return self
Expand All @@ -46,15 +52,20 @@ def __call__(self, REQUEST=None, **kw):
l = catalog(REQUEST.form)
data = [{item_name:r[item_name] for item_name in catalog.schema()} for r in l]
else:
data = {}
data['id'] = self.context.id
data['meta_id'] = self.context.meta_id
data['uid'] = self.context.get_uid()
obj_attrs = self.context.getObjAttrs()
metaobj_attrs = self.context.getMetaobjManager().getMetaobjAttrs(self.context.meta_id)
for metaobj_attr in metaobj_attrs:
id = metaobj_attr['id']
if id in obj_attrs:
data[id] = self.context.attr(id)
if self.ids == ['get_body_content']:
REQUEST.RESPONSE.setHeader('Content-Type','text/html')
return context.getBodyContent(REQUEST,forced=False)
else:
data = {}
data['id'] = context.id
data['meta_id'] = context.meta_id
data['uid'] = context.get_uid()
obj_attrs = context.getObjAttrs()
metaobj_attrs = context.getMetaobjManager().getMetaobjAttrs(self.context.meta_id)
for metaobj_attr in metaobj_attrs:
id = metaobj_attr['id']
if id in obj_attrs:
data[id] = context.attr(id)
REQUEST.RESPONSE.setHeader('Content-Type','application/json')
return json.dumps(data)
return None
18 changes: 18 additions & 0 deletions Products/zms/zpt/ZMS/openapi_yaml.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ paths:
application/json:
schema:
$ref: '#/components/responses/ZMSObjectResponse'
<tal:block tal:content="python:'/'.join(here.getDocumentElement().getPhysicalPath())"></tal:block>/++rest_api{path}/get_body_content:
get:
summary: Returns body-content of a ZMS-object.
description: get body-content of ZMS-objects
parameters:
- name: path
in: path
description: id-path to resource
required: false
schema:
type: string
example: /
responses:
'200': # status code
description: A JSON array of user names
content:
text/html:
type: string
components:
responses:
ZMSObjectResponse:
Expand Down

0 comments on commit 91ebff0

Please sign in to comment.