DeanWay / fastapi-versioning

api versioning for fastapi web applications
MIT License
642 stars 63 forks source link

Is there any way to versioning the internal methods like services, db operations, helpers etc #29

Closed sany2k8 closed 3 years ago

sany2k8 commented 3 years ago

This package seems very good for API route versioning, is there any way to versioning the internal methods like services, db operations, helpers etc

@version(1, 0)
@staticmethod
def get_seasons():
        return {
                'summer': 'June-August',
                'winter': 'December-February',
                'autumn': 'September-November',
                'spring': 'March-May'
        }
@version(1, 1)
@staticmethod
def get_seasons():
        return {
                'summer': '6-8',
                'winter': '12-2',
                'autumn': '9-11',
                'spring': '3-5'
        }

So in future if i need to remove the old version of service, helpers or db methods I can easily find by version and remove unused codes.

DeanWay commented 3 years ago

This request seems out of scope of this project, but maybe I can help with some suggestions.

If you have some logic that is truly tied to a particular api version then it might be best to collocate that logic with your api version function, or create some package structure to denote versioned logic.

Otherwise in the more likely case that you want your logic determined somewhat separately from your API structure, it seems what you want is a way to determine when you have some dead code. This is can be a hard problem in python since module attributes can be accessed dynamically and any definition can have side-effects, though in many circumstances searching for call sites is good enough. My best suggestion would be to use a test coverage tool to see which lines are hit when testing each API version to inform your approach for cleaning up dead code paths.

There is a tool on pypi whose stated purpose is to help you clean up dead code, never used it myself but you could check it out: https://pypi.org/project/vulture/