kenspirit / joi-to-json

Capable of converting different versions' joi object to json schema
MIT License
39 stars 18 forks source link

Ability to support custom annotations? #19

Closed rattrayalex closed 3 years ago

rattrayalex commented 3 years ago

Hello again,

OpenAPI lets you add custom annotations like so:

{'type': 'string', 'x-my-attribute': 'something'}

Is there a way to do this? I tried joi.string().meta({'x-foo': 'bar'}) but it did not seem to work. I am not sure if it would make sense to pass meta properties through in general.

Thanks!

kenspirit commented 3 years ago

Hi @rattrayalex, can you point me the documentation of OpenAPI that the support of custom annotations?

I think this issue can be considered with #18.

The previous approach is taking JSON as intermediary between Joi and OpenAPI. However, since JSON schema does not have the flexibility to support custom attributes, maybe the direct conversion between Joi and OpenAPI is better.

rattrayalex commented 3 years ago

Ah, sorry, they're called "Specification extensions" not "custom annotations". Basically you can have a field prefixed with x- that has any value. For one example you can search for x- in Stripe's openapi spec, there are many usages there.

I agree though that we should largely fold this into #18, I will discuss about openapi+json-schema there.

kenspirit commented 3 years ago

Supports in Version 2.0.0 and issue #18 is used to keep track of OpenAPI support.