Skip to content

Commit

Permalink
fix SwaggerHub allOf display issue
Browse files Browse the repository at this point in the history
  • Loading branch information
BrapiCoordinatorSelby committed Sep 16, 2021
1 parent e6b14f0 commit 22d6175
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Scripts/buildOpenAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import glob
import sys
import os
from dereferenceAll import dereferenceBrAPI
import dereferenceAll


def str_presenter(dumper, data):
Expand Down Expand Up @@ -63,6 +63,8 @@ def go(rootPaths, metaFilePath = './swaggerMetaData.yaml'):
out['paths'].update(paths)
out['components'].update(defin)

out = dereferenceAll.dereferenceAllOfClause(out, out)

with open(outFilePath, 'w') as outfile:
print(outFilePath)
yaml.dump(out, outfile, default_flow_style=False, width=float("inf"), Dumper=noalias_dumper)
Expand Down
32 changes: 32 additions & 0 deletions Scripts/dereferenceAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ def dereferenceAll(obj, parent):
return obj


def dereferenceAllOfClause(obj, parent):
#print(breadCrumb)
try:
if type(obj) is dict:
for fieldStr in obj:
#print(fieldStr)
if(fieldStr == 'allOf'):
comboObj = {'properties': {}, 'type': 'object'}
for item in obj[fieldStr]:
itemObj = dereferenceAll(item, parent)
comboObj['properties'] = {**(comboObj['properties']), **(itemObj['properties'])}
if 'title' in itemObj:
comboObj['title'] = itemObj['title']
if 'description' in itemObj:
comboObj['description'] = itemObj['description']
if 'example' in itemObj:
comboObj['example'] = itemObj['example']

obj = comboObj
else:
obj[fieldStr] = dereferenceAllOfClause(obj[fieldStr], parent)
elif type(obj) is list:
newList = []
for item in obj:
newList.append(dereferenceAllOfClause(item, parent))
obj = newList
except Exception as ex:
##print(obj)
raise ex
return obj


def dereferenceBrAPI(filePath = './brapi_openapi.yaml', verbose = False):
fileObj = {}
if verbose :
Expand Down

0 comments on commit 22d6175

Please sign in to comment.