Skip to content

Commit 4f3d8cb

Browse files
committed
Fail softly with invalid HTTP methods
Signed-off-by: Alan Cha <[email protected]>
1 parent e5ea096 commit 4f3d8cb

10 files changed

+39
-14
lines changed

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

+1-1
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

+14-2
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

+1-1
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

+1-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export declare enum MitigationTypes {
1212
COMBINE_SCHEMAS = "COMBINE_SCHEMAS",
1313
DUPLICATE_FIELD_NAME = "DUPLICATE_FIELD_NAME",
1414
DUPLICATE_LINK_KEY = "DUPLICATE_LINK_KEY",
15+
INVALID_HTTP_METHOD = "INVALID_HTTP_METHOD",
1516
INPUT_UNION = "INPUT_UNION",
1617
MISSING_RESPONSE_SCHEMA = "MISSING_RESPONSE_SCHEMA",
1718
MISSING_SCHEMA = "MISSING_SCHEMA",

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

+2
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

+1-1
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

+16-6
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,14 @@ export function preprocessOas<TSource, TContext, TArgs>(
263263
try {
264264
httpMethod = methodToHttpMethod(rawMethod)
265265
} catch (e) {
266-
throw new Error(
267-
`Invalid HTTP method '${rawMethod}' in operation '${operationString}'`
268-
)
266+
handleWarning({
267+
mitigationType: MitigationTypes.INVALID_HTTP_METHOD,
268+
message: `Invalid HTTP method '${rawMethod}' in operation '${operationString}'`,
269+
data,
270+
log: preprocessingLog
271+
})
272+
273+
return
269274
}
270275

271276
const operation = pathItem[httpMethod] as OperationObject
@@ -395,9 +400,14 @@ export function preprocessOas<TSource, TContext, TArgs>(
395400
callbackRawMethod
396401
)
397402
} catch (e) {
398-
throw new Error(
399-
`Invalid HTTP method '${rawMethod}' in callback '${callbackOperationString}' in operation '${operationString}'`
400-
)
403+
handleWarning({
404+
mitigationType: MitigationTypes.INVALID_HTTP_METHOD,
405+
message: `Invalid HTTP method '${rawMethod}' in callback '${callbackOperationString}' in operation '${operationString}'`,
406+
data,
407+
log: preprocessingLog
408+
})
409+
410+
return
401411
}
402412

403413
const callbackOperation = processOperation(

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

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum MitigationTypes {
2121
COMBINE_SCHEMAS = 'COMBINE_SCHEMAS',
2222
DUPLICATE_FIELD_NAME = 'DUPLICATE_FIELD_NAME',
2323
DUPLICATE_LINK_KEY = 'DUPLICATE_LINK_KEY',
24+
INVALID_HTTP_METHOD = 'INVALID_HTTP_METHOD',
2425
INPUT_UNION = 'INPUT_UNION',
2526
MISSING_RESPONSE_SCHEMA = 'MISSING_RESPONSE_SCHEMA',
2627
MISSING_SCHEMA = 'MISSING_SCHEMA',
@@ -68,6 +69,7 @@ export const mitigations: { [mitigationType in MitigationTypes]: string } = {
6869
DUPLICATE_FIELD_NAME: 'Ignore field and maintain preexisting field.',
6970
DUPLICATE_LINK_KEY: 'Ignore link and maintain preexisting link.',
7071
INPUT_UNION: 'The data will be stored in an arbitrary JSON type.',
72+
INVALID_HTTP_METHOD: 'Ignore operation and continue.',
7173
MISSING_RESPONSE_SCHEMA: 'Ignore operation.',
7274
MISSING_SCHEMA: 'Use arbitrary JSON type.',
7375
MULTIPLE_RESPONSES:

packages/openapi-to-graphql/test/example_api6_server.js

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
'use strict'
77

8-
const { send } = require('process')
9-
108
let server // holds server object for shutdown
119

1210
/**

0 commit comments

Comments
 (0)