fix(openapi): merge handlers with same route and different method #1497
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.
π Linked issue
#1350
β Type of change
π Description
In the openapi.ts file, the
paths
property is generated by usingObject.fromEntries
on the result of a map operation onhandlersMeta
. However, this causes unwanted behaviour : when there are sub-paths routes that only differ by their method, only the last path is present, as it has overridden the other paths information in the finalpaths
property.To fix this, I am now creating the paths object and merging the sub-paths using
Array.reduce
onhandlersMeta
instead. The operations inside this reduce are still the same as the ones inside the previous map implementation.What has changed is that now instead of returning an array of the route and its path, I now check if the accumulated value, (the total paths object), has the current route as a property. If it does not, I add the route property and the corresponding route information. If it does, I merge the current route information with the information already present for this route.
Resolves #1350
π Checklist