Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.
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

Closed

Description

@jeffm13

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?

Activity

  1. glennjones commented on Aug 17, 2014

    @glennjones
    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.

  2. Gregy commented on Nov 17, 2014

    @Gregy

    Hi,
    I just ran into the same issue.

    +1

  3. metaodi commented on Jan 11, 2015

    @metaodi
    Contributor

    +1, would like to see this "fixed"

  4. marcsmith commented on Feb 2, 2015

    @marcsmith

    +1 as well

  5. glennjones commented on Feb 14, 2015

    @glennjones
    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.

  6. glennjones commented on Feb 5, 2016

    @glennjones
    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

  7. jeffm13 commented on Feb 5, 2016

    @jeffm13
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions