kenspirit / joi-to-json

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

added support for object patterns #11

Closed PetarIvancevic closed 3 years ago

PetarIvancevic commented 3 years ago

Adding support for dynamic keys as described here https://github.com/kenspirit/joi-to-json/issues/10

kenspirit commented 3 years ago

@PetarIvancevic Thanks for the PR. Could you also update the sample in fixtures and the generated output? I still cannot imagine your use case and what the json schema looks like. If the pattern is a regex, this serves as one json schema field?

kenspirit commented 3 years ago

@PetarIvancevic

The PR seems good.

The question in my mind is that an "/s/" field in dynamicKeyHolder in the JSON schema is really helpful to you? I cannot imagine how you can validate your JSON using this schema. Do you have a custom JSON schema validator? Or any standard JSON schema validator can do that?

PetarIvancevic commented 3 years ago

On a project we have an object that has dynamic keys depending on the ids that are assigned. The ids are strings and they are objects which have a defined schema. For documentation purposes we require these fields to be documented. Using joi I made a small recursive function to go through your JSON output of the joi schema and define fields to populate in a table :)

kenspirit commented 2 years ago

Hi @PetarIvancevic,

I am wondering if your scenario of dynamic key should be using patternProperties as shown in this documentation