Skip to content

Commit 6609c3c

Browse files
Alan-ChaErikWittern
authored andcommitted
Support content property in parameter objects
Fix #153 Signed-off-by: Alan Cha <[email protected]>
1 parent 1f2b143 commit 6609c3c

15 files changed

+241
-121
lines changed

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/resolver_builder.js

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/resolver_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/schema_builder.js

Lines changed: 31 additions & 15 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export declare const mitigations: {
1616
DUPLICATE_LINK_KEY: string;
1717
UNRESOLVABLE_REFERENCE: string;
1818
UNSUPPORTED_HTTP_SECURITY_SCHEME: string;
19+
NON_APPLICATION_JSON_SCHEMA: string;
1920
UNRESOLVABLE_LINK: string;
2021
AMBIGUOUS_LINK: string;
2122
LINK_NAME_COLLISION: string;

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

Lines changed: 1 addition & 0 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/resolver_builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ export function getResolver({
324324
httpLog(
325325
`Call ${options.method.toUpperCase()} ${
326326
options.url
327-
}?${querystring.stringify(options.qs)}` +
327+
}?${querystring.stringify(options.qs)}\n` +
328328
`headers:${JSON.stringify(options.headers)}`
329329
)
330+
330331
return new Promise((resolve, reject) => {
331332
NodeRequest(options, (err, response, body) => {
332333
if (err) {

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

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -869,30 +869,28 @@ export function getArgs({
869869
* or the "content" field (but not both)
870870
*/
871871
let type: GraphQLType
872+
let schema: SchemaObject | ReferenceObject
872873
if (typeof parameter.schema === 'object') {
873-
let schema = parameter.schema
874-
if ('$ref' in parameter.schema) {
875-
schema = Oas3Tools.resolveRef(parameter.schema['$ref'], operation.oas)
876-
}
877-
878-
// TODO: remove
879-
const paramDef = createDataDef(
880-
{ fromRef: parameter.name },
881-
schema as SchemaObject,
882-
true,
883-
data
884-
)
885-
886-
// @ts-ignore
887-
type = getGraphQLType({
888-
def: paramDef,
889-
operation,
890-
data,
891-
iteration: 0,
892-
isMutation: true
893-
})
874+
schema = parameter.schema
894875
} else if (typeof parameter.content === 'object') {
895-
// TODO
876+
if (
877+
typeof parameter.content['application/json'] === 'object' &&
878+
typeof parameter.content['application/json'].schema === 'object'
879+
) {
880+
schema = parameter.content['application/json'].schema
881+
} else {
882+
handleWarning({
883+
typeKey: 'NON_APPLICATION_JSON_SCHEMA',
884+
message:
885+
`The operation '${operationString}' contains a ` +
886+
`parameter '${JSON.stringify(parameter)}' that has a 'content' ` +
887+
`property but no schemas in application/json format. The ` +
888+
`parameter will not be created`,
889+
data,
890+
log: translationLog
891+
})
892+
continue
893+
}
896894
} else {
897895
// Invalid OAS according to 3.0.2
898896
handleWarning({
@@ -907,6 +905,27 @@ export function getArgs({
907905
continue
908906
}
909907

908+
if ('$ref' in schema) {
909+
schema = Oas3Tools.resolveRef(schema['$ref'], operation.oas)
910+
}
911+
912+
// TODO: remove
913+
const paramDef = createDataDef(
914+
{ fromRef: parameter.name },
915+
schema as SchemaObject,
916+
true,
917+
data
918+
)
919+
920+
// @ts-ignore
921+
type = getGraphQLType({
922+
def: paramDef,
923+
operation,
924+
data,
925+
iteration: 0,
926+
isMutation: true
927+
})
928+
910929
/**
911930
* Sanitize the argument name
912931
*

0 commit comments

Comments
 (0)