Example #1
0
 def setUp(self):
     self.field = coreapi.Field(name='email',
                                required=True,
                                location='query',
                                description='A valid email address.')
     self.swagger = _get_parameters(coreapi.Link(fields=[self.field]),
                                    encoding='')
Example #2
0
 def setUp(self):
     self.field = coreapi.Field(
         name='page',
         required=True,
         location='query',
         schema=coreschema.Integer(description='A page number.'))
     self.swagger = _get_parameters(coreapi.Link(fields=[self.field]),
                                    encoding='')
 def setUp(self):
     self.field = coreapi.Field(
         name='email',
         required=True,
         location='query',
         schema=coreschema.String(description='A valid email address.')
     )
     self.swagger = _get_parameters(coreapi.Link(fields=[self.field]), encoding='')
Example #4
0
 def setUp(self):
     self.field = coreapi.Field(name='published_before',
                                required=True,
                                location='query',
                                schema=coreschema.String(
                                    description='Filter by published date.',
                                    format='date'))
     self.swagger = _get_parameters(coreapi.Link(fields=[self.field]),
                                    encoding='')
Example #5
0
    def get_response_object(self, response_serializer_class, description):

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

        for field in serializer.fields.values():
            if isinstance(field, serializers.Serializer):
                nested_obj[field.field_name] = self.get_response_object(
                    field.__class__, None)[0]['schema']
                nested_obj[field.field_name]['description'] = field.help_text
                continue

            fields.append(
                Field(name=field.field_name,
                      location='form',
                      required=field.required,
                      schema=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
Example #6
0
def _get_operation(operation_id: str, link: OpenApiLink, tags: List) -> Dict:
    encoding = get_encoding(link)
    description = link.description.strip()
    # summary = description.splitlines()[0] if description else None
    summary = link.url

    operation = {
        'operationId': operation_id,
        'responses': _get_responses(link),
        'parameters': _get_parameters(link, encoding)
    }

    if description:
        operation['description'] = description
    if summary:
        operation['summary'] = summary
    if encoding:
        operation['consumes'] = [encoding]
    if tags:
        operation['tags'] = tags
    return operation