mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-12 10:05:39 +00:00
[FR] Update to OpenAPI from CoreAPI (#4178)
* [FR] Update to OpenAPI from CoreAPI Fixes #3226 * factor request function out * add schema export task * add api-docs * add action to check if diff occured * also wait for docstyle * use full command * add envs for inventree * update inventree before running * use relative path * remove schema action * remove tags to fit 3.0 parsers * fix url base name for reloads * revert change in plugin resolver * remove unused tags * add rapidoc too * declare api regex * fix as suggested by @martonmiklos in https://github.com/inventree/InvenTree/pull/4178#discussion_r1167279443 * set inventree logo * remove Rapidoc
This commit is contained in:
34
tasks.py
34
tasks.py
@ -88,6 +88,22 @@ def manage(c, cmd, pty: bool = False):
|
||||
), pty=pty)
|
||||
|
||||
|
||||
def check_file_existance(filename: str, overwrite: bool = False):
|
||||
"""Checks if a file exists and asks the user if it should be overwritten.
|
||||
|
||||
Args:
|
||||
filename (str): Name of the file to check.
|
||||
overwrite (bool, optional): Overwrite the file without asking. Defaults to False.
|
||||
"""
|
||||
if Path(filename).is_file() and overwrite is False:
|
||||
response = input("Warning: file already exists. Do you want to overwrite? [y/N]: ")
|
||||
response = str(response).strip().lower()
|
||||
|
||||
if response not in ['y', 'yes']:
|
||||
print("Cancelled export operation")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Install tasks
|
||||
@task
|
||||
def plugins(c):
|
||||
@ -305,13 +321,7 @@ def export_records(c, filename='data.json', overwrite=False, include_permissions
|
||||
|
||||
print(f"Exporting database records to file '{filename}'")
|
||||
|
||||
if Path(filename).is_file() and overwrite is False:
|
||||
response = input("Warning: file already exists. Do you want to overwrite? [y/N]: ")
|
||||
response = str(response).strip().lower()
|
||||
|
||||
if response not in ['y', 'yes']:
|
||||
print("Cancelled export operation")
|
||||
sys.exit(1)
|
||||
check_file_existance(filename, overwrite)
|
||||
|
||||
tmpfile = f"{filename}.tmp"
|
||||
|
||||
@ -621,3 +631,13 @@ def coverage(c):
|
||||
|
||||
# Generate coverage report
|
||||
c.run('coverage html -i')
|
||||
|
||||
|
||||
@task(help={
|
||||
'filename': "Output filename (default = 'schema.yml')",
|
||||
'overwrite': "Overwrite existing files without asking first (default = off/False)",
|
||||
})
|
||||
def schema(c, filename='schema.yml', overwrite=False):
|
||||
"""Export current API schema."""
|
||||
check_file_existance(filename, overwrite)
|
||||
manage(c, f'spectacular --file {filename}')
|
||||
|
Reference in New Issue
Block a user