Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for Non-Model Views/Viewsets #4685

Closed
thiagocharao opened this issue Nov 16, 2016 · 7 comments
Closed

Documentation for Non-Model Views/Viewsets #4685

thiagocharao opened this issue Nov 16, 2016 · 7 comments

Comments

@thiagocharao
Copy link

thiagocharao commented Nov 16, 2016

I'm struggling with a similar scenario of this issue #3373. I have a very specific service layer that gives a pretty well formed return and my views/viewsets have one job, call this service and serialize its result.

The thing is, I have two serializers, one to validate query parameters and another one to serialize service's raw return. None of them are used as "required" by DRF as serializer_class resulting that their fields won't be considered by SchemeGenerator

I'm failing when trying to create custom documentation to each endpoint, since DRF is kind of model-oriented to generate its schemas (I could write down my own schema, but I would love if DRF generates it for me though), plus I'm using Swagger as interface.

In my opinion, it would be nice to permit create docstring to create coreapi.Documents by that it would be way more flexible. Any ideas how I could proceed for now?

@tomchristie
Copy link
Member

We do need to do a better job of documenting the limitations of the automatic schema generation, and describing how to do things explicitly in the cases that it can't automatically handle, yup.

@thiagocharao
Copy link
Author

Fair enough, for now I will write schemas explicitly then.

@tomchristie
Copy link
Member

That's perfectly sensible, yup. Either:

  • Internally as CoreAPI representations.
  • Externally as schema files that you then load into CoreAPI and expose in whatever format you want.
  • Externally as schema files that you expose statically.

@thiagocharao
Copy link
Author

thiagocharao commented Nov 17, 2016

Yeah, internal CoreAPI representations are my best choice now, as I see, I think this kind of docs should be generated (as it is in a well defined standard, by serializers, fields, routers...) or something like docstrings definitions (YAML, JSON...) but really close to the endpoint code and then schema would be generated from there. django-rest-swagger used to do this kind of thing taking advantage of YAML docstrings, but it is deprecated since version 2.0.

@carltongibson
Copy link
Collaborator

This should be handled with the changes coming in with v3.7.

Override AutoSchema (or provide a ManualSchema) for your endpoint and use whatever means necessary to generated your schema. ("Specify by hand" is viable.)

The new system allows doing this per-view, so you don't loose auto-generation elsewhere.

I'm going to close this for now. Happy to new issues on specifics once you've played with the new system!

@juja256
Copy link

juja256 commented Oct 20, 2017

@carltongibson What about AutoSchema and ManualSchema for ViewSet? Will it appear in future releases? Or maybe I should split ViewSet into Views and provide ManualSchema for each of them?

@carltongibson
Copy link
Collaborator

Viewsets are APIView subclasses. (It already works.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants