Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nested oneOf + allOf #37

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/includer/traverse/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ function prepareSampleElement(

const schema = findNonNullOneOfElement(value);

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

switch (type) {
case 'object':
return prepareSampleObject(schema, downCallstack);
Expand Down
Loading