Skip to content

Commit

Permalink
Add operationString field to Operation type
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
  • Loading branch information
Alan-Cha authored and ErikWittern committed Jul 17, 2019
1 parent f6f08a2 commit 47c6b47
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 94 deletions.
9 changes: 4 additions & 5 deletions packages/openapi-to-graphql/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/index.js.map

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions packages/openapi-to-graphql/lib/oas_3_tools.d.ts
Expand Up @@ -181,11 +181,6 @@ export declare function trim(str: string, length: number): string;
* method could point to other types of information (e.g., parameters, servers).
*/
export declare function isOperation(method: string): boolean;
/**
* Creates a string that describes an operation in the form:
* {name of OAS} {HTTP method in ALL_CAPS} {operation path}
*/
export declare function getOperationString(operation: Operation, oass: Oas3[]): string;
/**
* Formats a string that describes an operation in the form:
* {name of OAS} {HTTP method in ALL_CAPS} {operation path}
Expand Down
13 changes: 0 additions & 13 deletions packages/openapi-to-graphql/lib/oas_3_tools.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/oas_3_tools.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/openapi-to-graphql/lib/preprocessor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/preprocessor.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/openapi-to-graphql/lib/resolver_builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/resolver_builder.js.map

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions packages/openapi-to-graphql/lib/schema_builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/schema_builder.js.map

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/openapi-to-graphql/lib/types/operation.d.ts
Expand Up @@ -33,6 +33,16 @@ export declare type Operation = {
* Identifier of the operation - may be created by concatenating method & path
*/
operationId: string;
/**
* A combination of the operation method and path (and the title of the OAS
* where the operation originates from if multiple OASs are provided) in the
* form of:
*
* {title of OAS (if applicable)} {method in ALL_CAPS} {path}
*
* Used for documentation and logging
*/
operationString: string;
/**
* Human-readable description of the operation
*/
Expand Down
9 changes: 4 additions & 5 deletions packages/openapi-to-graphql/src/index.ts
Expand Up @@ -226,7 +226,6 @@ async function translateOpenApiToGraphQL(
.sort(([op1Id, op1], [op2Id, op2]) => sortOperations(op1, op2))
.forEach(([operationId, operation]) => {
translationLog(`Process operation '${operationId}'...`)
const operationString = Oas3Tools.getOperationString(operation, data.oass)

let field = getFieldForOperation(
operation,
Expand Down Expand Up @@ -264,7 +263,7 @@ async function translateOpenApiToGraphQL(
`'${fieldName}' and security requirement ` +
`'${securityRequirement}'. GraphQL field names must be ` +
`unique so only one can be added to the authentication ` +
`viewer. Operation '${operationString}' will be ignored.`,
`viewer. Operation '${operation.operationString}' will be ignored.`,
data,
log: translationLog
})
Expand Down Expand Up @@ -292,7 +291,7 @@ async function translateOpenApiToGraphQL(
`Multiple operations have the same name ` +
`'${fieldName}'. GraphQL field names must be ` +
`unique so only one can be added to the Query object. ` +
`Operation '${operationString}' will be ignored.`,
`Operation '${operation.operationString}' will be ignored.`,
data,
log: translationLog
})
Expand Down Expand Up @@ -323,7 +322,7 @@ async function translateOpenApiToGraphQL(
`'${saneFieldName}' and security requirement ` +
`'${securityRequirement}'. GraphQL field names must be ` +
`unique so only one can be added to the authentication ` +
`viewer. Operation '${operationString}' will be ignored.`,
`viewer. Operation '${operation.operationString}' will be ignored.`,
data,
log: translationLog
})
Expand All @@ -339,7 +338,7 @@ async function translateOpenApiToGraphQL(
`Multiple operations have the same name ` +
`'${saneFieldName}'. GraphQL field names must be ` +
`unique so only one can be added to the Mutation object. ` +
`Operation '${operationString}' will be ignored.`,
`Operation '${operation.operationString}' will be ignored.`,
data,
log: translationLog
})
Expand Down
16 changes: 0 additions & 16 deletions packages/openapi-to-graphql/src/oas_3_tools.ts
Expand Up @@ -1085,22 +1085,6 @@ export function isOperation(method: string): boolean {
return OAS_OPERATIONS.includes(method.toLowerCase())
}

/**
* Creates a string that describes an operation in the form:
* {name of OAS} {HTTP method in ALL_CAPS} {operation path}
*/
export function getOperationString(operation: Operation, oass: Oas3[]): string {
if (oass.length === 1) {
return formatOperationString(operation.method, operation.path)
} else {
return formatOperationString(
operation.method,
operation.path,
operation.oas.info.title
)
}
}

/**
* Formats a string that describes an operation in the form:
* {name of OAS} {HTTP method in ALL_CAPS} {operation path}
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-to-graphql/src/preprocessor.ts
Expand Up @@ -184,6 +184,7 @@ export function preprocessOas(
// Store determined information for operation
const operation: Operation = {
operationId,
operationString,
description,
path,
method: method.toLowerCase(),
Expand Down
19 changes: 4 additions & 15 deletions packages/openapi-to-graphql/src/resolver_builder.ts
Expand Up @@ -74,12 +74,7 @@ export function getResolver({
typeof customResolvers[title][path] === 'object' &&
typeof customResolvers[title][path][method] === 'function'
) {
translationLog(
`Use custom resolver for ${Oas3Tools.getOperationString(
operation,
data.oass
)}`
)
translationLog(`Use custom resolver for ${operation.operationString}`)

return customResolvers[title][path][method]
}
Expand Down Expand Up @@ -335,10 +330,7 @@ export function getResolver({
} else if (response.statusCode < 200 || response.statusCode > 299) {
httpLog(`${response.statusCode} - ${Oas3Tools.trim(body, 100)}`)

const errorString = `Could not invoke operation ${Oas3Tools.getOperationString(
operation,
data.oass
)}`
const errorString = `Could not invoke operation ${operation.operationString}`

if (data.options.provideErrorExtensions) {
let responseBody
Expand Down Expand Up @@ -386,7 +378,7 @@ export function getResolver({
) {
const errorString =
`Operation ` +
`${Oas3Tools.getOperationString(operation, data.oass)} ` +
`${operation.operationString} ` +
`should have a content-type '${operation.responseContentType}' ` +
`but has '${response.headers['content-type']}' instead`

Expand All @@ -408,10 +400,7 @@ export function getResolver({
} catch (e) {
const errorString =
`Cannot JSON parse response body of ` +
`operation ${Oas3Tools.getOperationString(
operation,
data.oass
)} ` +
`operation ${operation.operationString} ` +
`even though it has content-type 'application/json'`

httpLog(errorString)
Expand Down

0 comments on commit 47c6b47

Please sign in to comment.