PythonNest / PyNest

PyNest is a Python framework built on top of FastAPI that follows the modular architecture of NestJS
https://pythonnest.github.io/PyNest
MIT License
737 stars 50 forks source link

Using controller tag as default prefix breaks existing routes #38

Open emanuel248 opened 8 months ago

emanuel248 commented 8 months ago

Setting the controller tag as prefix if none was set breaks exisitng routes, such changes should be better thought through. At least add a runtime warning or an exception if no prefix was set and you want to make it mandatory. And the breaking change was made in a patch version !

ItayTheDar commented 8 months ago

Hi @emanuel248, You are correct, i don't know how I missed it, and how I didn't create a test for it. sorry for that.

just to be clear, you mean when I'm creating controller this way -

@Controller()
class BookController:
    service: BookService = Depends(BookService)

I'm getting this error - AttributeError: 'NoneType' object has no attribute 'startswith'

Is that the error you've encountered also?

and another question - what do you think would be the appropriate solution? if the tag and the prefix are both None then automatically set the route to "/", or force the tag/prefix not to be None?

emanuel248 commented 8 months ago

Hello @ItayTheDar ,

the case I had was to create the controller like this:

@Controller("documents")

this is used as tag but the controller prefix was empty. Now it will take the tag as prefix so all URLs will be prefixed with "/documents". I've fixed it by setting prefix="", tag="documents".

I'd propose to use "/" if no prefix is set, as prefix and tag have different semantic meanings, so should stay separated.

The solutions to this is:

@Controller(tag="documents", prefix="")