Skip to content

Commit

Permalink
fix: nested oneOf + allOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiri111enz authored and v8tenko committed Jan 30, 2024
1 parent c79f415 commit 02e1e5e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/__snapshots__/combiners/complex.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ Generated server url{.openapi__request__description}
\`\`\`json
{
"name": "b"
"name": "b",
"age": {
"c": "c"
}
}
\`\`\`
Expand Down Expand Up @@ -86,7 +89,10 @@ Base 200 response
\`\`\`json
{
"name": "b"
"name": "b",
"age": {
"c": "c"
}
}
\`\`\`
Expand Down
36 changes: 28 additions & 8 deletions src/__tests__/combiners/complex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@ describe('operators complex test', () => {
{
allOf: [
{
type: 'number',
default: 10,
type: 'object',
properties: {
c: {
type: 'string',
default: 'c'
}
}
},
],
},
{
allOf: [
{
type: 'boolean',
default: true,
type: 'object',
properties: {
d: {
type: 'number',
default: 10
}
}
},
],
},
Expand All @@ -79,16 +89,26 @@ describe('operators complex test', () => {
{
allOf: [
{
type: 'number',
default: 10,
type: 'object',
properties: {
c: {
type: 'string',
default: 'c'
}
}
},
],
},
{
allOf: [
{
type: 'boolean',
default: true,
type: 'object',
properties: {
d: {
type: 'number',
default: 10
}
}
},
],
},
Expand Down
5 changes: 5 additions & 0 deletions src/includer/traverse/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ function prepareSampleElement(
}

const downCallstack = callstack.concat(value);

if (value.oneOf?.length) {
return prepareSampleElement(key, value.oneOf[0], isRequired(key, value), downCallstack);
}

const type = inferType(value);

const schema = findNonNullOneOfElement(value);
Expand Down

0 comments on commit 02e1e5e

Please sign in to comment.