Commit d71407d6 authored by Joan Pascual Sana's avatar Joan Pascual Sana

Store responses on separated objects

parent 3c8f0f36
......@@ -172,7 +172,7 @@ class Documentation():
# Generate the indeted reference to get the return objects serialized
def generateOutputElemsValues(self):
s = "\n" + tab + tab + tab + tab + tab + tab + tab + tab
s = "\n" + tab + tab + tab
sprops = "properties:"
if self.hasRetVal():
sprops += s + tab + "retval:"
......@@ -198,8 +198,9 @@ class Documentation():
# Used for openapi body request parameter properties
def generateProperties(self):
s = '\n' + tab + tab + tab + tab
return s.join(p._name + ':' + p.getIndentedTypeReference(s + tab ) for p in self._paramsIn)
s = '\n' + tab + tab + tab
sprops = s + "properties:"
return sprops + ''.join(s + tab + p._name + ':' + p.getIndentedTypeReference(s + tab + tab ) for p in self._paramsIn)
def getText(e):
......@@ -431,7 +432,6 @@ def processFile(file):
substitutionsMap['detailedDesc'] = doc.generateDetailed()
substitutionsMap['return'] = doc.getReturn()
substitutionsMap['outputDescription'] = doc.generateOutputElems()
substitutionsMap['outputVals'] = doc.generateOutputElemsValues() if doc.hasOutParams() else ''
substitutionsMap['deprecated'] = 'true' if doc._detailed.lower() == 'deprecated' else 'false'
substitutionsMap['methodName'] = methodName
......@@ -447,9 +447,15 @@ def processFile(file):
requestBody = TemplateOwn(open(SUBREQUESTBODY, 'r').read())
requestBody = requestBody.safe_substitute(detailedDesc=doc.generateDetailed(), reqReference=reqReference,
examples=doc.generateDetailed())
rsRequestsMap.update({reqReference: doc.generateProperties()})
rsReqRespMap.update({reqReference: doc.generateProperties()})
substitutionsMap['requestBody'] = requestBody
substitutionsMap['respReference'] = 'type: object'
if doc.hasOutParams():
respReference = 'Resp' + operationId
substitutionsMap['respReference'] = "$ref: '#/components/schemas/" + respReference + "'"
rsReqRespMap.update({respReference: doc.generateOutputElemsValues()})
substitutionsMap['requiresAuth'] = 'security:\n'+ tab + tab + tab + tab + '- BasicAuth: []' if requiresAuth else ''
substitutionsMap['requiresAuthBadResponse'] = "'401':\n" + tab + tab + tab + tab + tab + "$ref: '#/components/responses/UnauthorizedError'" if requiresAuth else ''
......@@ -693,7 +699,7 @@ def initializeClassesFile():
# Write the requests objects
templFile = open(TEMPLATE_REQUESTS, 'r')
wrapperDef = TemplateOwn(templFile.read())
for reqName, reqProps in rsRequestsMap.items():
for reqName, reqProps in rsReqRespMap.items():
substitutionsMap = dict()
substitutionsMap["reqName"] = reqName
substitutionsMap["properties"] = reqProps
......@@ -762,7 +768,7 @@ TEMPLATE_RSCLASS='tmpl/openapi/openapi-rsclass.tmpl' # Template for RsClass wrap
TEMPLATE_RSCLASS_ENUM='tmpl/openapi/openapi-rsclass-enum.tmpl' # Template for RsClass enum type
HEADERTMPL='tmpl/openapi/openapi-header.tmpl' # Header template for api wrapper library
COMPONENTSTMPL='tmpl/openapi/openapi-components.tmpl' # Initialize components section
TEMPLATE_REQUESTS='tmpl/openapi/openapi-requests.tmpl' # Template for requests
TEMPLATE_REQUESTS='tmpl/openapi/openapi-requests-responses.tmpl' # Template for requests
# Used to create RsClasses, this map the RS metaclasses to python primitive types
# Where the key is the rfid of the data type in question
......@@ -786,8 +792,8 @@ wrapperDefWrite(open(HEADERTMPL, 'r').read())
# Used to store the parameters that maybe are classes with mMeta, for example rsGxsForumMsg
rsClassMap = {}
# It stores each request to create an independent object referencable with $ref on components section
rsRequestsMap = {}
# It stores each request and response to create an independent object referencable with $ref on components section
rsReqRespMap = {}
try:
for file in os.listdir(doxPrefix):
......
......@@ -14,6 +14,7 @@ $%requestBody%$
content:
application/json:
schema:
type: object
$%outputVals%$
$%respReference%$
$%requiresAuthBadResponse%$
$%reqName%$:
type: object
properties:
$%properties%$
\ No newline at end of file
$%properties%$
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment