Commit Graph

43 Commits

Author SHA1 Message Date
Carlton Gibson
7fb11bf2f5 Removed exclude_from_schema per deprecation policy. 2018-10-10 10:44:24 +02:00
Daniel Bate
5feb835929 Feature/action docs sections (#6060)
* added ability to add sections to custom action documentation

* added tests to cover docs sections in custom actions

* added method specific docs test for action mapping

* added docs for custom action documentation
2018-10-10 10:29:29 +02:00
Ryan P Kilby
33f8910b26
Fix deprecation warnings in tests (#6076)
* Fix deprecated arguments in schema tests

* Update optional reqs, fixing markdown deprecation
2018-07-09 23:56:52 -04:00
Ryan P Kilby
7095021db7 Rename base_name => basename for consistency's sake (#5990)
* Rename base_name => basename for consistency

* Update tests to use basename
2018-07-06 11:03:12 +02:00
Ryan P Kilby
6511b52cca Fix schemas for extra actions (#5992)
* Add failing test for extra action schemas

* Add ViewInspector setter to store instances

* Fix schema disabling for extra actions

* Add docs note about disabling schemas for actions
2018-07-06 10:35:36 +02:00
Ryan P Kilby
0148a9f8da Improvements to ViewSet extra actions (#5605)
* View suffix already set by initializer

* Add 'name' and 'description' attributes to ViewSet

ViewSets may now provide their `name` and `description` attributes
directly, instead of relying on view introspection to derive them.
These attributes may also be provided with the view's initkwargs.

The ViewSet `name` and `suffix` initkwargs are mutually exclusive.

The `action` decorator now provides the `name` and `description` to
the view's initkwargs. By default, these values are derived from the
method name and its docstring. The `name` may be overridden by providing
it as an argument to the decorator.

The `get_view_name` and `get_view_description` hooks now provide the
view instance to the handler, instead of the view class. The default
implementations of these handlers now respect the `name`/`description`.

* Add 'extra actions' to ViewSet & browsable APIs

* Update simple router tests

Removed old test logic around link/action decorators from `v2.3`. Also
simplified the test by making the results explicit instead of computed.

* Add method mapping to ViewSet actions

* Document extra action method mapping
2018-07-06 10:33:10 +02:00
Ryan P Kilby
1a170438d2 Add "optionals not required" build (#6047) 2018-06-22 10:16:57 +02:00
Jimmy Merrild Krag
5ee0e5df83 Correct schema parsing for JSONField (#5878)
Fixes #5873.
* Use Object type. 
* Add test for field_to_schema
2018-04-20 15:47:20 +02:00
Carlton Gibson
fc588f539b
Version 3.8 Release (#5769) 2018-04-03 15:35:26 +02:00
Jeremy Lainé
a8d129b7da Represent serializer DictField as an Object in schema
DictFields were incorrectly being output as String in the schema.
This pull request outputs an Object instead and adds a unit test.

Update s/detail_route/action/ after rebase
2018-02-01 16:23:24 +01:00
Jeremy Lainé
27f32faee4 Fix schema generation for PrimaryKeyRelatedField (#5764)
By default all subclasses of RelatedField are output as string fields in
the schema, which works well for StringRelatedField, SlugRelatedField or
HyperlinkedRelatedField.

Handle the common case of a PrimaryKeyRelatedField pointing to an
AutoField.
2018-02-01 16:14:35 +01:00
Ryan P Kilby
73203e6b59 Rework dynamic list/detail actions (#5705)
* Merge list/detail route decorators into 'action'

* Merge dynamic routes, add 'detail' attribute

* Add 'ViewSet.get_extra_actions()'

* Refactor dynamic route checking & collection

* Refactor dynamic route generation

* Add 'ViewSet.detail' initkwarg

* Fixup schema test

* Add release notes for dynamic action changes

* Replace list/detail route decorators in tests

* Convert tabs to spaces in router docs

* Update docs

* Make 'detail' a required argument of 'action'

* Improve router docs
2018-01-25 09:40:49 +01:00
Tilmann Becker
d38b94fd74 Fix URL pattern parsing in schema generation (#5689)
* Fix url parsing in schema generation

- Call `str(pattern)` to get non-escaped route
- Strip converters from path to comply with uritemplate format. 
   Background: https://github.com/encode/django-rest-framework/issues/5675#issuecomment-352829363

Fixes #5675
2017-12-20 09:10:28 +01:00
Carlton Gibson
791539acec
Add DEFAULT_SCHEMA_CLASS setting (#5658)
* Add test for new setting

* Add DefaultSchema utility

* Add new setting to docs
2017-12-14 11:24:21 +01:00
Carlton Gibson
a0cdba6277
Extract method for manual_fields processing (#5633)
* Extract method for `manual_fields` processing

Allows reuse of logic to replace Field instances in a field list by `Field.name`.

Adds a utility function for the logic plus a wrapper method on `AutoSchema`.

Closes #5632

* Manual fields suggestions (#2)

* Use OrderedDict in inspectors

* Move empty check to 'update_fields()'

* Make 'update_fields()' an AutoSchema staticmethod

* Add 'AutoSchema.get_manual_fields()'

* Conform '.get_manual_fields()' to other methods

* Add test for update_fields

* Make sure `manual_fields` is a list.

(As documented to be)

* Add docs for new AutoSchema methods.

* `get_manual_fields`
* `update_fields`

* Add release notes for PR.
2017-12-04 09:07:43 +01:00
Michał Bielawski
134a6f66f9 Fixed schema generation for filter backends (#5613) 2017-11-22 00:11:59 -05:00
Jon Dufresne
44823b0e1d Fix invalid escape sequence deprecation warnings
When running tests with warnings enabled, appear as:

  DeprecationWarning: invalid escape sequence \d

Starting with Python 3.6, invalid escape sequences are deprecated. In a
future Python versions they will be a syntax error. For more details, see:

https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior

> A backslash-character pair that is not a valid escape sequence now
> generates a DeprecationWarning. Although this will eventually become a
> SyntaxError, that will not be for several Python releases.
2017-11-05 10:09:38 -08:00
Carlton Gibson
7261ae653a Schema: Exclude OPTIONS/HEAD for ViewSet actions (#5532)
Closes #5528.

Viewset custom actions (@detail_route etc) OPTIONS (and HEAD) methods were not being excluded from Schema Generations.

This PR adds a test reproducing the reported error and adjusts `EndpointEnumerator.get_allowed_methods()` to filter ViewSet actions in the same way as other `APIView`s
2017-10-25 10:56:40 +02:00
Marcin
5d7b6e5b2f Fixed issues with schema name collisions (#5486)
* Fixed issues with schema name collisions

* Fixed mutating issues in python 3

* Optimized solution

* Fixed isort

* Removed not needed cast

* Fix for key collision

* Added preferred key to preserve if available

* Add accidently removed test
2017-10-16 11:32:48 +02:00
Carlton Gibson
c7fb60bcd4 Django 2.0a1 compat (#5503)
* Update remaing `include` calls

Missed as part of #5481 cleanup.

* Provide app_name in include_docs_urls

* Update remaining get_regex_pattern usages

* Allow functools.partial in is_simple_callable check
2017-10-16 11:31:13 +02:00
Carlton Gibson
2edeb74e0e Have is_list_view recognise RetrieveModel… views (#5480)
Fixes #5165
2017-10-05 20:41:14 +02:00
Carlton Gibson
d138f30a86 Fix naming collisions in Schema Generation (#5464)
* Add failing tests for #4704

* Add generic view based test case.

* Adjust insert_into to raise ValueError
2017-10-05 11:06:09 +02:00
Carlton Gibson
b1c6ea1240 Adjust schema get_filter_fields rules to match framework (#5454)
Closes #5237

Generics/ModelViewset performs filtering on: list, retrieve, put, patch and destroy (plus method equivalents).

i.e. on list plus anything that calls `get_object`.

This PR makes schema generation follow that.

It adds `AutoSchema._allows_filters()` which can be overridden in subclasses.

I’ve made this initially “private” so we can make quick changes if needs be in a 3.7.1 etc.
2017-09-27 09:13:10 +02:00
Carlton Gibson
7b1582e00e Allow schema = None. Deprecate exclude_from_schema (#5422)
* Add tests for schema exclusions

* Move exclusion check to should_include_endpoint

* Update docs

* Switch to using `schema = None`

* Test PendingDeprecationWarnings

* Add note to release notes.

* s/deprecated/pending deprecation/

* Add PR link to release notes

* Correct typo in test class name

* Test 'exclude_from_schema' deprecation warning message (#1)

* Correct deprecation warning message
2017-09-20 11:29:47 +02:00
Carlton Gibson
efff9ff338 5378 fix schema generation markdown (#5421)
* Test case for #5240
* Remove unnecessary strip()  from get_description

Closes #5240

* Adjust test case
2017-09-14 12:20:41 +01:00
Carlton Gibson
d54df8c438 Refactor schema generation to allow per-view customisation (#5354)
* Initial Refactor Step

* Add descriptor class
* call from generator
* proxy back to generator for implementation.

* Move `get_link` to descriptor

* Move `get_description` to descriptor

* Remove need for generator in get_description

* Move get_path_fields to descriptor

* Move `get_serializer_fields` to descriptor

* Move `get_pagination_fields` to descriptor

* Move `get_filter_fields` to descriptor

* Move `get_encoding` to descriptor.

* Pass just `url` from SchemaGenerator to descriptor

* Make `view` a property

Encapsulates check for a view instance.

* Adjust API Reference docs

* Add `ManualSchema` class

* Refactor to `ViewInspector` plus `AutoSchema`

The interface then is **just** `get_link()`

* Add `manual_fields` kwarg to AutoSchema

* Add schema decorator for FBVs

* Adjust comments

* Docs: Provide full params in example

Ref feedback b52e372f8f (r137254795)

* Add docstring for ViewInstpector.__get__ descriptor method.

Ref https://github.com/encode/django-rest-framework/pull/5354#discussion_r137265022

* Make `schemas` a package.

* Split generators, inspectors, views.

* Adjust imports

* Rename to EndpointEnumerator

* Adjust ManualSchema to take `fields`

… and `description`.

Allows `url` and `action` to remain dynamic

* Add package/module docstrings
2017-09-14 09:46:34 +01:00
Lim H
56021f9e77 Add tests for list field to schema 2017-08-20 17:12:56 +01:00
Bekhzod Tillakhanov
84e22cc2f3 Scheme fix when unauth and Flask8 lint fix 2017-05-30 00:15:07 +05:00
hurturk
2196cd2bbb Generate schema with respect to http_method_names provided by CBV 2017-04-18 23:44:18 -04:00
Tom Christie
68d2020112 Live API documentation (#4755) 2017-03-03 15:24:37 +00:00
Artem Muterko
401ab54275 Refactor schemas tests style 2017-01-12 18:33:24 +02:00
Andrzej Pragacz
45e058d7ba Fix unhandled Http404, PermissionDenied in schema generation (#4645) (#4646) 2016-11-02 09:04:01 +00:00
Tom Christie
0fe0e1e703 Fix schema base paths (#4611) 2016-10-21 16:59:34 +01:00
Alexey Evseev
2519ce9128 Fix schema generation with custom page_size pagination param (#4567) 2016-10-12 16:09:45 +01:00
Tom Christie
0dec36eb41 Version 3.5 (#4525)
* Start test case

* Added 'requests' test client

* Address typos

* Graceful fallback if requests is not installed.

* Add cookie support

* Tests for auth and CSRF

* Py3 compat

* py3 compat

* py3 compat

* Add get_requests_client

* Added SchemaGenerator.should_include_link

* add settings for html cutoff on related fields

* Router doesn't work if prefix is blank, though project urls.py handles prefix

* Fix Django 1.10 to-many deprecation

* Add django.core.urlresolvers compatibility

* Update django-filter & django-guardian

* Check for empty router prefix; adjust URL accordingly

It's easiest to fix this issue after we have made the regex.  To try
to fix it before would require doing something different for List vs
Detail, which means we'd have to know which type of url we're
constructing before acting accordingly.

* Fix misc django deprecations

* Use TOC extension instead of header

* Fix deprecations for py3k

* Add py3k compatibility to is_simple_callable

* Add is_simple_callable tests

* Drop python 3.2 support (EOL, Dropped by Django)

* schema_renderers= should *set* the renderers, not append to them.

* API client (#4424)

* Fix release notes

* Add note about 'User account is disabled.' vs 'Unable to log in'

* Clean up schema generation (#4527)

* Handle multiple methods on custom action (#4529)

* RequestsClient, CoreAPIClient

* exclude_from_schema

* Added 'get_schema_view()' shortcut

* Added schema descriptions

* Better descriptions for schemas

* Add type annotation to schema generation

* Coerce schema 'pk' in path to actual field name

* Deprecations move into assertion errors

* Use get_schema_view in tests

* Updte CoreJSON media type

* Handle schema structure correctly when path prefixs exist. Closes #4401

* Add PendingDeprecation to Router schema generation.

* Added SCHEMA_COERCE_PATH_PK and SCHEMA_COERCE_METHOD_NAMES

* Renamed and documented 'get_schema_fields' interface.
2016-10-10 13:03:46 +01:00
José Padilla
d0ed482d70 Skip HiddenField from Schema fields (#4429) 2016-08-22 16:53:53 +01:00
Tom Christie
e3f8d06baf Include .action attribute on viewsets when generating schemas (#4408) 2016-08-15 17:10:55 +01:00
Tom Christie
116917dbed Add form field descriptions to schemas (#4387) 2016-08-11 16:18:33 +01:00
Tom Christie
01b498ec51 Fix schema categories for custom list actions (#4386) 2016-08-11 14:07:40 +01:00
Tom Christie
b50d8950ee Pass request to schema generation (#4383)
Pass request to schema generation
2016-08-11 11:27:28 +01:00
Tom Christie
d5178c9246 Include kwargs passed to 'as_view' when generating schemas (#4359) 2016-08-05 11:19:39 +01:00
Alexander Gaevsky
46a870c002 Fix schema generation for APIView, since it does not have get_serializer_class method. (#4285) 2016-07-27 15:36:36 +01:00
Tom Christie
6ff9840bde Schemas & client libraries. (#4179)
* Added schema generation support.
* New tutorial section.
* API guide on schema generation.
* Topic guide on API clients.
2016-07-04 16:38:17 +01:00