diff --git a/docs/extract_schema.py b/docs/extract_schema.py index 1a781d76c51e..b6b70a9db1ff 100644 --- a/docs/extract_schema.py +++ b/docs/extract_schema.py @@ -44,7 +44,8 @@ def top_level_path(path: str) -> str: path = path.strip() - key = path.split('/')[1] + parts = path.split('/') + key = parts[1] if len(parts) > 1 else parts[0] if key in SPECIAL_PATHS: return key diff --git a/src/backend/InvenTree/InvenTree/api.py b/src/backend/InvenTree/InvenTree/api.py index 3771c411b5e1..f41ff67a86a2 100644 --- a/src/backend/InvenTree/InvenTree/api.py +++ b/src/backend/InvenTree/InvenTree/api.py @@ -30,7 +30,6 @@ from .mixins import ListAPI, RetrieveUpdateAPI from .status import check_system_health, is_worker_running from .version import inventreeApiText -from .views import AjaxView logger = logging.getLogger('inventree') @@ -196,8 +195,35 @@ def list(self, request, *args, **kwargs): return JsonResponse(inventreeApiText()) -class InfoView(AjaxView): - """Simple JSON endpoint for InvenTree information. +class InfoApiSerializer(serializers.Serializer): + """InvenTree server information - some information might be blanked if called without elevated credentials.""" + + server = serializers.CharField(read_only=True) + version = serializers.CharField(read_only=True) + instance = serializers.CharField(read_only=True) + apiVersion = serializers.IntegerField(read_only=True) # noqa: N815 + worker_running = serializers.BooleanField(read_only=True) + worker_count = serializers.IntegerField(read_only=True) + worker_pending_tasks = serializers.IntegerField(read_only=True) + plugins_enabled = serializers.BooleanField(read_only=True) + plugins_install_disabled = serializers.BooleanField(read_only=True) + active_plugins = serializers.JSONField(read_only=True) + email_configured = serializers.BooleanField(read_only=True) + debug_mode = serializers.BooleanField(read_only=True) + docker_mode = serializers.BooleanField(read_only=True) + default_locale = serializers.ChoiceField( + choices=settings.LOCALE_CODES, read_only=True + ) + system_health = serializers.BooleanField(read_only=True) + database = serializers.CharField(read_only=True) + platform = serializers.CharField(read_only=True) + installer = serializers.CharField(read_only=True) + target = serializers.CharField(read_only=True) + django_admin = serializers.CharField(read_only=True) + + +class InfoView(APIView): + """JSON endpoint for InvenTree server information. Use to confirm that the server is running, etc. """ @@ -208,6 +234,13 @@ def worker_pending_tasks(self): """Return the current number of outstanding background tasks.""" return OrmQ.objects.count() + @extend_schema( + responses={ + 200: OpenApiResponse( + response=InfoApiSerializer, description='InvenTree server information' + ) + } + ) def get(self, request, *args, **kwargs): """Serve current server information.""" is_staff = request.user.is_staff @@ -261,7 +294,7 @@ def check_auth_header(self, request): return False -class NotFoundView(AjaxView): +class NotFoundView(APIView): """Simple JSON view when accessing an invalid API view.""" permission_classes = [permissions.AllowAny] @@ -280,22 +313,27 @@ def options(self, request, *args, **kwargs): """Return 404.""" return self.not_found(request) + @extend_schema(exclude=True) def get(self, request, *args, **kwargs): """Return 404.""" return self.not_found(request) + @extend_schema(exclude=True) def post(self, request, *args, **kwargs): """Return 404.""" return self.not_found(request) + @extend_schema(exclude=True) def patch(self, request, *args, **kwargs): """Return 404.""" return self.not_found(request) + @extend_schema(exclude=True) def put(self, request, *args, **kwargs): """Return 404.""" return self.not_found(request) + @extend_schema(exclude=True) def delete(self, request, *args, **kwargs): """Return 404.""" return self.not_found(request) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index d54290fcdc81..e745c7cf66d4 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,13 +1,17 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 279 +INVENTREE_API_VERSION = 280 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v280 - 2024-11-10 : https://github.com/inventree/InvenTree/pull/8461 + - Makes schema for API information endpoint more informing + - Removes general not found endpoint + v279 - 2024-11-09 : https://github.com/inventree/InvenTree/pull/8458 - Adds "order_outstanding" and "part" filters to the BuildLine API endpoint - Adds "order_outstanding" filter to the SalesOrderLineItem API endpoint