Add title to property based on Joi meta property #878
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The thing that led to this PR is the OpenAPI v3 AnyOf generation. In Redocly (which we use) at least this shows the type ('object', 'string', 'number') on the alternatives-selector by default.
To show a more descriptive label you can add the
title
property to each of the alternatives, which gets you something like this:This PR adds support for the
title
-property to hapi-swagger through thetitle
Joi.meta() property.I've added it very generically, as this property can be added to any schema in both OpenAPI 2 & 3, and display after the property type in Redocly:
It was deceptively simple to add, so please let me know if I missed any edge-cases, added it to the wrong tests or did something else stupid :)
I did not check how this affects SwaggerUI display, but it seems that such an integral part of the OpenAPI def should just work :)
The meta property name
title
may be too generic, we could change it toswaggerTitle
I guess.