mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] RequestBody versus params in auto apidoc
This commit is contained in:
parent
2ba20f715e
commit
bd9bedc4b8
4 changed files with 94 additions and 25 deletions
|
@ -7,7 +7,6 @@
|
||||||
<link rel="stylesheet" type="text/css" href="swagger/swagger-ui.css" />
|
<link rel="stylesheet" type="text/css" href="swagger/swagger-ui.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="swagger/index.css" />
|
<link rel="stylesheet" type="text/css" href="swagger/index.css" />
|
||||||
<link rel="icon" type="image/png" href="swagger/favicon-32x32.png" sizes="32x32" />
|
<link rel="icon" type="image/png" href="swagger/favicon-32x32.png" sizes="32x32" />
|
||||||
<link rel="icon" type="image/png" href="swagger/favicon-16x16.png" sizes="16x16" />
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -18,7 +17,6 @@
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
//<editor-fold desc="Changeable Configuration Block">
|
//<editor-fold desc="Changeable Configuration Block">
|
||||||
|
|
||||||
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
|
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
|
||||||
window.ui = SwaggerUIBundle({
|
window.ui = SwaggerUIBundle({
|
||||||
spec: openapiJSON,
|
spec: openapiJSON,
|
||||||
|
|
|
@ -48,11 +48,58 @@ def main():
|
||||||
|
|
||||||
},
|
},
|
||||||
'servers': [
|
'servers': [
|
||||||
{'url': 'https://demo.yunohost.org'},
|
{'url': 'https://demo.yunohost.org/yunohost/api'},
|
||||||
{'url': 'https://'+ domain}
|
{'url': f"https://{domain}/yunohost/api"}
|
||||||
],
|
],
|
||||||
'tags': [],
|
'tags': [
|
||||||
'paths': {}
|
{
|
||||||
|
'name': 'public',
|
||||||
|
'description': 'Public route'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'paths': {
|
||||||
|
'/login': {
|
||||||
|
'post': {
|
||||||
|
'tags': ['public'],
|
||||||
|
'summary': 'Logs in and returns the authentication cookie',
|
||||||
|
'requestBody': {
|
||||||
|
'required': True,
|
||||||
|
'content': {
|
||||||
|
'multipart/form-data': {
|
||||||
|
'schema': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'password': {
|
||||||
|
'type': 'string',
|
||||||
|
'format': 'password'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'required': [
|
||||||
|
'password'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'security': [],
|
||||||
|
'responses': {
|
||||||
|
'200': {
|
||||||
|
'description': 'Successfully login'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'components': {
|
||||||
|
'securitySchemes': {
|
||||||
|
'cookieAuth': {
|
||||||
|
'type': 'apiKey',
|
||||||
|
'in': 'cookie',
|
||||||
|
'name': 'session.yunohost.admin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'security': {'cookieAuth': [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,6 +129,7 @@ def main():
|
||||||
for i, api in enumerate(action_params['api']):
|
for i, api in enumerate(action_params['api']):
|
||||||
print(api)
|
print(api)
|
||||||
method, path = api.split(' ')
|
method, path = api.split(' ')
|
||||||
|
method = method.lower()
|
||||||
key_param = ''
|
key_param = ''
|
||||||
if '{' in path:
|
if '{' in path:
|
||||||
key_param = path[path.find("{")+1:path.find("}")]
|
key_param = path[path.find("{")+1:path.find("}")]
|
||||||
|
@ -105,6 +153,21 @@ def main():
|
||||||
}
|
}
|
||||||
|
|
||||||
if 'arguments' in action_params:
|
if 'arguments' in action_params:
|
||||||
|
if method in ['put', 'post', 'patch']:
|
||||||
|
operation['requestBody'] = {
|
||||||
|
'required': True,
|
||||||
|
'content': {
|
||||||
|
'multipart/form-data': {
|
||||||
|
'schema': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
},
|
||||||
|
'required': []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
operation['parameters'] = []
|
operation['parameters'] = []
|
||||||
for arg_name, arg_params in action_params['arguments'].items():
|
for arg_name, arg_params in action_params['arguments'].items():
|
||||||
if 'help' not in arg_params:
|
if 'help' not in arg_params:
|
||||||
|
@ -132,10 +195,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
allow_multiple = False
|
allow_multiple = False
|
||||||
if 'choices' in arg_params:
|
if 'choices' in arg_params:
|
||||||
allowable_values = {
|
allowable_values = arg_params['choices']
|
||||||
'valueType': 'LIST',
|
|
||||||
'values': arg_params['choices']
|
|
||||||
}
|
|
||||||
if 'action' in arg_params and arg_params['action'] == 'store_true':
|
if 'action' in arg_params and arg_params['action'] == 'store_true':
|
||||||
allowable_values = {
|
allowable_values = {
|
||||||
'valueType': 'LIST',
|
'valueType': 'LIST',
|
||||||
|
@ -147,6 +207,17 @@ def main():
|
||||||
required = True
|
required = True
|
||||||
allow_multiple = False
|
allow_multiple = False
|
||||||
|
|
||||||
|
if method in ['put', 'post', 'patch']:
|
||||||
|
schema = operation['requestBody']['content']['multipart/form-data']['schema']
|
||||||
|
schema['properties'][name] = {
|
||||||
|
'type': 'string',
|
||||||
|
'description': arg_params['help']
|
||||||
|
}
|
||||||
|
if required:
|
||||||
|
schema['required'].append(name)
|
||||||
|
if allowable_values is not None:
|
||||||
|
schema['properties'][name]['enum'] = allowable_values
|
||||||
|
else:
|
||||||
parameters = {
|
parameters = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'in': param_type,
|
'in': param_type,
|
||||||
|
@ -157,8 +228,8 @@ def main():
|
||||||
},
|
},
|
||||||
'explode': allow_multiple
|
'explode': allow_multiple
|
||||||
}
|
}
|
||||||
#if allowable_values is not None:
|
if allowable_values is not None:
|
||||||
# parameters['allowableValues'] = allowable_values
|
parameters['schema']['enum'] = allowable_values
|
||||||
|
|
||||||
operation['parameters'].append(parameters)
|
operation['parameters'].append(parameters)
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue