Skip to content

Commit

Permalink
fix: properties + oneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiri111enz committed Feb 6, 2024
1 parent 09d3017 commit 321767e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/__snapshots__/combiners/complex.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Generated server url{.openapi__request__description}
"name": "b",
"age": {
"c": "c"
}
},
"type": "string",
"bar": "string"
}
\`\`\`
Expand Down Expand Up @@ -92,7 +94,9 @@ Base 200 response
"name": "b",
"age": {
"c": "c"
}
},
"type": "string",
"bar": "string"
}
\`\`\`
Expand Down
16 changes: 12 additions & 4 deletions src/__snapshots__/combiners/oneOf.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ Generated server url{.openapi__request__description}
\`\`\`json
{
"name": "string",
"age": 0
"age": 0,
"type": "string",
"baz": "string"
}
\`\`\`
Expand Down Expand Up @@ -190,7 +192,9 @@ Cat class
\`\`\`json
{
"name": "string",
"age": 0
"age": 0,
"type": "string",
"baz": "string"
}
\`\`\`
Expand Down Expand Up @@ -251,7 +255,9 @@ Generated server url{.openapi__request__description}
"pet": {
"type": "string",
"baz": "string"
}
},
"type": "string",
"baz": "string"
}
\`\`\`
Expand Down Expand Up @@ -305,7 +311,9 @@ Cat class
"pet": {
"type": "string",
"baz": "string"
}
},
"type": "string",
"baz": "string"
}
\`\`\`
Expand Down
7 changes: 7 additions & 0 deletions src/includer/traverse/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ function findNonNullOneOfElement(schema: OpenJSONSchema): OpenJSONSchema {
const merged = RefsService.merge(v);

if (Object.keys(merged.properties || {}).length) {
if (v.oneOf?.length) {
const option = v.oneOf[0];
if (typeof option === 'object' && option.properties) {
v.properties = {...v.properties, ...option.properties}

Check failure on line 241 in src/includer/traverse/tables.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`
}
delete v.oneOf;
}
return v;
}

Expand Down

0 comments on commit 321767e

Please sign in to comment.