Redocly / Redocly/openapi-sampler
OneOf not generating all options
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 228
- Forks
- 52
- Avg merge
- 48m
- Merged PRs (30d)
- 6
Description
Hi, thanks for providing such a library for the community. We are using redoc in our code and we found a potential issue in the generated JSON and we traced it down to this library. I compared the OpenAPI doc we generate using the https://editor.swagger.io/ to see if we were diverging from what is expected and apparently it is a bug here in openapi-sampler.
It happens when we use the OneOf and it generates the wrong output. To best exemplify, I created a test for the object.spec.js file.
Please let me know what you think.
it('should generate both items of oneOf', () => {
res = sampleObject({
'type': 'object',
'properties': {
'my_obj': {
'type': 'object',
'properties': {
'elements': {
'items': {
'oneOf': [
{
'type': 'object',
'properties': {
'name': {
'type': 'string',
'description': '',
'enum': [
'obj_a'
]
}
},
'title': 'obj_a',
'required': [
'name'
]
},
{
'type': 'object',
'properties': {
'name': {
'type': 'string',
'description': '',
'enum': [
'obj_b'
]
}
},
'title': 'obj_b',
'required': [
'name'
]
}
]
},
'type': 'array',
'minItems': 2,
'maxItems': 2,
'uniqueItems': true
}
},
'title': '',
'required': [
'elements'
]
}
},
'required': [
'my_obj'
]
})
expect(res).deep.equal({
'my_obj': {
'elements': [
{
'name': 'obj_a'
},
{
'name': 'obj_b'
}
]
}
})
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the object.spec.js test shown in the issue and inspect the sampleObject call for the array items using oneOf. The change is done when the test produces both objects, with names obj_a and obj_b, in the elements array as shown in the expected result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100