Skip to content

Commit dfd6d89

Browse files
committed
Fix simpleEnumValues error
Improve test type checking Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
1 parent 0126988 commit dfd6d89

21 files changed

+265
-107
lines changed

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

Lines changed: 6 additions & 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/oas_3_tools.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/oas_3_tools.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,14 @@ export function sanitize(str: string, caseStyle: CaseStyle): string {
11001100
* characters and preserves casing
11011101
*/
11021102
if (caseStyle === CaseStyle.simple) {
1103-
return str.replace(/[^a-zA-Z0-9_]/gi, '')
1103+
let sanitized = str.replace(/[^a-zA-Z0-9_]/gi, '')
1104+
1105+
// Special case: we cannot start with number, and cannot be empty:
1106+
if (/^[0-9]/.test(sanitized) || sanitized === '') {
1107+
sanitized = '_' + sanitized
1108+
}
1109+
1110+
return sanitized
11041111
}
11051112

11061113
/**

packages/openapi-to-graphql/test/authentication.test.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
'use strict'
77

8-
/* globals beforeAll, test, expect */
9-
108
import { graphql } from 'graphql'
9+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
1110

1211
import * as openAPIToGraphQL from '../lib/index'
1312
import { startServer, stopServer } from './example_api_server'
@@ -46,7 +45,7 @@ test('Get patent using basic auth', () => {
4645
}
4746
}
4847
}`
49-
return graphql(createdSchema, query, null, {}).then(result => {
48+
return graphql(createdSchema, query, null, {}).then((result) => {
5049
expect(result).toEqual({
5150
data: {
5251
viewerBasicAuth: {
@@ -67,7 +66,7 @@ test('Get patent using API key', () => {
6766
}
6867
}
6968
}`
70-
return graphql(createdSchema, query, null, {}).then(result => {
69+
return graphql(createdSchema, query, null, {}).then((result) => {
7170
expect(result).toEqual({
7271
data: {
7372
viewerApiKey2: {
@@ -88,7 +87,7 @@ test('Get patent using API key 3', () => {
8887
}
8988
}
9089
}`
91-
return graphql(createdSchema, query, null, {}).then(result => {
90+
return graphql(createdSchema, query, null, {}).then((result) => {
9291
expect(result).toEqual({
9392
data: {
9493
viewerApiKey3: {
@@ -110,7 +109,7 @@ test('Get project using API key 1', () => {
110109
}
111110
}
112111
}`
113-
return graphql(createdSchema, query, null, {}).then(result => {
112+
return graphql(createdSchema, query, null, {}).then((result) => {
114113
expect(result).toEqual({
115114
data: {
116115
viewerApiKey: {
@@ -136,7 +135,7 @@ test('Get project using API key passed as option - viewer is disabled', async ()
136135
projectId
137136
}
138137
}`
139-
return graphql(schema, query, null, {}).then(result => {
138+
return graphql(schema, query, null, {}).then((result) => {
140139
expect(result).toEqual({
141140
data: {
142141
projectWithId: {
@@ -162,7 +161,7 @@ test('Get project using API key passed in the requestOptions - viewer is disable
162161
projectId
163162
}
164163
}`
165-
return graphql(schema, query, null, {}).then(result => {
164+
return graphql(schema, query, null, {}).then((result) => {
166165
expect(result).toEqual({
167166
data: {
168167
projectWithId: {
@@ -181,7 +180,7 @@ test('Get project using API key 2', () => {
181180
}
182181
}
183182
}`
184-
return graphql(createdSchema, query, null, {}).then(result => {
183+
return graphql(createdSchema, query, null, {}).then((result) => {
185184
expect(result).toEqual({
186185
data: {
187186
viewerApiKey2: {
@@ -207,7 +206,7 @@ test('Post project using API key 1', () => {
207206
}
208207
}
209208
}`
210-
return graphql(createdSchema, query, null, {}).then(result => {
209+
return graphql(createdSchema, query, null, {}).then((result) => {
211210
expect(result).toEqual({
212211
data: {
213212
mutationViewerApiKey: {
@@ -235,7 +234,7 @@ test('Post project using API key 2', () => {
235234
}
236235
}
237236
}`
238-
return graphql(createdSchema, query, null, {}).then(result => {
237+
return graphql(createdSchema, query, null, {}).then((result) => {
239238
expect(result).toEqual({
240239
data: {
241240
mutationViewerApiKey2: {
@@ -258,7 +257,7 @@ test('Get project using API key 3', async () => {
258257
}
259258
}
260259
}`
261-
return graphql(createdSchema, query, null, {}).then(result => {
260+
return graphql(createdSchema, query, null, {}).then((result) => {
262261
expect(result).toEqual({
263262
data: {
264263
viewerApiKey3: {
@@ -283,7 +282,7 @@ test('Get project using API key 3 passed as option - viewer is disabled', async
283282
projectId
284283
}
285284
}`
286-
return graphql(schema, query, null, {}).then(result => {
285+
return graphql(schema, query, null, {}).then((result) => {
287286
expect(result).toEqual({
288287
data: {
289288
projectWithId: {
@@ -309,7 +308,7 @@ test('Get project using API key 3 passed in the requestOptions - viewer is disab
309308
projectId
310309
}
311310
}`
312-
return graphql(schema, query, null, {}).then(result => {
311+
return graphql(schema, query, null, {}).then((result) => {
313312
expect(result).toEqual({
314313
data: {
315314
projectWithId: {
@@ -328,7 +327,7 @@ test('Basic AnyAuth usage', () => {
328327
}
329328
}
330329
}`
331-
return graphql(createdSchema, query, null, {}).then(result => {
330+
return graphql(createdSchema, query, null, {}).then((result) => {
332331
expect(result).toEqual({
333332
data: {
334333
viewerAnyAuth: {
@@ -349,7 +348,7 @@ test('Basic AnyAuth usage with extraneous auth data', () => {
349348
}
350349
}
351350
}`
352-
return graphql(createdSchema, query, null, {}).then(result => {
351+
return graphql(createdSchema, query, null, {}).then((result) => {
353352
expect(result).toEqual({
354353
data: {
355354
viewerAnyAuth: {
@@ -373,7 +372,7 @@ test('Basic AnyAuth usage with multiple operations', () => {
373372
}
374373
}
375374
}`
376-
return graphql(createdSchema, query, null, {}).then(result => {
375+
return graphql(createdSchema, query, null, {}).then((result) => {
377376
expect(result).toEqual({
378377
data: {
379378
viewerAnyAuth: {
@@ -400,7 +399,7 @@ test('AnyAuth with multiple operations with different auth requirements', () =>
400399
}
401400
}
402401
}`
403-
return graphql(createdSchema, query, null, {}).then(result => {
402+
return graphql(createdSchema, query, null, {}).then((result) => {
404403
expect(result).toEqual({
405404
data: {
406405
viewerAnyAuth: {
@@ -432,7 +431,7 @@ test('AnyAuth with multiple operations with different auth requirements in a lin
432431
}
433432
}
434433
}`
435-
return graphql(createdSchema, query, null, {}).then(result => {
434+
return graphql(createdSchema, query, null, {}).then((result) => {
436435
expect(result).toEqual({
437436
data: {
438437
viewerAnyAuth: {
@@ -464,7 +463,7 @@ test('Extract token from context', () => {
464463
})
465464
.then(({ schema }) => {
466465
return graphql(schema, query, null, { user: { token: 'abcdef' } }).then(
467-
result => {
466+
(result) => {
468467
expect(result).toEqual({
469468
data: {
470469
secure: 'A secure message.'

packages/openapi-to-graphql/test/cloudfunction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
'use strict'
77

8-
/* globals beforeAll, test, expect */
8+
import { graphql, parse, validate } from 'graphql'
9+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
910

1011
import * as openAPIToGraphQL from '../lib/index'
11-
const { parse, validate } = require('graphql')
1212

1313
const oas = require('./fixtures/cloudfunction.json')
1414

packages/openapi-to-graphql/test/docusign.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
'use strict'
77

8-
/* globals test, expect */
8+
import { graphql } from 'graphql'
9+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
910

1011
import * as openAPIToGraphQL from '../lib/index'
1112
import { Options } from '../lib/types/options'

packages/openapi-to-graphql/test/example_api.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
'use strict'
77

8-
/* globals beforeAll, test, expect */
9-
108
import { graphql, parse, validate } from 'graphql'
9+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
1110

1211
import * as openAPIToGraphQL from '../lib/index'
1312
import { Options } from '../lib/types/options'

packages/openapi-to-graphql/test/example_api2.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
'use strict'
77

8-
/* globals beforeAll, test, expect */
9-
108
import { graphql } from 'graphql'
9+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
1110

1211
import * as openAPIToGraphQL from '../lib/index'
1312
import { startServer, stopServer } from './example_api2_server'
@@ -76,7 +75,7 @@ test('Querying the two operations', () => {
7675
name
7776
}
7877
}`
79-
return graphql(createdSchema, query).then(result => {
78+
return graphql(createdSchema, query).then((result) => {
8079
expect(result).toEqual({
8180
data: {
8281
getUser: {

packages/openapi-to-graphql/test/example_api3.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
'use strict'
77

8-
/* globals beforeAll, test, expect */
8+
import { graphql, parse, validate } from 'graphql'
9+
import { afterAll, beforeAll, expect, test } from '@jest/globals'
910

1011
import * as openAPIToGraphQL from '../lib/index'
1112
import { Options } from '../lib/types/options'
12-
import { graphql, parse, validate } from 'graphql'
1313

1414
const api = require('./example_api_server')
1515
const api2 = require('./example_api3_server')
@@ -63,7 +63,7 @@ test('Basic query on two APIs', () => {
6363
name
6464
}
6565
}`
66-
return graphql(createdSchema, query).then(result => {
66+
return graphql(createdSchema, query).then((result) => {
6767
expect(result).toEqual({
6868
data: {
6969
author: {
@@ -108,7 +108,7 @@ test('Two APIs with independent links', () => {
108108
}
109109
}
110110
}`
111-
return graphql(createdSchema, query).then(result => {
111+
return graphql(createdSchema, query).then((result) => {
112112
expect(result).toEqual({
113113
data: {
114114
author: {
@@ -165,7 +165,7 @@ test('Two APIs with interrelated links', () => {
165165
}
166166
}
167167
}`
168-
return graphql(createdSchema, query).then(result => {
168+
return graphql(createdSchema, query).then((result) => {
169169
expect(result).toEqual({
170170
data: {
171171
author: {
@@ -210,7 +210,7 @@ test('Two APIs with viewers', () => {
210210
}
211211
}
212212
}`
213-
return graphql(createdSchema, query).then(result => {
213+
return graphql(createdSchema, query).then((result) => {
214214
expect(result).toEqual({
215215
data: {
216216
viewerApiKey: {
@@ -244,7 +244,7 @@ test('Two APIs with AnyAuth viewer', () => {
244244
}
245245
}
246246
}`
247-
return graphql(createdSchema, query).then(result => {
247+
return graphql(createdSchema, query).then((result) => {
248248
expect(result).toEqual({
249249
data: {
250250
viewerAnyAuth: {
@@ -278,7 +278,7 @@ test('Two APIs with AnyAuth viewer and interrelated links', () => {
278278
}
279279
}
280280
}`
281-
return graphql(createdSchema, query).then(result => {
281+
return graphql(createdSchema, query).then((result) => {
282282
expect(result).toEqual({
283283
data: {
284284
viewerAnyAuth: {
@@ -336,7 +336,7 @@ test('Option customResolver with two APIs', () => {
336336
const ast = parse(query)
337337
const errors = validate(schema, ast)
338338
expect(errors).toEqual([])
339-
return graphql(schema, query).then(result => {
339+
return graphql(schema, query).then((result) => {
340340
expect(result).toEqual({
341341
data: {
342342
user: {
@@ -413,7 +413,7 @@ test('Option customResolver with two APIs and interrelated links', () => {
413413
const ast = parse(query)
414414
const errors = validate(schema, ast)
415415
expect(errors).toEqual([])
416-
return graphql(schema, query).then(result => {
416+
return graphql(schema, query).then((result) => {
417417
expect(result).toEqual({
418418
data: {
419419
author: {

0 commit comments

Comments
 (0)