コード例 #1
0
ファイル: openapi.py プロジェクト: mdellweg/drf-spectacular
 def get_description(self):
     """ override this for custom behaviour """
     action_or_method = getattr(
         self.view, getattr(self.view, 'action', self.method.lower()), None)
     view_doc = get_doc(self.view.__class__)
     action_doc = get_doc(action_or_method)
     return action_doc or view_doc
コード例 #2
0
ファイル: openapi.py プロジェクト: pca/web-backend
 def get_docstring(self):
     action_or_method = getattr(
         self.view, getattr(self.view, "action", self.method.lower()), None
     )
     view_doc = get_doc(self.view.__class__)
     action_doc = get_doc(action_or_method)
     return action_doc or view_doc
コード例 #3
0
ファイル: openapi.py プロジェクト: mdellweg/drf-spectacular
    def _map_basic_serializer(self, serializer, direction):
        serializer = force_instance(serializer)
        required = set()
        properties = {}

        for field in serializer.fields.values():
            if isinstance(field, serializers.HiddenField):
                continue
            if field.field_name in get_override(serializer, 'exclude_fields',
                                                []):
                continue

            schema = self._map_serializer_field(field, direction)
            # skip field if there is no schema for the direction
            if not schema:
                continue

            add_to_required = (
                field.required or
                (schema.get('readOnly')
                 and not spectacular_settings.COMPONENT_NO_READ_ONLY_REQUIRED))
            if add_to_required:
                required.add(field.field_name)

            self._map_field_validators(field, schema)

            properties[field.field_name] = safe_ref(schema)

        if spectacular_settings.COMPONENT_SPLIT_PATCH:
            if self.method == 'PATCH' and direction == 'request':
                required = []

        return build_object_type(
            properties=properties,
            required=required,
            description=get_doc(serializer.__class__),
        )