Skip to content

Commit 76fa169

Browse files
committed
Deployed ddfb967 with MkDocs version: 1.0.4
1 parent 9d6bc0f commit 76fa169

File tree

20 files changed

+350
-136
lines changed

20 files changed

+350
-136
lines changed

404.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
66
<meta charset="utf-8">
77
<title>Django REST framework</title>
8-
<link href="//img/favicon.ico" rel="icon" type="image/x-icon">
8+
<link href="/img/favicon.ico" rel="icon" type="image/x-icon">
99
<link rel="canonical" href="/." />
1010
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1111
<meta name="description" content="Django, API, REST">
1212
<meta name="author" content="Tom Christie">
1313

1414
<!-- Le styles -->
15-
<link href="//css/prettify.css" rel="stylesheet">
16-
<link href="//css/bootstrap.css" rel="stylesheet">
17-
<link href="//css/bootstrap-responsive.css" rel="stylesheet">
18-
<link href="//css/default.css" rel="stylesheet">
15+
<link href="/css/prettify.css" rel="stylesheet">
16+
<link href="/css/bootstrap.css" rel="stylesheet">
17+
<link href="/css/bootstrap-responsive.css" rel="stylesheet">
18+
<link href="/css/default.css" rel="stylesheet">
1919

2020
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
2121
<!--[if lt IE 9]>
@@ -406,7 +406,7 @@ <h3 id="myModalLabel">Documentation search</h3>
406406

407407

408408
<div class="promo">
409-
<hr/>
409+
410410
<div id="sidebarInclude">
411411
</div>
412412
</ul>
@@ -419,7 +419,7 @@ <h3 id="myModalLabel">Documentation search</h3>
419419

420420
<h1 id="404-page-not-found" style="text-align: center">404</h1>
421421
<p style="text-align: center"><strong>Page not found</strong></p>
422-
<p style="text-align: center">Try the <a href="https://www.django-rest-framework.org/">homepage</a>, or <a href="#searchModal" data-toggle="modal">search the documentation</a>.</p>
422+
<p style="text-align: center">Try the <a href="/">homepage</a>, or <a href="#mkdocs_search_modal" data-toggle="modal">search the documentation</a>.</p>
423423

424424

425425

@@ -439,10 +439,10 @@ <h1 id="404-page-not-found" style="text-align: center">404</h1>
439439
================================================== -->
440440
<!-- Placed at the end of the document so the pages load faster -->
441441
<script async src="https://fund.django-rest-framework.org/sidebar_include.js"></script>
442-
<script src="//js/jquery-1.8.1-min.js"></script>
443-
<script src="//js/prettify-1.0.js"></script>
444-
<script src="//js/bootstrap-2.1.1-min.js"></script>
445-
<script src="//js/theme.js"></script>
442+
<script src="/js/jquery-1.8.1-min.js"></script>
443+
<script src="/js/prettify-1.0.js"></script>
444+
<script src="/js/bootstrap-2.1.1-min.js"></script>
445+
<script src="/js/theme.js"></script>
446446

447447
<script>var base_url = '/';</script>
448448

api-guide/fields/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ <h1 id="custom-fields"><a class="toclink" href="#custom-fields">Custom fields</a
10411041
<p>If you want to create a custom field, you'll need to subclass <code>Field</code> and then override either one or both of the <code>.to_representation()</code> and <code>.to_internal_value()</code> methods. These two methods are used to convert between the initial datatype, and a primitive, serializable datatype. Primitive datatypes will typically be any of a number, string, boolean, <code>date</code>/<code>time</code>/<code>datetime</code> or <code>None</code>. They may also be any list or dictionary like object that only contains other primitive objects. Other types might be supported, depending on the renderer that you are using.</p>
10421042
<p>The <code>.to_representation()</code> method is called to convert the initial datatype into a primitive, serializable datatype.</p>
10431043
<p>The <code>to_internal_value()</code> method is called to restore a primitive datatype into its internal python representation. This method should raise a <code>serializers.ValidationError</code> if the data is invalid.</p>
1044-
<p>Note that the <code>WritableField</code> class that was present in version 2.x no longer exists. You should subclass <code>Field</code> and override <code>to_internal_value()</code> if the field supports data input.</p>
10451044
<h2 id="examples"><a class="toclink" href="#examples">Examples</a></h2>
10461045
<h3 id="a-basic-custom-field"><a class="toclink" href="#a-basic-custom-field">A Basic Custom Field</a></h3>
10471046
<p>Let's look at an example of serializing a class that represents an RGB color value:</p>

