Support Static Path Prefix per Definition #432
+79
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support for a static
path_prefixvalue to be set on the creation of aDefinition. The issue with the existingconfig.pathfunction is that it needs to run at runtime for every single request, and that when there are many different possible prefixes it needs to account for all of them.Imagine a Rails app built from many different engines. Engines like:
rootweatherstocksanalyticsThese engines each provide APIs that have different scaling needs. So in a production environment, you will not deploy them together. They will each get their own domains like:
api.example.comweather-api.example.comstocks-api.example.comanalytics-api.example.comHowever when you are running this Rails app locally you mount all of the engines to a single app, and configure them like:
localhost:3000localhost:3000/weatherlocalhost:3000/stockslocalhost:3000/analyticsFurthermore, imagine that each of your engines have their own Open API document. In a scenario like this, in order to configure prefixes when running locally you would have to drop those prefixes from every request like:
But this has issues because:
delete_prefixchecks are going to run on every request, even for engines that don't care about the prefix being deletedrootengine has any endpoints that begin with/weather,/stocks, or/analyticsthey will lose the prefix when they shouldn'tSo adding support for
path_prefixon Definition load enables this to become:And now the prefix only drops for the specific definition being evaluated.