当前位置: 首页>>代码示例>>Python>>正文


Python coreapi.Field方法代码示例

本文整理汇总了Python中coreapi.Field方法的典型用法代码示例。如果您正苦于以下问题:Python coreapi.Field方法的具体用法?Python coreapi.Field怎么用?Python coreapi.Field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coreapi的用法示例。


在下文中一共展示了coreapi.Field方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_schema_fields

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_schema_fields(self, view):
        fields = self.get_default_schema_fields()

        for field_name in self.search_index_class.fields:
            field = self.search_index_class.fields[field_name]

            if field.faceted:
                fields.append(
                    coreapi.Field(
                        name=field_name,
                        location='query',
                        required=False,
                        schema=coreschema.String(description=field_name),
                    ))

        return fields 
开发者ID:openlegaldata,项目名称:oldp,代码行数:18,代码来源:filters.py

示例2: get_manual_fields

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_manual_fields(self, path, method):
        f, url, params, returns = self._method_meta[method]
        if params is None:
            return []
        field_schemas = T(params).__schema__.items
        path_fields = self.get_path_fields(path, method)
        path_field_names = set(x.name for x in path_fields)
        fields = []
        for name, item in field_schemas.items():
            if name in path_field_names or name in ['id', 'pk']:
                continue
            required = not item.params.get('optional', False)
            default = item.params.get('default')
            if not (default is None or default == ''):
                required = False
            if method in ['GET', 'DELETE']:
                location = 'query'
            else:
                location = 'form'
            field = coreapi.Field(
                name=name,
                required=required,
                location=location,
                schema=coreschema_from_validr(item)
            )
            fields.append(field)
        return fields 
开发者ID:anyant,项目名称:rssant,代码行数:29,代码来源:__init__.py

示例3: schema

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def schema(self):
        fields = [
            coreapi.Field(
                "auth_token",
                required=True,
                location="form",
                schema=coreschema.String(max_length=40),
            )]
        return schemas.ManualSchema(fields=fields) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:11,代码来源:v1.py

示例4: schema

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def schema(self):
        if self.request.method == 'GET':
            fields = [
                coreapi.Field(
                    "name",
                    required=False,
                    location="query",
                    schema=coreschema.String(max_length=30)
                ),
                coreapi.Field(
                    "name_contains",
                    required=False,
                    location="query",
                    schema=coreschema.String(max_length=30)
                )]
        elif self.request.method == 'POST':
            fields = [
                coreapi.Field(
                    "params",
                    required=True,
                    location="body",
                    schema=coreschema.Object()
                )]
        else:
            fields = [
                coreapi.Field(
                    "name",
                    required=True,
                    location="body",
                    schema=coreschema.String(max_length=30)
                )]
        return schemas.ManualSchema(fields=fields) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:34,代码来源:v1.py

示例5: get_default_schema_fields

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_default_schema_fields(self):
        return [
            # Search query field is required
            coreapi.Field(
                name='text',
                location='query',
                required=True,
                schema=coreschema.String(description='Search query on text content (Lucence syntax support).'),
            )
        ] 
开发者ID:openlegaldata,项目名称:oldp,代码行数:12,代码来源:api_views.py

示例6: get_default_schema_fields

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_default_schema_fields(self):
        return [
            # Search query field is required
            coreapi.Field(
                name='text',
                location='query',
                required=True,
                schema=coreschema.String(description='Search query on text content (Lucence syntax support).'),
                description='',
                example=[_('search_example_query1'),  _('search_example_query2'), _('search_example_query3')]
            )
        ] 
开发者ID:openlegaldata,项目名称:oldp,代码行数:14,代码来源:api_views.py

