コード例 #1
0
ファイル: field.py プロジェクト: sKotenok/drf-yasg-json-api
    def process_result(self, result, method_name, obj, **kwargs):
        if isinstance(result, openapi.Schema.OR_REF) and is_json_api(
                self.view):
            schema = openapi.resolve_ref(result, self.components)
            self.format_schema(schema)

        return result
コード例 #2
0
ファイル: field.py プロジェクト: sKotenok/drf-yasg-json-api
    def field_to_swagger_object(self, field, swagger_object_type, **kwargs):
        if not isinstance(field, serializers.IntegerField) or not is_json_api(
                self.view):
            return inspectors.NotHandled

        stringify_id = False
        integer_format = None

        parent_serializer = get_parent_serializer(field)
        serializer_meta = getattr(parent_serializer, 'Meta', None)
        model = getattr(serializer_meta, 'model', None)
        if model is not None:
            field_name = getattr(field, 'source', None) or field.field_name
            model_field = get_model_field(model, field_name)
            # Check for primary key only if sure it is pure Field (not FieldCacheMixin or anything)
            if (model_field is not None
                    and isinstance(model_field,
                                   (models.IntegerField, models.AutoField))
                    and model_field.primary_key):
                stringify_id = True
                integer_format = self.get_format(model_field)

        elif field.field_name == 'id' and isinstance(field,
                                                     serializers.IntegerField):
            stringify_id = True

        if not stringify_id:
            return inspectors.NotHandled

        SwaggerType, ChildSwaggerType = self._get_partial_types(
            field, swagger_object_type, **kwargs)
        return SwaggerType(type=openapi.TYPE_STRING, format=integer_format)
コード例 #3
0
ファイル: field.py プロジェクト: sKotenok/drf-yasg-json-api
    def field_to_swagger_object(self, field, swagger_object_type, **kwargs):
        if not isinstance(
                field, serializers.PrimaryKeyRelatedField) or not is_json_api(
                    self.view):
            return inspectors.NotHandled

        if is_many_related_field(field):
            return inspectors.NotHandled

        related_model = get_field_related_model(field)
        if related_model:
            related_model_pk_field = get_model_field(related_model, 'pk')
            if isinstance(related_model_pk_field,
                          (models.IntegerField, models.AutoField)):
                SwaggerType, ChildSwaggerType = self._get_partial_types(
                    field, swagger_object_type, **kwargs)
                return SwaggerType(
                    type=openapi.TYPE_STRING,
                    format=self.get_format(related_model_pk_field))

        return inspectors.NotHandled
コード例 #4
0
ファイル: field.py プロジェクト: sKotenok/drf-yasg-json-api
    def field_to_swagger_object(self, field, swagger_object_type, **kwargs):
        if is_many_related_field(field) and is_json_api(self.view):
            return self.probe_field_inspectors(field.child_relation,
                                               swagger_object_type, **kwargs)

        return inspectors.NotHandled