You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 4, 2026. It is now read-only.
UI doesn't invoke URIs with optional path parameters #54
It looks like the Swagger UI has a problem with hapi-style optional path parameters. With a route defined as:
/books/{id}/cover
Swagger UI has no trouble at all. It documents the route, and enables me to invoke it from the UI. Great!
But when a parameterized path contains an optional parameter at the end, it has a problem:
/library/shelves/{shelfId}/book/{id?}
Here it documents the route, including the optional parameter segment. But when I try to execute the from the UI, leaving the optional parameter blank, the UI never invokes the API.
Did I miss something in the documentation? Or is this an issue?
Had a look at the Swagger spec and it looks like it only works with optional parameters for form and querystrings, but not path parameters. This is one of area where HAPI has wider functionality than Swagger.
It would be possible to fix this, you would need to modify the swagger.js file function SwaggerOperation.prototype.urlify. I am trying not to make this type of change as it will make the plug-in harder to maintain. The swagger.js file is updated quite often. You could of course fork the project and do it yourself. If enough people want this, I will consider making the changes needed.
This use case of a optional path is not supported by swagger 1.2 spec and the current swagger UI code. swagger-api/swagger-ui#380
At the bottom of the comments on the issue Tony Tam says that the issue maybe fix with swagger 2.0 spec and new swagger UI.
I am just about to start the work to move over to 2.0 swagger, so I hope there will be a fix for you somewhere down the line. I am not sure how long it going to take to rebuild the plug-in, but I will post on this issue again when I have something.
I'll try to check it out in the next few days. I just wanted to say thank you now for all the work you've done on this plugin. It keeps on getting better and you apparently have endless energy. Great work!
Activity
glennjones commentedon Aug 17, 2014
Hi sorry its taken a while to get back to you.
Had a look at the Swagger spec and it looks like it only works with optional parameters for form and querystrings, but not path parameters. This is one of area where HAPI has wider functionality than Swagger.
It would be possible to fix this, you would need to modify the swagger.js file function SwaggerOperation.prototype.urlify. I am trying not to make this type of change as it will make the plug-in harder to maintain. The swagger.js file is updated quite often. You could of course fork the project and do it yourself. If enough people want this, I will consider making the changes needed.
Gregy commentedon Nov 17, 2014
Hi,
I just ran into the same issue.
+1
metaodi commentedon Jan 11, 2015
+1, would like to see this "fixed"
marcsmith commentedon Feb 2, 2015
+1 as well
glennjones commentedon Feb 14, 2015
Hi Everyone
Taken another look at this
This use case of a optional path is not supported by swagger 1.2 spec and the current swagger UI code. swagger-api/swagger-ui#380
At the bottom of the comments on the issue Tony Tam says that the issue maybe fix with swagger 2.0 spec and new swagger UI.
I am just about to start the work to move over to 2.0 swagger, so I hope there will be a fix for you somewhere down the line. I am not sure how long it going to take to rebuild the plug-in, but I will post on this issue again when I have something.
glennjones commentedon Feb 5, 2016
Support for Swagger v2.x was added in December 2015 and we now have partial fixes for some of the path template issues
The plug-in now supported for paths like:
There is no support for paths like
You still need to declare the path params in the routes
validateobjectSorry it took so long
jeffm13 commentedon Feb 5, 2016
Glenn,
I'll try to check it out in the next few days. I just wanted to say thank you now for all the work you've done on this plugin. It keeps on getting better and you apparently have endless energy. Great work!
Jeff