Python/실험실
arg로 받아서 dictionary 만들어주기
두잇 두두
2024. 5. 30. 15:49
728x90
def create_openapi_response(*args):
'''
key, type, description, format_[optional]
'''
properties = {}
for arg in args:
key, type_, description = arg[:3]
format_ = arg[3] if len(arg) > 3 else None
items = arg[4] if len(arg) > 4 else None
prop = {
'type': type_,
'description': description
}
if format_:
prop['format'] = format_
if items:
prop['items'] = items
properties[key] = prop
return {
'type': 'object',
'properties': properties
}