Skip to content

Commit 8f39554

Browse files
committed
Adjust API Reference docs
1 parent 03ec9fe commit 8f39554

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

docs/api-guide/schemas.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ to the Open API ("Swagger") format:
372372

373373
## SchemaGenerator
374374

375-
A class that deals with introspecting your API views, which can be used to
376-
generate a schema.
375+
A class that walks a list of routed URL patterns, requests the schema for each view,
376+
and collates the resulting CoreAPI Document.
377377

378378
Typically you'll instantiate `SchemaGenerator` with a single argument, like so:
379379

@@ -406,36 +406,60 @@ Return a nested dictionary containing all the links that should be included in t
406406
This is a good point to override if you want to modify the resulting structure of the generated schema,
407407
as you can build a new dictionary with a different layout.
408408

409-
### get_link(self, path, method, view)
409+
410+
## APIViewSchemaDescriptor
411+
412+
A class that deals with introspection of individual views for schema generation.
413+
414+
`APIViewSchemaDescriptor` is attached to `APIView` via the `schema` attribute.
415+
416+
Typically you will subclass `APIViewSchemaDescriptor` to customise schema generation
417+
and then set your subclass on your view.
418+
419+
420+
class CustomViewSchema(APIViewSchemaDescriptor):
421+
"""
422+
Overrides `get_link()` to provide Custom Behavior X
423+
"""
424+
425+
def get_link(self, path, method, base_url):
426+
link = super().get_link(path, method, base_url)
427+
# Do something to customize link here...
428+
return link
429+
430+
class MyView(APIView):
431+
schema = CustomViewSchema()
432+
433+
### get_link(self, path, method, base_url)
410434

411435
Returns a `coreapi.Link` instance corresponding to the given view.
412436

413437
You can override this if you need to provide custom behaviors for particular views.
414438

415-
### get_description(self, path, method, view)
439+
### get_description(self, path, method)
416440

417441
Returns a string to use as the link description. By default this is based on the
418442
view docstring as described in the "Schemas as Documentation" section above.
419443

420-
### get_encoding(self, path, method, view)
444+
### get_encoding(self, path, method)
421445

422446
Returns a string to indicate the encoding for any request body, when interacting
423447
with the given view. Eg. `'application/json'`. May return a blank string for views
424448
that do not expect a request body.
425449

426-
### get_path_fields(self, path, method, view):
450+
### get_path_fields(self, path, method):
427451

428452
Return a list of `coreapi.Link()` instances. One for each path parameter in the URL.
429453

430-
### get_serializer_fields(self, path, method, view)
454+
### get_serializer_fields(self, path, method)
431455

432456
Return a list of `coreapi.Link()` instances. One for each field in the serializer class used by the view.
433457

434-
### get_pagination_fields(self, path, method, view
458+
### get_pagination_fields(self, path, method)
435459

436460
Return a list of `coreapi.Link()` instances, as returned by the `get_schema_fields()` method on any pagination class used by the view.
437461

438-
### get_filter_fields(self, path, method, view)
462+
### get_filter_fields(self, path, method)
439463

440464
Return a list of `coreapi.Link()` instances, as returned by the `get_schema_fields()` method of any filter classes used by the view.
441465

0 commit comments

Comments
 (0)