Skip to content

Commit cc0f9d5

Browse files
committed
fixes
Signed-off-by: Dotan Simha <[email protected]>
1 parent 97e37f7 commit cc0f9d5

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { sortObject, handleWarning } from './utils'
5454
type Result = {
5555
schema: GraphQLSchema
5656
report: Report
57+
data: PreprocessingData
5758
}
5859

5960
const translationLog = debug('translation')
@@ -140,13 +141,14 @@ export async function createGraphQLSchema(
140141
oass = [await Oas3Tools.getValidOAS3(spec)]
141142
}
142143

143-
const { schema, report } = await translateOpenAPIToGraphQL(
144+
const { schema, report, data } = await translateOpenAPIToGraphQL(
144145
oass,
145146
options as InternalOptions
146147
)
147148
return {
148149
schema,
149-
report
150+
report,
151+
data
150152
}
151153
}
152154

@@ -185,7 +187,7 @@ async function translateOpenAPIToGraphQL(
185187
provideErrorExtensions,
186188
equivalentToMessages
187189
}: InternalOptions
188-
): Promise<{ schema: GraphQLSchema; report: Report }> {
190+
): Promise<{ schema: GraphQLSchema; report: Report; data: PreprocessingData }> {
189191
const options = {
190192
strict,
191193
report,
@@ -476,7 +478,7 @@ async function translateOpenAPIToGraphQL(
476478

477479
const schema = new GraphQLSchema(schemaConfig)
478480

479-
return { schema, report: options.report }
481+
return { schema, report: options.report, data }
480482
}
481483

482484
/**

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OperationObject } from './types/oas3'
12
// Copyright IBM Corp. 2018. All Rights Reserved.
23
// Node module: openapi-to-graphql
34
// This file is licensed under the MIT License.
@@ -77,7 +78,7 @@ export function preprocessOas(
7778
continue
7879
}
7980

80-
const endpoint = oas.paths[path][method]
81+
const endpoint: OperationObject = oas.paths[path][method]
8182
const operationString =
8283
oass.length === 1
8384
? Oas3Tools.formatOperationString(method, path)
@@ -92,6 +93,9 @@ export function preprocessOas(
9293
description = endpoint.summary
9394
}
9495

96+
// Determine tags
97+
const tags = endpoint.tags || []
98+
9599
if (data.options.equivalentToMessages) {
96100
// Description may not exist
97101
if (typeof description !== 'string') {
@@ -206,6 +210,8 @@ export function preprocessOas(
206210

207211
// Store determined information for operation
208212
const operation: Operation = {
213+
object: endpoint,
214+
tags,
209215
operationId,
210216
operationString,
211217
description,
@@ -1045,7 +1051,7 @@ function resolveAllOf(
10451051

10461052
type MemberSchemaData = {
10471053
allTargetGraphQLTypes: string[]
1048-
allProperties: ({ [key: string]: SchemaObject | ReferenceObject })[]
1054+
allProperties: { [key: string]: SchemaObject | ReferenceObject }[]
10491055
allRequired: string[]
10501056
}
10511057

@@ -1207,11 +1213,11 @@ function createDataDefFromAnyOf(
12071213
Object.keys(properties).forEach(propertyName => {
12081214
if (
12091215
!incompatibleProperties.has(propertyName) && // Has not been already identified as a problematic property
1210-
(typeof allProperties[propertyName] === 'object' &&
1216+
typeof allProperties[propertyName] === 'object' &&
12111217
allProperties[propertyName].some(property => {
12121218
// Property does not match a recorded one
12131219
return !deepEqual(property, properties[propertyName])
1214-
}))
1220+
})
12151221
) {
12161222
incompatibleProperties.add(propertyName)
12171223
}

packages/openapi-to-graphql/src/types/operation.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OperationObject } from './oas3'
12
// Copyright IBM Corp. 2018. All Rights Reserved.
23
// Node module: openapi-to-graphql
34
// This file is licensed under the MIT License.
@@ -93,6 +94,11 @@ export type Operation = {
9394
*/
9495
operationId: string
9596

97+
/**
98+
* The raw operation object from the OAS spec
99+
*/
100+
object: OperationObject
101+
96102
/**
97103
* A combination of the operation method and path (and the title of the OAS
98104
* where the operation originates from if multiple OASs are provided) in the
@@ -114,6 +120,11 @@ export type Operation = {
114120
*/
115121
path: string
116122

123+
/**
124+
* Tags from the original OAS
125+
*/
126+
tags: string[]
127+
117128
/**
118129
* HTTP method for this operation
119130
*/

0 commit comments

Comments
 (0)