Skip to content

Commit 1c4429c

Browse files
Alan-ChaErikWittern
authored andcommitted
More fixes
Signed-off-by: Alan Cha <[email protected]>
1 parent aeca460 commit 1c4429c

File tree

10 files changed

+77
-154
lines changed

10 files changed

+77
-154
lines changed

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

Lines changed: 18 additions & 18 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: 0 additions & 35 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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ export declare const mitigations: {
77
*/
88
INVALID_OAS: string;
99
UNNAMED_PARAMETER: string;
10-
MULTIPLE_RESPONSES: string;
11-
MISSING_RESPONSE_SCHEMA: string;
10+
AMBIGUOUS_UNION_MEMBERS: string;
11+
CANNOT_GET_FIELD_TYPE: string;
12+
COMBINE_SCHEMAS: string;
1213
DUPLICATE_FIELD_NAME: string;
1314
DUPLICATE_LINK_KEY: string;
14-
UNSUPPORTED_HTTP_SECURITY_SCHEME: string;
15+
MISSING_RESPONSE_SCHEMA: string;
16+
MISSING_SCHEMA: string;
17+
MULTIPLE_RESPONSES: string;
1518
NON_APPLICATION_JSON_SCHEMA: string;
1619
OBJECT_MISSING_PROPERTIES: string;
17-
UNSUPPORTED_JSON_SCHEMA_KEYWORD: string;
18-
AMBIGUOUS_UNION_MEMBERS: string;
19-
CANNOT_GET_FIELD_TYPE: string;
20-
COMBINE_SCHEMAS: string;
2120
UNKNOWN_TARGET_TYPE: string;
22-
MISSING_SCHEMA: string;
2321
UNRESOLVABLE_SCHEMA: string;
24-
UNRESOLVABLE_LINK: string;
22+
UNSUPPORTED_HTTP_SECURITY_SCHEME: string;
23+
UNSUPPORTED_JSON_SCHEMA_KEYWORD: string;
2524
AMBIGUOUS_LINK: string;
2625
LINK_NAME_COLLISION: string;
27-
MULTIPLE_OAS_SAME_TITLE: string;
26+
UNRESOLVABLE_LINK: string;
2827
DUPLICATE_OPERATIONID: string;
2928
DUPLICATE_SECURITY_SCHEME: string;
29+
MULTIPLE_OAS_SAME_TITLE: string;
3030
CUSTOM_RESOLVER_UNKNOWN_OAS: string;
3131
CUSTOM_RESOLVER_UNKNOWN_PATH_METHOD: string;
3232
LIMIT_ARGUMENT_NAME_COLLISION: string;

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

Lines changed: 10 additions & 10 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: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ export function preprocessOas(
223223
oas
224224
}
225225

226-
// Handle operationId property name collision // May occur if multiple OAS are provided
226+
/**
227+
* Handle operationId property name collision
228+
* May occur if multiple OAS are provided
229+
*/
227230
if (operationId in data.operations) {
228231
handleWarning({
229232
typeKey: 'DUPLICATE_OPERATIONID',
@@ -291,7 +294,7 @@ function getProcessedSecuritySchemes(
291294
for (let key in security) {
292295
const protocol = security[key]
293296

294-
// Determine the parameters and the schema for the security protocol
297+
// Determine the schema and the parameters for the security protocol
295298
let schema
296299
let parameters = {}
297300
let description
@@ -368,6 +371,7 @@ function getProcessedSecuritySchemes(
368371
}
369372
break
370373

374+
// TODO: Implement
371375
case 'openIdConnect':
372376
handleWarning({
373377
typeKey: 'UNSUPPORTED_HTTP_SECURITY_SCHEME',
@@ -378,7 +382,6 @@ function getProcessedSecuritySchemes(
378382
log: preprocessingLog
379383
})
380384

381-
// TODO: Implement
382385
break
383386

384387
case 'oauth2':
@@ -969,14 +972,14 @@ export function createDataDef(
969972
oas
970973
)
971974
} else {
972-
// handleWarning({
973-
// typeKey: 'UNKNOWN_TARGET_TYPE',
974-
// message: `No GraphQL target type could be identified for schema '${JSON.stringify(
975-
// schema
976-
// )}'.`,
977-
// data,
978-
// log: preprocessingLog
979-
// })
975+
handleWarning({
976+
typeKey: 'OBJECT_MISSING_PROPERTIES',
977+
message:
978+
`Schema ${JSON.stringify(schema)} does not have ` +
979+
`any properties`,
980+
data,
981+
log: preprocessingLog
982+
})
980983

981984
def.targetGraphQLType = 'json'
982985
}
@@ -1042,21 +1045,17 @@ function getSchemaIndex(
10421045
* been taken.
10431046
*/
10441047
function getPreferredName(names: Oas3Tools.SchemaNames): string {
1045-
let schemaName // CASE: preferred name already known
1046-
10471048
if (typeof names.preferred === 'string') {
1048-
schemaName = names.preferred // CASE: name from reference
1049+
return Oas3Tools.sanitize(names.preferred, Oas3Tools.CaseStyle.PascalCase) // CASE: preferred name already known
10491050
} else if (typeof names.fromRef === 'string') {
1050-
schemaName = names.fromRef // CASE: name from schema (i.e., "title" property in schema)
1051+
return Oas3Tools.sanitize(names.fromRef, Oas3Tools.CaseStyle.PascalCase) // CASE: name from reference
10511052
} else if (typeof names.fromSchema === 'string') {
1052-
schemaName = names.fromSchema // CASE: name from path
1053+
return Oas3Tools.sanitize(names.fromSchema, Oas3Tools.CaseStyle.PascalCase) // CASE: name from schema (i.e., "title" property in schema)
10531054
} else if (typeof names.fromPath === 'string') {
1054-
schemaName = names.fromPath // CASE: placeholder name
1055+
return Oas3Tools.sanitize(names.fromPath, Oas3Tools.CaseStyle.PascalCase) // CASE: name from path
10551056
} else {
1056-
schemaName = 'PlaceholderName'
1057+
return 'PlaceholderName' // CASE: placeholder name
10571058
}
1058-
1059-
return Oas3Tools.sanitize(schemaName, Oas3Tools.CaseStyle.camelCase)
10601059
}
10611060

10621061
/**

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

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,6 @@ export function getGraphQLType({
111111
isInputObjectType
112112
})
113113

114-
// CASE: combine schemas
115-
case 'combination':
116-
// TODO: currently assuming that the combined schema is an object type
117-
return createOrReuseOt({
118-
def,
119-
operation,
120-
data,
121-
iteration,
122-
isInputObjectType
123-
})
124-
125114
// CASE: union - create UnionType
126115
case 'union':
127116
return createOrReuseUnion({
@@ -220,36 +209,6 @@ function createOrReuseOt({
220209
const schema = def.schema
221210
const description = schema.description
222211

223-
/**
224-
* If the schema does not contain any properties, then OpenAPI-to-GraphQL
225-
* cannot create a GraphQL object type for it because in GraphQL, all object
226-
* type properties must be named.
227-
*
228-
* Instead, store response in an arbitray JSON type.
229-
*/
230-
if (
231-
(typeof def.schema.properties === 'undefined' ||
232-
Object.keys(def.schema.properties).length === 0) && // Empty object
233-
typeof def.schema.allOf === 'undefined' &&
234-
typeof def.schema.oneOf === 'undefined' &&
235-
typeof def.schema.anyOf === 'undefined'
236-
) {
237-
handleWarning({
238-
typeKey: 'OBJECT_MISSING_PROPERTIES',
239-
message:
240-
`The operation ` +
241-
`'${operation.operationString}' contains ` +
242-
`an object schema ${JSON.stringify(schema)} with no properties. ` +
243-
`GraphQL objects must have well-defined properties so a one to ` +
244-
`one conversion cannot be achieved.`,
245-
data,
246-
log: translationLog
247-
})
248-
249-
def.graphQLType = GraphQLJSON
250-
return def.graphQLType
251-
}
252-
253212
// CASE: query - create object type
254213
if (!isInputObjectType) {
255214
translationLog(
@@ -1227,13 +1186,13 @@ export function getArgs({
12271186
})
12281187

12291188
// Sanitize the argument name
1230-
const saneName = data.options.genericPayloadArgName ?
1231-
'requestBody' :
1232-
Oas3Tools.sanitize(
1233-
requestPayloadDef.graphQLInputObjectTypeName,
1234-
Oas3Tools.CaseStyle.camelCase
1235-
)
1236-
1189+
const saneName = data.options.genericPayloadArgName
1190+
? 'requestBody'
1191+
: Oas3Tools.sanitize(
1192+
requestPayloadDef.graphQLInputObjectTypeName,
1193+
Oas3Tools.CaseStyle.camelCase
1194+
)
1195+
12371196
const reqRequired =
12381197
typeof operation === 'object' &&
12391198
typeof operation.payloadRequired === 'boolean'

0 commit comments

Comments
 (0)