示例7: get_path_fields

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_path_fields(self, path, method, view):
        """
        Return a list of `coreapi.Field` instances corresponding to any
        templated path variables.
        """
        model = getattr(getattr(view, 'queryset', None), 'model', None)
        fields = []

        for variable in uritemplate.variables(path):

            if variable == 'version':
                continue

            title = ''
            description = ''
            schema_cls = coreschema.String
            kwargs = {}
            if model is not None:
                # Attempt to infer a field description if possible.
                try:
                    model_field = model._meta.get_field(variable)
                except:
                    model_field = None

                if model_field is not None and model_field.verbose_name:
                    title = force_text(model_field.verbose_name)

                if model_field is not None and model_field.help_text:
                    description = force_text(model_field.help_text)
                elif model_field is not None and model_field.primary_key:
                    description = get_pk_description(model, model_field)

                if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable:
                    kwargs['pattern'] = view.lookup_value_regex
                elif isinstance(model_field, models.AutoField):
                    schema_cls = coreschema.Integer

            field = Field(
                name=variable,
                location='path',
                required=True,
                schema=schema_cls(title=title, description=description, **kwargs)
            )
            fields.append(field)

        return fields 
开发者ID:limdauto,项目名称:drf_openapi,代码行数:48,代码来源:entities.py

示例8: get_serializer_fields

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_serializer_fields(self, path, method, view, version=None, method_func=None):
        """
        Return a list of `coreapi.Field` instances corresponding to any
        request body input, as determined by the serializer class.
        """
        if method in ('PUT', 'PATCH', 'POST'):
            location = 'form'
        else:
            location = 'query'

        serializer_class = self.get_serializer_class(view, method_func)
        if not serializer_class:
            return []

        serializer = serializer_class()
        if isinstance(serializer, serializers.ListSerializer):
            return [
                Field(
                    name='data',
                    location=location,
                    required=True,
                    schema=coreschema.Array()
                )
            ]

        if not isinstance(serializer, serializers.Serializer):
            return []

        fields = []
        for field in serializer.fields.values():
            if field.read_only or isinstance(field, serializers.HiddenField):
                continue

            required = field.required and method != 'PATCH'
            # if the attribute ('help_text') of this field is a lazy translation object, force it to generate a string
            description = str(field.help_text) if isinstance(field.help_text, Promise) else field.help_text
            fallback_schema = self.fallback_schema_from_field(field)
            field = Field(
                name=field.field_name,
                location=location,
                required=required,
                schema=fallback_schema if fallback_schema else field_to_schema(field),
                description=description,
            )
            fields.append(field)

        return fields 
开发者ID:limdauto,项目名称:drf_openapi,代码行数:49,代码来源:entities.py

示例9: get_response_object

# 需要导入模块: import coreapi [as 别名]
# 或者: from coreapi import Field [as 别名]
def get_response_object(self, response_serializer_class, description):

        fields = []
        serializer = response_serializer_class()
        nested_obj = {}

        for field in serializer.fields.values():
            # If field is a serializer, attempt to get its schema.
            if isinstance(field, serializers.Serializer):
                subfield_schema = self.get_response_object(field.__class__, None)[0].get('schema')

                # If the schema exists, use it as the nested_obj
                if subfield_schema is not None:
                    nested_obj[field.field_name] = subfield_schema
                    nested_obj[field.field_name]['description'] = field.help_text
                    continue

            # Otherwise, carry-on and use the field's schema.
            fallback_schema = self.fallback_schema_from_field(field)
            fields.append(Field(
                name=field.field_name,
                location='form',
                required=field.required,
                schema=fallback_schema if fallback_schema else field_to_schema(field),
            ))

        res = _get_parameters(Link(fields=fields), None)

        if not res:
            if nested_obj:
                return {
                    'description': description,
                    'schema': {
                        'type': 'object',
                        'properties': nested_obj
                    }
                }, {}
            else:
                return {}, {}

        schema = res[0]['schema']
        schema['properties'].update(nested_obj)
        response_schema = {
            'description': description,
            'schema': schema
        }

        error_status_codes = {}

        response_meta = getattr(response_serializer_class, 'Meta', None)

        for status_code, description in getattr(response_meta, 'error_status_codes', {}).items():
            error_status_codes[status_code] = {'description': description}

        return response_schema, error_status_codes 
开发者ID:limdauto,项目名称:drf_openapi,代码行数:57,代码来源:entities.py


注:本文中的coreapi.Field方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。