Skip to content

Add operationId on OpenAPI operations #6549

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

Merged
merged 1 commit into from
Mar 29, 2019
Merged

Add operationId on OpenAPI operations #6549

merged 1 commit into from
Mar 29, 2019

Conversation

Lucidiot
Copy link
Contributor

@Lucidiot Lucidiot commented Mar 29, 2019

This pull request adds an operationId property on generated OpenAPI operations from #6532. This property is recommended in the OpenAPI specification and is actually a requirement if we want the generated schema to have any use with OpenAPI clients ; most client libraries will use those operation IDs to build methods. See the Operation Object in the OpenAPI spec for more info.

Example with openapi3 and an hypothetical ThingsListAPIView:

>>> import yaml
>>> from openapi3 import OpenAPI
>>> api = OpenAPI(yaml.safe_load(open('schema.yml').read()))
>>> api.call_ListThings()
[{'id': 1, 'name': 'thing1'}, {'id': 2, 'name': 'thing2'}]

Same example with apistar:

>>> import apistar
>>> api = apistar.Client(open('schema.yml').read())
>>> c.request('ListThings')
[{'id': 1, 'name': 'thing1'}, {'id': 2, 'name': 'thing2'}]

TODO:

  • Probably more unit tests
  • Allow setting a custom operation ID on views with an attribute?
  • Raise exceptions when operation IDs are not unique across a schema

Fixes #6542

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Lucidiot. Super.

Let's merge this in as-is, and address the points on the main PR. (It gives people a chance to test...)
I'll have a look over the weekend in more depth, but I'd rather have it in attracting issues than think about it forever first. (I hope that makes sense.)

Thanks for the input!

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

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy