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

OpenAPI schema generation is missing operationId properties #6542

Closed
4 of 6 tasks
Lucidiot opened this issue Mar 28, 2019 · 4 comments
Closed
4 of 6 tasks

OpenAPI schema generation is missing operationId properties #6542

Lucidiot opened this issue Mar 28, 2019 · 4 comments

Comments

@Lucidiot
Copy link
Contributor

This issue occurs when using the updated OpenAPI schema generation by @carltongibson (#6532).

Most OpenAPI client tools, such as apistar or openapi3, require an operationId property to be able to perform requests. In the case of APIStar, if the operation ID is missing, a slugified title is used (code here); however the title property seems to also be missing. For those reasons, opening a generated schema with a client will show zero available endpoints.

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Run ./manage.py generateschema on any project that has an API endpoint, then load the generated YAML schema with a client library such as API Star:

>>> import apistar
>>> client = apistar.Client('schema.yaml')
>>> client.document.get_links()
[]

APIStar will state that the schema is valid, because operationId is not required but recommended, but it will be empty.

Expected behavior

An OpenAPI schema with operationId properties to give a name to each endpoint. It seems the renderer on 3.9/master did set the property.

Actual behavior

Each path in the schema is missing a name, description, or any kind of identifier that could be used by client libraries.

@carltongibson
Copy link
Collaborator

Yep. On the list, but input there welcome too. (Both on operationId and title.)
(The CoreAPI generation already generates similar so it should just be a case of moving parts around...)

@Lucidiot
Copy link
Contributor Author

Lucidiot commented Mar 29, 2019

@carltongibson I am trying to look into the code to understand how I could experiment with the ID generation, and I was wondering: if coreapi is being deprecated, why is it still in use everywhere in the OpenAPI schema generators? Is there a transition planned later on to another library?

@carltongibson
Copy link
Collaborator

carltongibson commented Mar 29, 2019

...why is it still in use everywhere in the OpenAPI schema generators?

It's not. 🙂 It's still in the files because A) it's being deprecated not removed instantly and B) I've not got to the cleanup phase where it might (say) get moved in a separate file.

If you want to add this... OpenAPIAutoSchema.get_operation() : the return dict there needs an extra key. (operationId). It'll need to be named off of the view or model or serializer name, plus a mapping from method to e.g. create, destroy etc. (e.g. good operationIds might be CreateSnippet, RetrieveSnippet, ListSnippets, and so on.)

If you just want to have a first go at that and open a PR, I'm happy to advise... 🙂

@carltongibson
Copy link
Collaborator

Closed by #6549

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

2 participants