commonground-api-common 2.1.2__py3-none-any.whl → 2.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. commonground_api_common-2.1.2.data/scripts/patch_content_types → commonground_api_common-2.3.0.data/scripts/generate_schema +2 -4
  2. {commonground_api_common-2.1.2.dist-info → commonground_api_common-2.3.0.dist-info}/METADATA +12 -3
  3. {commonground_api_common-2.1.2.dist-info → commonground_api_common-2.3.0.dist-info}/RECORD +27 -36
  4. {commonground_api_common-2.1.2.dist-info → commonground_api_common-2.3.0.dist-info}/WHEEL +1 -1
  5. vng_api_common/__init__.py +1 -1
  6. vng_api_common/api/views.py +1 -0
  7. vng_api_common/apps.py +43 -26
  8. vng_api_common/audittrails/utils.py +44 -0
  9. vng_api_common/conf/api.py +33 -45
  10. vng_api_common/contrib/setup_configuration/models.py +32 -0
  11. vng_api_common/contrib/setup_configuration/steps.py +46 -0
  12. vng_api_common/extensions/file.py +26 -0
  13. vng_api_common/extensions/gegevensgroep.py +16 -0
  14. vng_api_common/extensions/geojson.py +270 -0
  15. vng_api_common/extensions/hyperlink.py +37 -0
  16. vng_api_common/extensions/polymorphic.py +68 -0
  17. vng_api_common/extensions/query.py +20 -0
  18. vng_api_common/filters.py +0 -1
  19. vng_api_common/generators.py +12 -113
  20. vng_api_common/notifications/api/views.py +3 -3
  21. vng_api_common/oas.py +6 -7
  22. vng_api_common/schema.py +414 -158
  23. vng_api_common/views.py +1 -1
  24. commonground_api_common-2.1.2.data/scripts/generate_schema +0 -39
  25. commonground_api_common-2.1.2.data/scripts/use_external_components +0 -16
  26. vng_api_common/inspectors/cache.py +0 -57
  27. vng_api_common/inspectors/fields.py +0 -126
  28. vng_api_common/inspectors/files.py +0 -121
  29. vng_api_common/inspectors/geojson.py +0 -360
  30. vng_api_common/inspectors/polymorphic.py +0 -72
  31. vng_api_common/inspectors/query.py +0 -91
  32. vng_api_common/inspectors/utils.py +0 -40
  33. vng_api_common/inspectors/view.py +0 -547
  34. vng_api_common/management/commands/generate_autorisaties.py +0 -43
  35. vng_api_common/management/commands/generate_notificaties.py +0 -40
  36. vng_api_common/management/commands/generate_swagger.py +0 -197
  37. vng_api_common/management/commands/patch_error_contenttypes.py +0 -61
  38. vng_api_common/management/commands/use_external_components.py +0 -94
  39. vng_api_common/templates/vng_api_common/api_schema_to_markdown_table.md +0 -16
  40. vng_api_common/templates/vng_api_common/autorisaties.md +0 -15
  41. vng_api_common/templates/vng_api_common/notificaties.md +0 -24
  42. {commonground_api_common-2.1.2.dist-info → commonground_api_common-2.3.0.dist-info}/top_level.txt +0 -0
  43. /vng_api_common/{inspectors → contrib}/__init__.py +0 -0
  44. /vng_api_common/{management → contrib/setup_configuration}/__init__.py +0 -0
  45. /vng_api_common/{management/commands → extensions}/__init__.py +0 -0
