Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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