Skip to content

Commit c473524

Browse files
committed
Generate unions from oneOf return type
Signed-off-by: Florian Tatzky <[email protected]>
1 parent 1e845bf commit c473524

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/openapi-to-graphql/src/oas_3_tools.ts

+7
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,13 @@ export function getSchemaTargetGraphQLType<TSource, TContext, TArgs>(
406406
schema: SchemaObject,
407407
data: PreprocessingData<TSource, TContext, TArgs>
408408
): string | null {
409+
if (schema.oneOf) {
410+
return 'union'
411+
}
412+
413+
if (schema.allOf) {
414+
return 'object'
415+
}
409416
// CASE: object
410417
if (schema.type === 'object' || typeof schema.properties === 'object') {
411418
// TODO: additionalProperties is more like a flag than a type itself

packages/openapi-to-graphql/src/preprocessor.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1504,14 +1504,10 @@ function createDataDefFromOneOf<TSource, TContext, TArgs>(
15041504
if (
15051505
oneOfData.allTargetGraphQLTypes.every(memberTargetGraphQLType => {
15061506
return memberTargetGraphQLType === 'object'
1507-
}) &&
1508-
oneOfData.allProperties.length > 0 // Redundant check
1507+
})
15091508
) {
15101509
// Ensure that parent schema is compatiable with oneOf
1511-
if (
1512-
def.targetGraphQLType === null ||
1513-
def.targetGraphQLType === 'object'
1514-
) {
1510+
if (def.targetGraphQLType === 'union') {
15151511
def.subDefinitions = []
15161512

15171513
collapsedSchema.oneOf.forEach(memberSchema => {

0 commit comments

Comments
 (0)