@@ -372,8 +372,8 @@ to the Open API ("Swagger") format:
372
372
373
373
## SchemaGenerator
374
374
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 .
377
377
378
378
Typically you'll instantiate ` SchemaGenerator ` with a single argument, like so:
379
379
@@ -406,36 +406,60 @@ Return a nested dictionary containing all the links that should be included in t
406
406
This is a good point to override if you want to modify the resulting structure of the generated schema,
407
407
as you can build a new dictionary with a different layout.
408
408
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)
410
434
411
435
Returns a ` coreapi.Link ` instance corresponding to the given view.
412
436
413
437
You can override this if you need to provide custom behaviors for particular views.
414
438
415
- ### get_description(self, path, method, view )
439
+ ### get_description(self, path, method)
416
440
417
441
Returns a string to use as the link description. By default this is based on the
418
442
view docstring as described in the "Schemas as Documentation" section above.
419
443
420
- ### get_encoding(self, path, method, view )
444
+ ### get_encoding(self, path, method)
421
445
422
446
Returns a string to indicate the encoding for any request body, when interacting
423
447
with the given view. Eg. ` 'application/json' ` . May return a blank string for views
424
448
that do not expect a request body.
425
449
426
- ### get_path_fields(self, path, method, view ):
450
+ ### get_path_fields(self, path, method):
427
451
428
452
Return a list of ` coreapi.Link() ` instances. One for each path parameter in the URL.
429
453
430
- ### get_serializer_fields(self, path, method, view )
454
+ ### get_serializer_fields(self, path, method)
431
455
432
456
Return a list of ` coreapi.Link() ` instances. One for each field in the serializer class used by the view.
433
457
434
- ### get_pagination_fields(self, path, method, view
458
+ ### get_pagination_fields(self, path, method)
435
459
436
460
Return a list of ` coreapi.Link() ` instances, as returned by the ` get_schema_fields() ` method on any pagination class used by the view.
437
461
438
- ### get_filter_fields(self, path, method, view )
462
+ ### get_filter_fields(self, path, method)
439
463
440
464
Return a list of ` coreapi.Link() ` instances, as returned by the ` get_schema_fields() ` method of any filter classes used by the view.
441
465
0 commit comments