fastify / fastify-swagger

Swagger documentation generator for Fastify
MIT License
915 stars 201 forks source link

feat: add support for server relative and templated urls #684

Closed salvdel closed 1 year ago

salvdel commented 1 year ago

Checklist

Hello everyone, in an attempt to fix issues #494 and #540 I integrated support for server relative and templated urls.

When stripBasePath was set to true then the server url was being parsed as is using new URL(serverUrl). This inevitably resulted in an error when the server url was either relative (e.g. /foo/bar) or templated (e.g. http://localhost:{port}/{basePath}).

The changes introduced by this PR solve the issue by first resolving the server url (by replacing templated variables with the corresponing values) and then by using it as is if relative or otherwise parsing it through new URL(serverUrl) in order to extract the pathname.

Fixes #494, Fixes #540

salvdel commented 1 year ago

@Fdawgs Hello there and thank you for the review.

Regarding the documentation I don't think it needs to be updated. This is more of a bug fix since the related behavior was already kind of expected but didn't work properly.

salvdel commented 1 year ago

@Uzlopak thank you for merging this.

I have a small request: I'm participating in hacktoberfest 2022 and it would be very cool to have this PR count toward the monthly PRs goal over there. Is there a chance you can label this PR with the hacktoberfest-accepted label?