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

Operation ids from same function name #70

Closed
vitalik opened this issue Jan 25, 2021 · 6 comments
Closed

Operation ids from same function name #70

vitalik opened this issue Jan 25, 2021 · 6 comments
Milestone

Comments

@vitalik
Copy link
Owner

vitalik commented Jan 25, 2021

@api.get('/foo')
def operation(request):  #!
     pass

@api.get('/bar')
def operation(request):  #!
     pass

^ this is currently a valid and working code, but it generates two identical operation_IDs

it should validate if that happens and throw and error that operation id is already taken - pelase rename your function or set id manually

@yedpodtrzitko
Copy link

Hi,
should this really be a responsibility of the framework? To me it looks like a job for linting/static analysis tools. Both mypy or pylint (the most common tools for this purpose) are catching this kind of error. Seems good enough to me:

$ cat collide.py
def foo(): pass
def foo(): pass

$ mypy collide.py
collide.py:2: error: Name 'foo' already defined on line 1

$ pylint collide.py
collide.py:2:0: E0102: function already defined line 1 (function-redefined)

@vitalik
Copy link
Owner Author

vitalik commented Mar 9, 2021

hi @yedpodtrzitko

well it is, but technically it still a valid python code..
larger problem is here actually in operation id's - if they are the same - swagger ui basically blocks you from opening 2nd operation

@yedpodtrzitko
Copy link

well it is

sorry I'm not sure which things are you answering to - that it is part of framework's responsibilities or the CI tools?

but technically it still a valid python code..

yes. that's why the tools are able to detect and report such errors which are relatively easy to make.

larger problem is here actually in operation id's - if they are the same - swagger ui basically blocks you from opening 2nd operation

Maybe I'm missing here some piece of information - is operation a magic name which is expected to be present in order for the API docs to be generated? As such, more API endpoints in the same file would need to have the same name to get their docs generated? If not, then again - why not leave this to the CI tools?

@vitalik
Copy link
Owner Author

vitalik commented Mar 9, 2021

why not leave this to the CI tools?

because people do not do this :) and I already got lot of issues when functions are named the same

basically there two solutions here:

  • either throw exceptoin or warning when same function name detected
  • or OpenId operationId in sequence -> operation, operation_1, operation_2, , operation_3 automatically

@vitalik
Copy link
Owner Author

vitalik commented Mar 9, 2021

Maybe I'm missing here some piece of information - is operation a magic name which is expected to be present in order for the API docs to be generated?

https://swagger.io/docs/specification/paths-and-operations/

CleanShot 2021-03-09 at 11 23 41

@vitalik
Copy link
Owner Author

vitalik commented Apr 28, 2021

0.12.3 - showing a warning
0.13.0 - will throw an error

@vitalik vitalik closed this as completed Apr 28, 2021
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

No branches or pull requests

2 participants