Skip to content

Commit 185cb34

Browse files
Alan-ChaErikWittern
authored andcommitted
Improve error handling
Mention keywords for combining schema Signed-off-by: Alan Cha <[email protected]>
1 parent fc97761 commit 185cb34

File tree

10 files changed

+40
-49
lines changed

10 files changed

+40
-49
lines changed

packages/openapi-to-graphql/lib/preprocessor.js

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/preprocessor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/schema_builder.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/schema_builder.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/utils.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export declare const mitigations: {
66
* Should be caught by the module oas-validator
77
*/
88
INVALID_OAS: string;
9-
INVALID_SCHEMA_TYPE: string;
10-
INVALID_SCHEMA_TYPE_LIST_ITEM: string;
11-
INVALID_SCHEMA_TYPE_SCALAR: string;
129
UNNAMED_PARAMETER: string;
1310
MULTIPLE_RESPONSES: string;
1411
MISSING_RESPONSE_SCHEMA: string;

packages/openapi-to-graphql/lib/utils.js

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,24 @@ export function createDataDef(
415415
// Resolve allOf element in schema if applicable
416416
if ('allOf' in schema) {
417417
schema = mergeAllOf(schema)
418+
} else if ('anyOf' in schema) {
419+
throw new Error(
420+
`OpenAPI-to-GraphQL currently cannot handle 'anyOf' keyword in '${JSON.stringify(
421+
schema
422+
)}'`
423+
)
424+
} else if ('oneOf' in schema) {
425+
throw new Error(
426+
`OpenAPI-to-GraphQL currently cannot handle 'oneOf' keyword in '${JSON.stringify(
427+
schema
428+
)}'`
429+
)
430+
} else if ('not' in schema) {
431+
throw new Error(
432+
`OpenAPI-to-GraphQL currently cannot handle 'not' keyword in '${JSON.stringify(
433+
schema
434+
)}'`
435+
)
418436
}
419437

420438
const preferredName = getPreferredName(names)
@@ -486,17 +504,11 @@ export function createDataDef(
486504
// Determine the type of the schema
487505
const type = Oas3Tools.getSchemaType(schema as SchemaObject)
488506
if (!type) {
489-
// TODO: Throw error?
490-
handleWarning({
491-
typeKey: 'INVALID_SCHEMA_TYPE',
492-
message:
493-
`Request/response schema has no (valid) type ` +
494-
`'${JSON.stringify(schema)}'.`,
495-
data,
496-
log: preprocessingLog
497-
})
498-
499-
return null
507+
throw new Error(
508+
`Cannot process schema '${JSON.stringify(
509+
schema
510+
)}'. Cannot identify type of schema.`
511+
)
500512
} else {
501513
// Add the names to the master list
502514
data.usedOTNames.push(saneName)

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,8 @@ function reuseOrCreateList({
348348
}
349349
return listObjectType
350350
} else {
351-
handleWarning({
352-
typeKey: 'INVALID_SCHEMA_TYPE_LIST_ITEM',
353-
message:
354-
`List item '${itemsName}' in list '${name}' contains an ` +
355-
`invalid JSON schema '${JSON.stringify(itemsSchema)}'`,
356-
data,
357-
log: translationLog
358-
})
359-
return new GraphQLList(GraphQLString)
351+
throw new Error(`Cannot create list item object type '${itemsName}' in list
352+
'${name}' with schema '${JSON.stringify(itemsSchema)}'`)
360353
}
361354
}
362355

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export const mitigations = {
1313
* Should be caught by the module oas-validator
1414
*/
1515
INVALID_OAS: `Ignore issue and continue.`,
16-
INVALID_SCHEMA_TYPE: `Fall back to GraphQL string type and stringify returned data.`,
17-
INVALID_SCHEMA_TYPE_LIST_ITEM: `Fall back to GraphQL string type and stringify returned data.`,
18-
INVALID_SCHEMA_TYPE_SCALAR: `Fall back to GraphQL string type and stringify returned data.`,
1916
UNNAMED_PARAMETER: `Ignore parameter.`,
2017

2118
// General problems

0 commit comments

Comments
 (0)