@@ -1,72 +0,0 @@
1
- """
2
- Introspect polymorphic resources
3
-
4
- Bulk of the code taken from https://github.com/axnsan12/drf-yasg/issues/100
5
- """
6
-
7
- from drf_yasg import openapi
8
- from drf_yasg.errors import SwaggerGenerationError
9
- from drf_yasg.inspectors.base import NotHandled
10
- from drf_yasg.inspectors.field import (
11
- CamelCaseJSONFilter,
12
- ReferencingSerializerInspector,
13
- )
14
-
15
- from ..polymorphism import PolymorphicSerializer
16
- from ..utils import underscore_to_camel
17
-
18
-
19
- class PolymorphicSerializerInspector(
20
- CamelCaseJSONFilter, ReferencingSerializerInspector
21
- ):
22
- def field_to_swagger_object(
23
- self, field, swagger_object_type, use_references, **kwargs
24
- ):
25
- SwaggerType, ChildSwaggerType = self._get_partial_types(
26
- field, swagger_object_type, use_references, **kwargs
27
- )
28
-
29
- if not isinstance(field, PolymorphicSerializer):
30
- return NotHandled
31
-
32
- if not getattr(field, "discriminator", None):
33
- raise SwaggerGenerationError(
34
- "'PolymorphicSerializer' derived serializers need to have 'discriminator' set"
35
- )
36
-
37
- base_schema_ref = super().field_to_swagger_object(
38
- field, swagger_object_type, use_references, **kwargs
39
- )
40
- if not isinstance(base_schema_ref, openapi.SchemaRef):
41
- raise SwaggerGenerationError(
42
- "discriminator inheritance requires model references"
43
- )
44
-
45
- base_schema = base_schema_ref.resolve(self.components) # type: openapi.Schema
46
- base_schema.discriminator = underscore_to_camel(
47
- field.discriminator.discriminator_field
48
- )
49
-
50
- for value, serializer in field.discriminator.mapping.items():
51
- if serializer is None:
52
- allof_derived = openapi.Schema(
53
- type=openapi.TYPE_OBJECT, all_of=[base_schema_ref]
54
- )
55
- else:
56
- derived_ref = self.probe_field_inspectors(
57
- serializer, openapi.Schema, use_references=True
58
- )
59
- if not isinstance(derived_ref, openapi.SchemaRef):
60
- raise SwaggerGenerationError(
61
- "discriminator inheritance requies model references"
62
- )
63
-
64
- allof_derived = openapi.Schema(
65
- type=openapi.TYPE_OBJECT, all_of=[base_schema_ref, derived_ref]
66
- )
67
- if not self.components.has(value, scope=openapi.SCHEMA_DEFINITIONS):
68
- self.components.set(
69
- value, allof_derived, scope=openapi.SCHEMA_DEFINITIONS
70
- )
71
-
72
- return base_schema_ref
@@ -1,91 +0,0 @@
1
- from django.db import models
2
- from django.utils.encoding import force_str
3
- from django.utils.translation import gettext as _
4
-
5
- from django_filters.filters import BaseCSVFilter, ChoiceFilter
6
- from drf_yasg import openapi
7
- from drf_yasg.inspectors.query import CoreAPICompatInspector
8
- from rest_framework.filters import OrderingFilter
9
-
10
- from ..filters import URLModelChoiceFilter
11
- from ..utils import underscore_to_camel
12
- from .utils import get_target_field
13
-
14
-
15
- class FilterInspector(CoreAPICompatInspector):
16
- """
17
- Filter inspector that specifies the format of URL-based fields and lists
18
- enum options.
19
- """
20
-
21
- def get_filter_parameters(self, filter_backend):
22
- fields = super().get_filter_parameters(filter_backend)
23
- if isinstance(filter_backend, OrderingFilter):
24
- return fields
25
-
26
- if fields:
27
- queryset = self.view.get_queryset()
28
- filter_class = filter_backend.get_filterset_class(self.view, queryset)
29
-
30
- for parameter in fields:
31
- filter_field = filter_class.base_filters[parameter.name]
32
- model_field = get_target_field(queryset.model, parameter.name)
33
- parameter._filter_field = filter_field
34
-
35
- help_text = filter_field.extra.get(
36
- "help_text",
37
- getattr(model_field, "help_text", "") if model_field else "",
38
- )
39
-
40
- if isinstance(filter_field, BaseCSVFilter):
41
- if "choices" in filter_field.extra:
42
- schema = openapi.Schema(
43
- type=openapi.TYPE_ARRAY,
44
- items=openapi.Schema(
45
- type=openapi.TYPE_STRING,
46
- enum=[
47
- choice[0]
48
- for choice in filter_field.extra["choices"]
49
- ],
50
- ),
51
- )
52
- else:
53
- schema = openapi.Schema(
54
- type=openapi.TYPE_ARRAY,
55
- items=openapi.Schema(type=openapi.TYPE_STRING),
56
- )
57
- parameter["type"] = openapi.TYPE_ARRAY
58
- parameter["schema"] = schema
59
- parameter["style"] = "form"
60
- parameter["explode"] = False
61
- elif isinstance(filter_field, URLModelChoiceFilter):
62
- description = _("URL to the related {resource}").format(
63
- resource=parameter.name
64
- )
65
- parameter.description = help_text or description
66
- parameter.format = openapi.FORMAT_URI
67
- elif isinstance(filter_field, ChoiceFilter):
68
- parameter.enum = [
69
- choice[0] for choice in filter_field.extra["choices"]
70
- ]
71
- elif model_field and isinstance(model_field, models.URLField):
72
- parameter.format = openapi.FORMAT_URI
73
-
74
- if not parameter.description and help_text:
75
- parameter.description = force_str(help_text)
76
-
77
- if "max_length" in filter_field.extra:
78
- parameter.max_length = filter_field.extra["max_length"]
79
- if "min_length" in filter_field.extra:
80
- parameter.min_length = filter_field.extra["min_length"]
81
-
82
- return fields
83
-
84
- def process_result(self, result, method_name, obj, **kwargs):
85
- """
86
- Convert snake-case to camelCase.
87
- """
88
- if result and type(result) is list:
89
- for parameter in result:
90
- parameter.name = underscore_to_camel(parameter.name)
91
- return result
@@ -1,40 +0,0 @@
1
- from typing import Optional, Type
2
-
3
- from django.db import models
4
-
5
- from rest_framework.utils.model_meta import get_field_info
6
-
7
-
8
- def get_target_field(model: Type[models.Model], field: str) -> Optional[models.Field]:
9
- """
10
- Retrieve the end-target that ``field`` points to.
11
-
12
- :param field: A string containing a lookup, potentially spanning relations. E.g.:
13
- foo__bar__lte.
14
- :return: A Django model field instance or `None`
15
- """
16
-
17
- start, *remaining = field.split("__")
18
- field_info = get_field_info(model)
19
-
20
- # simple, non relational field?
21
- if start in field_info.fields:
22
- return field_info.fields[start]
23
-
24
- # simple relational field?
25
- if start in field_info.forward_relations:
26
- relation_info = field_info.forward_relations[start]
27
- if not remaining:
28
- return relation_info.model_field
29
- else:
30
- return get_target_field(relation_info.related_model, "__".join(remaining))
31
-
32
- # check the reverse relations - note that the model name is used instead of model_name_set
33
- # in the queries -> we can't just test for containment in field_info.reverse_relations
34
- for relation_info in field_info.reverse_relations.values():
35
- # not sure about this - what if there are more relations with different related names?
36
- if relation_info.related_model._meta.model_name != start:
37
- continue
38
- return get_target_field(relation_info.related_model, "__".join(remaining))
39
-
40
- return None