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: properties + oneOf #39

Merged
merged 1 commit into from
Feb 6, 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
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};
}
delete v.oneOf;
}
return v;
}

Expand Down
Loading