z0mt3c / hapi-swaggered

Yet another hapi plugin providing swagger compliant API specifications based on routes and joi schemas to be used with swagger-ui.
MIT License
82 stars 38 forks source link

Add support for optional path parameters #160

Closed lroggendorff closed 7 years ago

lroggendorff commented 7 years ago

Hapi supports optional parameters in a route's path, designated by a ? at the end of the parameter name.

The Swagger 2.0 spec does not allow optional path parameters:

Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false.

This change allows for a valid Swagger 2.0 file to be generated from routes with optional path parameters by duplicating such routes and adjusting the parameter definitions to match.

optionssss

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 2f8b14b563dced6263a2a748d88c07ef312083e4 on lroggendorff:add-support-for-single-optional-path-parameters into d54f707c86f28ec60ad8a88e2c701b09bb5ff6ee on z0mt3c:master.

lroggendorff commented 7 years ago

@JoshMock Funny you should ask... I wondered the same thing, and even started writing a test, and then upon getting an Invalid path error from Hoek decided to look it up:

It is important to be aware that only the last named parameter in a path can be optional.

Go fig. Now, if someone wants to adds support for multi-segment parameters... that'd be fun.

z0mt3c commented 7 years ago

perfect... thanks!