Commit 3e2f6d15 authored by janis.streib's avatar janis.streib 🦉
Browse files

FIX: new api format and non existent defaults

parent f0b0e083
Pipeline #59505 passed with stages
in 4 minutes and 34 seconds
......@@ -44,6 +44,9 @@ if not request.status_code == 200:
print("Is the NETDB_AUTH environment variable correct?")
exit(1)
func_index = request.json()[0]
data_types = {k['name']: k for k in sess.get(
"{scheme}://{base_host}{base_url}/cntl/data_type/list".format(scheme=API_SCHEME, base_host=API_HOST,
base_url=API_BASE_URL)).json()[0]}
for f in func_index:
fname = '{system}.{object_type}.js'.format(system=f['system'], object_type=f['object_type'])
f_handle = files.get(fname, None)
......@@ -65,28 +68,41 @@ export default {
params_dict_new = '{'
params_dict_old = '{'
for (p, v) in f['parameters'].items():
old_def_def = False
new_def_def = False
old_default = None
new_default = None
p_esc = p
for (unesc, esc) in keyword_replacements.items():
p_esc = p_esc.replace(unesc, esc)
if 'old' in v:
old_default = v['old']['dataDefault']
old_def_def = 'dataDefault' in v['old']
if old_def_def:
old_default = v['old']['dataDefault']
if 'new' in v:
new_default = v['new']['dataDefault']
if v['dataType']['jsonName'] == 'string':
new_def_def = 'dataDefault' in v['new']
if new_def_def:
new_default = v['new']['dataDefault']
v['dataType'] = data_types[v['dataType']]
if v['dataType']['json_name'] == 'string':
if old_default is not None:
old_default = '"{}"'.format(old_default)
if new_default is not None:
new_default = '"{}"'.format(new_default)
if 'old' in v:
if not f['is_data_manipulating'] and v['dataType']['jsonName'] == 'array':
if not f['is_data_manipulating'] and v['dataType']['json_name'] == 'array':
params_dict_old += '\'{p}\': ({p_esc}_old===null)?null:JSON.stringify({p}_old), '.format(p_esc=p, p=p)
else:
params_dict_old += '\'{p}\': {p_esc}_old, '.format(p=p, p_esc=p_esc)
params_str += '{p_esc}_old={d}, '.format(p_esc=p_esc, p=p, d=old_default)
if old_def_def:
params_str += '{p_esc}_old={d}, '.format(p_esc=p_esc, p=p, d=old_default)
else:
params_str += '{p_esc}_old, '.format(p_esc=p_esc, p=p)
if 'new' in v:
params_str += '{p}_new={d}, '.format(p=p, d=new_default)
if new_def_def:
params_str += '{p}_new={d}, '.format(p=p, d=new_default)
else:
params_str += '{p}_new, '.format(p=p)
params_dict_new += '\'{p}\': {p}_new, '.format(p=p)
params_dict_new += '}'
......@@ -134,40 +150,62 @@ for f in files.values():
f.close()
def setDef(tmp):
res = []
for r in tmp:
if 'schema' in r:
if not r['schema']['has_def']:
del (r['schema']['default'])
del (r['schema']['has_def'])
res.append(r)
else:
if not r['has_def']:
del (r['default'])
del (r['has_def'])
res.append(r)
return res
def generateParamters(f):
if not f['is_data_manipulating']:
return [
tmp = [
{
'name': p, 'description': d['description'],
'required': d['old']['isRequired'] if 'old' in d else d['new']['isRequired'],
'schema': {
'type': d['dataType']['jsonName'],
'default': d['old']['dataDefault'],
'type': d['dataType']['json_name'],
'nullable': d['old']['isNullable'],
'has_def': 'dataDefault' in d['old'],
'default': d['old'].get('dataDefault', None)
},
'in': 'query'
}
for p, d in f['parameters'].items()]
return setDef(tmp)
new_params = {
p: {
'type': d['dataType']['jsonName'],
'type': d['dataType']['json_name'],
'description': d['description'],
'required': d['new']['isRequired'],
'nullable': d['new']['isNullable'],
'default': d['new']['dataDefault']
'has_def': 'dataDefault' in d['new'],
'default': d['new'].get('dataDefault', None)
}
for p, d in f['parameters'].items() if 'new' in d
}
old_params = {
p: {
'type': d['dataType']['jsonName'],
'type': d['dataType']['json_name'],
'description': d['description'],
'required': d['old']['isRequired'],
'nullable': d['old']['isNullable'],
'default': d['old']['dataDefault']
'has_def': 'dataDefault' in d['old'],
'default': d['old'].get('dataDefault', None)
}
for p, d in f['parameters'].items() if 'old' in d
}
old_params = {k: setDef([v])[0] for k, v in old_params.items()}
new_params = {k: setDef([v])[0] for k, v in new_params.items()}
props = {}
if len(old_params) > 0:
props['old'] = {
......@@ -213,7 +251,7 @@ swagger['paths'] = {f"/{f['system']}/{f['object_type']}/{f['name']}":
'schema': {
'type': 'array',
'items': {
'$ref': '#/definitions/' + f['system']+'.'+f['object_type']
'$ref': '#/definitions/' + f['system'] + '.' + f['object_type']
}
} if f['is_returning'] else None
},
......@@ -232,16 +270,20 @@ swagger['paths'] = {f"/{f['system']}/{f['object_type']}/{f['name']}":
def renderDataType(d):
dat = {'type': d['dataType']['jsonName'],
dat = {'type': d['dataType']['json_name'],
'description': d['description']
}
if d['dataType']['apiName'] == 'text_array':
if d['dataType']['name'] == 'text_array':
dat['items'] = {
'type': 'string'
}
return dat
for o in objects:
for a,d in o['attributes'].items():
d['dataType'] = data_types[d['dataType']]
swagger['definitions'] = {o['fq_name']:
{
'type': 'object',
......
Supports Markdown
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