Пример #1
0
 def decorate_with_data(self, result):
     return openapi.Schema(
         type=openapi.TYPE_OBJECT,
         required=['data'],
         properties=utils.OrderedDict((
             ('data', result),
         ))
     )
Пример #2
0
 def generate_meta(self):
     return openapi.Schema(
         title='Meta of result with pagination count',
         type=openapi.TYPE_OBJECT,
         required=['count'],
         properties=utils.OrderedDict((
             ('count', openapi.Schema(
                 type=openapi.TYPE_INTEGER,
                 title='Number of results on page',
             )),
         ))
     )
Пример #3
0
 def generate_relationships(self, obj):
     relationships_properties = []
     for field in obj.fields.values():
         if isinstance(field, serializers.ResourceRelatedField):
             relationships_properties.append(
                 self.generate_relationship(field)
             )
     if relationships_properties:
         return openapi.Schema(
             title='Relationships of object',
             type=openapi.TYPE_OBJECT,
             properties=utils.OrderedDict(relationships_properties),
         )
Пример #4
0
 def formatted_model_result(self, result, obj):
     return openapi.Schema(
         type=openapi.TYPE_OBJECT,
         required=['properties'],
         properties=utils.OrderedDict((
             ('type', openapi.Schema(
                 type=openapi.TYPE_STRING,
                 enum=[serializers.get_resource_type_from_serializer(obj)],
                 title='Type of related object',
             )),
             ('attributes', result),
         ))
     )
Пример #5
0
    def get_paginated_response(self, paginator, response_schema):
        paged_schema = None
        if isinstance(paginator, pagination.LimitOffsetPagination):
            paged_schema = openapi.Schema(
                type=openapi.TYPE_OBJECT,
                properties=utils.OrderedDict((
                    ('links', self.generate_links()),
                    ('data', response_schema),
                    ('meta', self.generate_meta())
                )),
                required=['data']
            )

        return paged_schema
Пример #6
0
 def generate_relationship(self, field):
     field_schema = openapi.Schema(
         title='Relationship object',
         type=openapi.TYPE_OBJECT,
         properties=utils.OrderedDict((
             ('type', openapi.Schema(
                 type=openapi.TYPE_STRING,
                 title='Type of related object',
                 enum=[get_related_resource_type(field)]
             )),
             ('id', openapi.Schema(
                 type=openapi.TYPE_STRING,
                 title='ID of related object',
             ))
         ))
     )
     return field.field_name, self.decorate_with_data(field_schema)
Пример #7
0
 def generate_links(self):
     return openapi.Schema(
         title='Links',
         type=openapi.TYPE_OBJECT,
         required=['first', 'last'],
         properties=utils.OrderedDict((
             ('first', openapi.Schema(
                 type=openapi.TYPE_STRING, title='Link to first object',
                 read_only=True, format=openapi.FORMAT_URI
             )),
             ('last', openapi.Schema(
                 type=openapi.TYPE_STRING, title='Link to last object',
                 read_only=True, format=openapi.FORMAT_URI
             )),
             ('next', openapi.Schema(
                 type=openapi.TYPE_STRING, title='Link to next object',
                 read_only=True, format=openapi.FORMAT_URI
             )),
             ('prev', openapi.Schema(
                 type=openapi.TYPE_STRING, title='Link to prev object',
                 read_only=True, format=openapi.FORMAT_URI
             ))
         ))
     )