Redocly / Redocly/openapi-sampler
BUG: Recursive schemas are not handled correctly
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 228
- Forks
- 52
- Avg merge
- 48m
- Merged PRs (30d)
- 6
Description
Reproduction:
import { sample } from "openapi-sampler";
const recursive = {
type: "object",
properties: { human: { $ref: "#/definitions/person" } },
definitions: {
person: {
type: "object",
properties: {
name: { type: "string" },
friend: { $ref: "#/definitions/person" },
friends: { type: "array", items: { $ref: "#/definitions/person" } },
},
required: ["name", "friends"],
},
},
}
const fromSampler = sample(recursive, {}, recursive);
console.log(fromSampler);
Reproduction Invalid Output
{ human: { name: 'string', friend: {}, friends: [ {} ] } }
Which is invalid according to the schema, the friends array should be either empty or contain one valid person and friend field should be either omitted or valid item.
Expected Output
Where friends array is just empty and friend item omitted.
{ human: { name: "string", friends: [] } }
Or where it contains one valid item:
{
human: {
name: "string",
friend: { name: "string", friends: [] },
friends: [{ name: "string", friends: [] }],
},
}
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 by running the reproduction with sample from the package and compare the invalid and expected outputs. Trace recursive $ref handling, then verify that recursive friend and friends values are either omitted or empty, or contain valid person samples rather than invalid empty objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100