Skip to content

UI doesn't invoke URIs with optional path parameters #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeffm13 opened this issue Aug 11, 2014 · 7 comments
Closed

UI doesn't invoke URIs with optional path parameters #54

jeffm13 opened this issue Aug 11, 2014 · 7 comments

Comments

@jeffm13
Copy link

jeffm13 commented Aug 11, 2014

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?

@glennjones
Copy link
Collaborator

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
Copy link

Gregy commented Nov 17, 2014

Hi,
I just ran into the same issue.

+1

@metaodi
Copy link
Contributor

metaodi commented Jan 11, 2015

+1, would like to see this "fixed"

@marcsmith
Copy link

+1 as well

@glennjones
Copy link
Collaborator

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
Copy link
Collaborator

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:

/books/{id}/cover
/library/shelves/{shelfId}/book/{id?}

There is no support for paths like

/books/{id*}
/books/{id*3}

You still need to declare the path params in the routes validate object

validate: {
            params: {
                shelfId: Joi.string().required()
                id: Joi.string().optional()
            },
}

Sorry it took so long

@jeffm13
Copy link
Author

jeffm13 commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants