Arrays in schemas show up as a separate model
See original GitHub issuev7.1.0
If I have:
"topten": Joi.array().items(
Joi.object({
name: Joi.string().required().label('name').description('user name'),
score: Joi.number().required().min(0).label('score')
}).label('TopTen')
I get something like:
{
topten (topten, optional)
}
topten [
TopTen
]
TopTen {
name (string): user name ,
score (number),
}
I would like to get something like:
{
topten (Array of TopTen, optional)
}
TopTen {
name (string): user name ,
score (number),
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Arrays in schemas show up as a separate model #331 - GitHub
Is it possible to set an option to avoid each array becoming a separate model? In my case it will reduce the number...
Read more >How can a json schema represent an array with different ...
This schema explicitly states that there can be a heartrate object. You say you're familiar with arrays of a single object type, but...
Read more >array — Understanding JSON Schema 2020-12 documentation
Arrays are used for ordered elements. In JSON, each element in an array may be of a different type. Language-specific info: Python; Ruby....
Read more >Mongoose v6.8.2: SchemaTypes
You can think of a Mongoose schema as the configuration object for a Mongoose model. A SchemaType is then a configuration object for...
Read more >Express Tutorial Part 3: Using a Database (with Mongoose)
It explains how object schema and models are declared, the main field ... The examples above show an array of objects without a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi guys,
Is it possible to set an option to avoid each array becoming a separate model? In my case it will reduce the number of models significantly.
The object above shows up like this in the swagger.json:
What I want is to reduce it to the following
Hi Glenn,
First let me thank you for all the hard work you’ve put into this over what now amounts to years. I understand the challenge of keeping things in sync with the fast moving Hapi and Joi targets, let along the swagger and swagger-ui changes.
The real goal for me in using this module is to generate clear, understandable API documentation for end-user developers. Unfortunately, we’re not there yet and in some ways it seems to be moving away from my goal. I don’t claim to understand all the ways people are using this module and for what purposes (code generation seems to be one) but they seem to be different from mine.
For documentation purposes, I don’t think it makes sense to break arrays out as separate objects. It’s just confusing. As well, I don’t understand the use of object definition equality/hashing in the module. For me, if Joi objects have different labels, they are different classes.
Right now if I do:
In the Swagger UI I see:
Apart from them being mislabeled as optional, both are marked as class A when b should be B.
Again, I don’t understand how people are using this module but I think a lot can be simplified in new versions by forcing people to be explicit in their labeling and using those labels without doing any kind of equality tests.
I don’t know where that leaves me. I see three options: