Skip to content
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

Add title to property based on Joi meta property #878

Merged
merged 1 commit into from
Nov 4, 2023

Conversation

mattixittam
Copy link
Contributor

@mattixittam mattixittam commented Oct 24, 2023

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.

image

To show a more descriptive label you can add the title property to each of the alternatives, which gets you something like this:

image

This PR adds support for the title-property to hapi-swagger through the title Joi.meta() property.

joiModel.meta({ title: 'SIF' })

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:

status: Joi.string().meta({ title: 'QuotationStatus' }),

image

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 to swaggerTitle I guess.

@robmcguinness robmcguinness merged commit af8c9c6 into hapi-swagger:master Nov 4, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants