Twipped / joi-to-swagger

A library to convert Joi schema objects into Swagger schema definitions
Other
164 stars 63 forks source link

Fix: enable support for Key-Value Maps via additionalProperties #93

Closed JKEnv closed 2 years ago

JKEnv commented 2 years ago

This fix enables the following swagger function: https://swagger.io/docs/specification/data-models/dictionaries/

This is how its done via Joi: Joi.object().pattern(/^/, Joi.object({name: Joi.string()}))

I've tested this in a personal project.

Mairu commented 2 years ago

Could you please add a test case for it?

JKEnv commented 2 years ago
const joiObj = Joi.object().pattern(/^/, Joi.object().keys({name: Joi.string()}));

let TestMap = j2s(joiObj).swagger;

with the current implementation it gets me the following: grafik

with my pull request it gets me: grafik

Mairu commented 2 years ago

What I meant was, if you could please add a unit test (case) for it to the tests.js file. Sorry for being not specific enough in the first place.

JKEnv commented 2 years ago

Oh, thanks for the more precise definition. I've added some tests to prove my point

Mairu commented 2 years ago

Thank you for the PR, will release a new version soon. Closes #94