scramble icon indicating copy to clipboard operation
scramble copied to clipboard

Routes with optional params redirect to the docs home screen

Open dmason30 opened this issue 2 years ago • 2 comments

Version: 0.7.0

image

When clicking the above route with an optional parameter {book?} rather than showing the documentation for the route it redirects home /docs/api#/.

It seems likely that the question mark is causing the issue..

dmason30 avatar Jan 12 '23 12:01 dmason30

Hey @dmason30

This is a problem indeed, however I'm not sure how to solve it.

So the reason here is not only the question mark, but Open API spec itself as well. Path parameters in Open API must be required. So I'm not sure how to solve it.

Have you had Open API documentation prior to using Scramble? If so, how'd you documented this case?

Thanks!

UPD: As a solution, Scramble can document 2 endpoints: /rates and /rates/{book}. This way docs will work.

romalytvynenko avatar Jan 15 '23 10:01 romalytvynenko

Hey @dmason30

This is a problem indeed, however I'm not sure how to solve it.

So the reason here is not only the question mark, but Open API spec itself as well. Path parameters in Open API must be required. So I'm not sure how to solve it.

Have you had Open API documentation prior to using Scramble? If so, how'd you documented this case?

Thanks!

UPD: As a solution, Scramble can document 2 endpoints: /rates and /rates/{book}. This way docs will work.

This is my first time working with Open API, but after some research the way I think you describe of converting it to two endpoints seems to be the best option.

However. I am not sure how it would handle a more complex use case such as multiple optional params. But maybe have a simple solution first then try and figure the edge cases later for something like /foo/{bar?}/{baz?}. Would that end up needing to be three endpoints /foo , /foo/{bar} and /foo/{bar}/{baz}

Laravel does have a protected function getOptionalParameterNames which you could invoke via reflection to get all of the names from a route.

dmason30 avatar Jan 15 '23 14:01 dmason30