api-guide/filtering/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ <h2 id="searchfilter"><a class="toclink" href="#searchfilter">SearchFilter</a></
679679
<ul>
680680
<li>'^' Starts-with search.</li>
681681
<li>'=' Exact matches.</li>
682-
<li>'@' Full-text search. (Currently only supported Django's MySQL backend.)</li>
682+
<li>'@' Full-text search. (Currently only supported Django's <a href="https://docs.djangoproject.com/en/dev/ref/contrib/postgres/search/">PostgreSQL backend</a>.)</li>
683683
<li>'$' Regex search.</li>
684684
</ul>
685685
<p>For example:</p>

api-guide/generic-views/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ <h4 id="get_serializer_classself"><a class="toclink" href="#get_serializer_class
678678
raise ValidationError('You have already signed up')
679679
serializer.save(user=self.request.user)
680680
</code></pre>
681-
<p><strong>Note</strong>: These methods replace the old-style version 2.x <code>pre_save</code>, <code>post_save</code>, <code>pre_delete</code> and <code>post_delete</code> methods, which are no longer available.</p>
682681
<p><strong>Other methods</strong>:</p>
683682
<p>You won't typically need to override the following methods, although you might need to call into them if you're writing custom views using <code>GenericAPIView</code>.</p>
684683
<ul>

api-guide/schemas/index.html

Lines changed: 187 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,16 @@ <h1 id="schema"><a class="toclink" href="#schema">Schema</a></h1>
449449
<p>Django REST Framework provides support for automatic generation of
450450
<a href="https://github.com/OAI/OpenAPI-Specification">OpenAPI</a> schemas.</p>
451451
<h2 id="generating-an-openapi-schema"><a class="toclink" href="#generating-an-openapi-schema">Generating an OpenAPI Schema</a></h2>
452-
<h3 id="install-pyyaml"><a class="toclink" href="#install-pyyaml">Install <code>pyyaml</code></a></h3>
453-
<p>You'll need to install <code>pyyaml</code>, so that you can render your generated schema
454-
into the commonly used YAML-based OpenAPI format.</p>
455-
<pre><code>pip install pyyaml
452+
<h3 id="install-dependencies"><a class="toclink" href="#install-dependencies">Install dependencies</a></h3>
453+
<pre><code>pip install pyyaml uritemplate
456454
</code></pre>
455+
<ul>
456+
<li><code>pyyaml</code> is used to generate schema into YAML-based OpenAPI format.</li>
457+
<li><code>uritemplate</code> is used internally to get parameters in path.</li>
458+
</ul>
457459
<h3 id="generating-a-static-schema-with-the-generateschema-management-command"><a class="toclink" href="#generating-a-static-schema-with-the-generateschema-management-command">Generating a static schema with the <code>generateschema</code> management command</a></h3>
458460
<p>If your schema is static, you can use the <code>generateschema</code> management command:</p>
459-
<pre><code class="bash">./manage.py generateschema &gt; openapi-schema.yml
461+
<pre><code class="bash">./manage.py generateschema --file openapi-schema.yml
460462
</code></pre>
461463

462464
<p>Once you've generated a schema in this way you can annotate it with any
@@ -542,7 +544,7 @@ <h2 id="customizing-schema-generation"><a class="toclink" href="#customizing-sch
542544
<p>You may customize schema generation at the level of the schema as a whole, or
543545
on a per-view basis.</p>
544546
<h3 id="schema-level-customization"><a class="toclink" href="#schema-level-customization">Schema Level Customization</a></h3>
545-
<p>In order to customize the top-level schema sublass
547+
<p>In order to customize the top-level schema subclass
546548
<code>rest_framework.schemas.openapi.SchemaGenerator</code> and provide it as an argument
547549
to the <code>generateschema</code> command or <code>get_schema_view()</code> helper function.</p>
548550
<h4 id="schemagenerator"><a class="toclink" href="#schemagenerator">SchemaGenerator</a></h4>
@@ -616,6 +618,185 @@ <h3 id="per-view-customization"><a class="toclink" href="#per-view-customization
616618
</code></pre>
617619
<p>If you wish to provide a base <code>AutoSchema</code> subclass to be used throughout your
618620
project you may adjust <code>settings.DEFAULT_SCHEMA_CLASS</code> appropriately.</p>
621+
<h3 id="grouping-operations-with-tags"><a class="toclink" href="#grouping-operations-with-tags">Grouping Operations With Tags</a></h3>
622+
<p>Tags can be used to group logical operations. Each tag name in the list MUST be unique. </p>
623+
<hr />
624+
<h4 id="django-rest-framework-generates-tags-automatically-with-the-following-logic"><a class="toclink" href="#django-rest-framework-generates-tags-automatically-with-the-following-logic">Django REST Framework generates tags automatically with the following logic:</a></h4>
625+
<p>Tag name will be first element from the path. Also, any <code>_</code> in path name will be replaced by a <code>-</code>.
626+
Consider below examples.</p>
627+
<p>Example 1: Consider a user management system. The following table will illustrate the tag generation logic.
628+
Here first element from the paths is: <code>users</code>. Hence tag wil be <code>users</code></p>
629+
<table>
630+
<thead>
631+
<tr>
632+
<th>Http Method</th>
633+
<th>Path</th>
634+
<th>Tags</th>
635+
</tr>
636+
</thead>
637+
<tbody>
638+
<tr>
639+
<td>PUT, PATCH, GET(Retrieve), DELETE</td>
640+
<td>/users/{id}/</td>
641+
<td>['users']</td>
642+
</tr>
643+
<tr>
644+
<td>POST, GET(List)</td>
645+
<td>/users/</td>
646+
<td>['users']</td>
647+
</tr>
648+
</tbody>
649+
</table>
650+
<p>Example 2: Consider a restaurant management system. The System has restaurants. Each restaurant has branches.
651+
Consider REST APIs to deal with a branch of a particular restaurant.
652+
Here first element from the paths is: <code>restaurants</code>. Hence tag wil be <code>restaurants</code>.</p>
653+
<table>
654+
<thead>
655+
<tr>
656+
<th>Http Method</th>
657+
<th>Path</th>
658+
<th>Tags</th>
659+
</tr>
660+
</thead>
661+
<tbody>
662+
<tr>
663+
<td>PUT, PATCH, GET(Retrieve), DELETE:</td>
664+
<td>/restaurants/{restaurant_id}/branches/{branch_id}</td>
665+
<td>['restaurants']</td>
666+
</tr>
667+
<tr>
668+
<td>POST, GET(List):</td>
669+
<td>/restaurants/{restaurant_id}/branches/</td>
670+
<td>['restaurants']</td>
671+
</tr>
672+
</tbody>
673+
</table>
674+
<p>Example 3: Consider Order items for an e commerce company.</p>
675+
<table>
676+
<thead>
677+
<tr>
678+
<th>Http Method</th>
679+
<th>Path</th>
680+
<th>Tags</th>
681+
</tr>
682+
</thead>
683+
<tbody>
684+
<tr>
685+
<td>PUT, PATCH, GET(Retrieve), DELETE</td>
686+
<td>/order_items/{id}/</td>
687+
<td>['order-items']</td>
688+
</tr>
689+
<tr>
690+
<td>POST, GET(List)</td>
691+
<td>/order_items/</td>
692+
<td>['order-items']</td>
693+
</tr>
694+
</tbody>
695+
</table>
696+
<hr />
697+
<h4 id="overriding-auto-generated-tags"><a class="toclink" href="#overriding-auto-generated-tags">Overriding auto generated tags:</a></h4>
698+
<p>You can override auto-generated tags by passing <code>tags</code> argument to the constructor of <code>AutoSchema</code>. <code>tags</code> argument must be a list or tuple of string.</p>
699+
<pre><code class="python">from rest_framework.schemas.openapi import AutoSchema
700+
from rest_framework.views import APIView
701+
702+
class MyView(APIView):
703+
schema = AutoSchema(tags=['tag1', 'tag2'])
704+
...
705+
</code></pre>
706+
707+
<p>If you need more customization, you can override the <code>get_tags</code> method of <code>AutoSchema</code> class. Consider the following example:</p>
708+
<pre><code class="python">from rest_framework.schemas.openapi import AutoSchema
709+
from rest_framework.views import APIView
710+
711+
class MySchema(AutoSchema):
712+
...
713+
def get_tags(self, path, method):
714+
if method == 'POST':
715+
tags = ['tag1', 'tag2']
716+
elif method == 'GET':
717+
tags = ['tag2', 'tag3']
718+
elif path == '/example/path/':
719+
tags = ['tag3', 'tag4']
720+
else:
721+
tags = ['tag5', 'tag6', 'tag7']
722+
723+
return tags
724+
725+
class MyView(APIView):
726+
schema = MySchema()
727+
...
728+
</code></pre>
729+
730+
<h3 id="operationid"><a class="toclink" href="#operationid">OperationId</a></h3>
731+
<p>The schema generator generates an <a href="openapi-operationid">operationid</a> for each operation. This <code>operationId</code> is deduced from the model name, serializer name or view name. The operationId may looks like "listItems", "retrieveItem", "updateItem", etc..
732+
The <code>operationId</code> is camelCase by convention.</p>
733+
<p>If you have several views with the same model, the generator may generate duplicate operationId.
734+
In order to work around this, you can override the second part of the operationId: operation name.</p>
735+
<pre><code class="python">from rest_framework.schemas.openapi import AutoSchema
736+
737+
class ExampleView(APIView):
738+
&quot;&quot;&quot;APIView subclass with custom schema introspection.&quot;&quot;&quot;
739+
schema = AutoSchema(operation_id_base=&quot;Custom&quot;)
740+
</code></pre>
741+
742+
<p>The previous example will generate the following operationId: "listCustoms", "retrieveCustom", "updateCustom", "partialUpdateCustom", "destroyCustom".
743+
You need to provide the singular form of he operation name. For the list operation, a "s" will be appended at the end of the operation.</p>
744+
<p>If you need more configuration over the <code>operationId</code> field, you can override the <code>get_operation_id_base</code> and <code>get_operation_id</code> methods from the <code>AutoSchema</code> class:</p>
745+
<pre><code class="python">class CustomSchema(AutoSchema):
746+
def get_operation_id_base(self, path, method, action):
747+
pass
748+
749+
def get_operation_id(self, path, method):
750+
pass
751+
752+
class MyView(APIView):
753+
schema = AutoSchema(component_name=&quot;Ulysses&quot;)
754+
</code></pre>
755+
756+
<h3 id="components"><a class="toclink" href="#components">Components</a></h3>
757+
<p>Since DRF 3.12, Schema uses the <a href="openapi-components">OpenAPI Components</a>. This method defines components in the schema and <a href="openapi-reference">references them</a> inside request and response objects. By default, the component's name is deduced from the Serializer's name.</p>
758+
<p>Using OpenAPI's components provides the following advantages:
759+
* The schema is more readable and lightweight.
760+
* If you use the schema to generate an SDK (using <a href="openapi-generator">openapi-generator</a> or <a href="swagger-codegen">swagger-codegen</a>). The generator can name your SDK's models.</p>
761+
<h3 id="handling-components-schema-errors"><a class="toclink" href="#handling-components-schema-errors">Handling component's schema errors</a></h3>
762+
<p>You may get the following error while generating the schema:</p>
763+
<pre><code>&quot;Serializer&quot; is an invalid class name for schema generation.
764+
Serializer's class name should be unique and explicit. e.g. &quot;ItemSerializer&quot;.
765+
</code></pre>
766+
767+
<p>This error occurs when the Serializer name is "Serializer". You should choose a component's name unique across your schema and different than "Serializer".</p>
768+
<p>You may also get the following warning:</p>
769+
<pre><code>Schema component &quot;ComponentName&quot; has been overriden with a different value.
770+
</code></pre>
771+
772+
<p>This warning occurs when different components have the same name in one schema. Your component name should be unique across your project. This is likely an error that may lead to an invalid schema.</p>
773+
<p>You have two ways to solve the previous issues:
774+
* You can rename your serializer with a unique name and another name than "Serializer".
775+
* You can set the <code>component_name</code> kwarg parameter of the AutoSchema constructor (see below).
776+
* You can override the <code>get_component_name</code> method of the AutoSchema class (see below).</p>
777+
<h4 id="set-a-custom-components-name-for-your-view"><a class="toclink" href="#set-a-custom-components-name-for-your-view">Set a custom component's name for your view</a></h4>
778+
<p>To override the component's name in your view, you can use the <code>component_name</code> parameter of the AutoSchema constructor:</p>
779+
<pre><code class="python">from rest_framework.schemas.openapi import AutoSchema
780+
781+
class MyView(APIView):
782+
schema = AutoSchema(component_name=&quot;Ulysses&quot;)
783+
</code></pre>
784+
785+
<h4 id="override-the-default-implementation"><a class="toclink" href="#override-the-default-implementation">Override the default implementation</a></h4>
786+
<p>If you want to have more control and customization about how the schema's components are generated, you can override the <code>get_component_name</code> and <code>get_components</code> method from the AutoSchema class.</p>
787+
<pre><code class="python">from rest_framework.schemas.openapi import AutoSchema
788+
789+
class CustomSchema(AutoSchema):
790+
def get_components(self, path, method):
791+
# Implement your custom implementation
792+
793+
def get_component_name(self, serializer):
794+
# Implement your custom implementation
795+
796+
class CustomView(APIView):
797+
&quot;&quot;&quot;APIView subclass with custom schema introspection.&quot;&quot;&quot;
798+
schema = CustomSchema()
799+
</code></pre>
619800

620801

621802
</div> <!--/span-->

api-guide/serializers/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ <h4 id="writing-update-methods-for-nested-representations"><a class="toclink" hr
906906
<pre><code> def update(self, instance, validated_data):
907907
profile_data = validated_data.pop('profile')
908908
# Unless the application properly enforces that this field is
909-
# always set, the follow could raise a `DoesNotExist`, which
909+
# always set, the following could raise a `DoesNotExist`, which
910910
# would need to be handled.
911911
profile = instance.profile
912912

@@ -949,8 +949,8 @@ <h4 id="handling-saving-related-instances-in-model-manager-classes"><a class="to
949949
<pre><code>def create(self, validated_data):
950950
return User.objects.create(
951951
username=validated_data['username'],
952-
email=validated_data['email']
953-
is_premium_member=validated_data['profile']['is_premium_member']
952+
email=validated_data['email'],
953+
is_premium_member=validated_data['profile']['is_premium_member'],
954954
has_support_contract=validated_data['profile']['has_support_contract']
955955
)
956956
</code></pre>

0 commit comments

Comments
 (0)