Coverage for app/venv/lib/python3.14/site-packages/weblate/api/generators.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5from __future__ import annotations 

6 

7from drf_spectacular.generators import SchemaGenerator 

8from drf_standardized_errors.openapi import AutoSchema 

9 

10 

11class WeblateSchemaGenerator(SchemaGenerator): 

12 def _should_include_path(self, path: str) -> bool: 

13 return ( 

14 # Our API endpoints, exclude third-party one such 

15 # as django_otp_webauthn 

16 path.startswith(("/api/", "/hooks/")) 

17 and 

18 # Exclude legacy URL for webhook 

19 path != "/hooks/{service}" 

20 ) 

21 

22 def _get_paths_and_endpoints(self): 

23 paths = super()._get_paths_and_endpoints() 

24 return [ 

25 (path, path_regex, method, view) 

26 for path, path_regex, method, view in paths 

27 if self._should_include_path(path) 

28 ] 

29 

30 

31class WeblateAutoSchema(AutoSchema): 

32 def get_tags(self) -> list[str]: 

33 """Override this for custom behaviour.""" 

34 tokenized_path = self._tokenize_path() 

35 # use first non-parameter path part as tag 

36 if tokenized_path[0] == "api": 

37 return tokenized_path[1:2] 

38 return tokenized_path[:1] 

39 

40 def get_operation_id(self) -> str: 

41 result = super().get_operation_id() 

42 if result == "hooks_create": 

43 return "hooks_incoming" 

44 return result