diff --git a/Scripts/buildOpenAPI.py b/Scripts/buildOpenAPI.py index e9ff3c8c..3c9b5ed2 100644 --- a/Scripts/buildOpenAPI.py +++ b/Scripts/buildOpenAPI.py @@ -9,7 +9,7 @@ import glob import sys import os -from dereferenceAll import dereferenceBrAPI +import dereferenceAll def str_presenter(dumper, data): @@ -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) diff --git a/Scripts/dereferenceAll.py b/Scripts/dereferenceAll.py index 93900331..47076174 100644 --- a/Scripts/dereferenceAll.py +++ b/Scripts/dereferenceAll.py @@ -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 :