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
I'd like to be able to set up a separate default on the Swagger from the one in Joi.
My use case is this: I want to add a default solely in the Swagger docs for a query parameter, so that all new uses where people use the "Try it out" option to get the url to use, they will have the new default. This helps with a slow migration to make that the default in Joi as well and drop the old behavior.
If the customization allows for removing a default as well, it would help workaround issues like #874 from user-land where the default is a complex object and won't work in the swagger ui.
- let propertyDefault = Hoek.reach(joiObj, '_flags.default');+ let propertyDefault = Utilites.getJoiMetaProperty(joiObj, 'swaggerDefault') ?? Hoek.reach(joiObj, '_flags.default');
Edit: Utilities.getJoiMetaProperty should likely be updated to check for nulls instead of truthyness. - currently a meta value of false would return undefined instead of false
This one-liner would require documenting with the swagerDefault that an empty array will prevent any defaults from being set, as that wouldn't be intuitive to users.
You could also make it so that an undefinedswaggerDefault would continue to the normal default, but a null one would also prevent a default from being set, or some other variation of this (like checking if the swaggerDefault meta key exists at all and using it if it does).
Edit2: Probably best to go with this second option - as if you send in an empty array, the UI for the defaultValue when "Try it Out" is not on will show "Default value : List []" as the default, instead of nothing.
It might also make sense to add a swaggerDefaultText to override the "Default value : ..." text when needed.
The text was updated successfully, but these errors were encountered:
Issue
I'd like to be able to set up a separate default on the Swagger from the one in Joi.
My use case is this: I want to add a default solely in the Swagger docs for a query parameter, so that all new uses where people use the "Try it out" option to get the url to use, they will have the new default. This helps with a slow migration to make that the default in Joi as well and drop the old behavior.
If the customization allows for removing a default as well, it would help workaround issues like #874 from user-land where the default is a complex object and won't work in the swagger ui.
Proposed Solution:
Change properties.js#343 to:
Edit:
Utilities.getJoiMetaProperty
should likely be updated to check for nulls instead of truthyness. - currently a meta value offalse
would returnundefined
instead offalse
This one-liner would require documenting with the
swagerDefault
that an empty array will prevent any defaults from being set, as that wouldn't be intuitive to users.You could also make it so that an
undefined
swaggerDefault
would continue to the normal default, but anull
one would also prevent a default from being set, or some other variation of this (like checking if theswaggerDefault
meta key exists at all and using it if it does).Edit2: Probably best to go with this second option - as if you send in an empty array, the UI for the defaultValue when "Try it Out" is not on will show "Default value : List []" as the default, instead of nothing.
It might also make sense to add a
swaggerDefaultText
to override the "Default value : ..." text when needed.The text was updated successfully, but these errors were encountered: