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

[REQ] name endpoint fns/methods using spec case operationId #32

Closed
spacether opened this issue Jan 7, 2022 · 3 comments
Closed

[REQ] name endpoint fns/methods using spec case operationId #32

spacether opened this issue Jan 7, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@spacether
Copy link
Contributor

spacether commented Jan 7, 2022

Is your feature request related to a problem? Please describe.

Some engineers prefer that endpoint methods/fns be named using the original operationId spec case
Can this feature be added to python-experimental?
@rm3l

Describe the solution you'd like

Using the original case is possible but awkward because operationIds can be any string, even invalid python variable names like:

  • " "
  • "123"
  • "A-B"

So to implement this, the api classes would:

  • be an instance of TypedDict going from operationId to endpoint fn OR
  • assign the operationId in the class __dict__

Whichever one best works with type hints would be chosen.
To do this, api_client may have to be passed in to each endpoint call.
Pseudocode would look like:

operation_id = "A-B"
endpoint = FakeApi[operation_id]
api_response = endpoint(query=params={}, body={})

Describe alternatives you've considered

Or we can keep the code as-is where operationId is converted to python snake case

Additional context

This was requested in: OpenAPITools/openapi-generator#5214 (comment)
Similar issue: OpenAPITools/openapi-generator#3813

Please vote for what you want!

  • If you want spec case used for operationId please upvote with thumbs up 👍
  • if want the code to keep using snake case for endpoint method names vote thumbs down 👎
@spacether spacether changed the title [python] have endpoint fns/methods named using original spec case [python] name endpoint fns/methods using spec case operationId Jan 7, 2022
@spacether spacether changed the title [python] name endpoint fns/methods using spec case operationId [python-experimental] name endpoint fns/methods using spec case operationId Feb 3, 2022
@spacether
Copy link
Contributor Author

spacether commented Jul 28, 2022

This issue came up when writing v3.0.3 unit test spec. When one endpoint has multiple tags it was generated multiple times. A better way to do it is to generate each endpoint once then import or inherit it in tag code.
When one does that one can easily add a dict to go from path to an Api or a tag to an Api
I am working on this in OpenAPITools/openapi-generator#13007

@spacether
Copy link
Contributor Author

spacether commented Aug 1, 2022

@rm3l and @kevariste225
With my above PR, one can get a specific endpoint by using the string path. So that allows retrieval of an endpoint using only the path and knowledge of if one needs the get/put/post/patch method.

Your feature request was to get an endpoint by operationId though.
Do either of you want to write a PR adding this functionality?
One could do it by

  • in the api class, add a class property which is a TypedDict going from spec operationId to the endpoint class that contains that method
  • one may want to add an enum class in each api tag module which contains all the operationIds in that tag so one could use values from the enum as the key in the above dict

Then one could do this:

# get an api by a tag
from package.apis.tags import TagValues
from package.apis.tag_to_api import tag_to_api
tag_enum = TagValues("someTag")
api = tag_to_api[tag_enum]
api_with_endpoint_by_operation_id = api['someOperationId']

One could see my above PR as a similar-to and I am available if you want a meeting to talk about how to do it.

@spacether spacether transferred this issue from OpenAPITools/openapi-generator Oct 1, 2022
@spacether spacether added the enhancement New feature or request label Oct 1, 2022
@spacether spacether changed the title [python-experimental] name endpoint fns/methods using spec case operationId [REQ] name endpoint fns/methods using spec case operationId Oct 1, 2022
@spacether
Copy link
Contributor Author

Closing because this repo has been relocated

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

No branches or pull requests

1 participant