Skip to content

Commit e4d4a0d

Browse files
Alan-ChaErikWittern
authored andcommitted
Identify allOf
Fix #237 Signed-off-by: Alan Cha <[email protected]>
1 parent eeb4b64 commit e4d4a0d

File tree

7 files changed

+60
-15
lines changed

7 files changed

+60
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"test": "cd packages/openapi-to-graphql/ && npm test"
66
},
77
"devDependencies": {
8-
"@types/jest": "^24.0.16",
8+
"@types/jest": "^24.0.18",
99
"graphql": "^14.5.0",
1010
"jest": "^24.8.0",
1111
"lerna": "^3.4.3",

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

Lines changed: 7 additions & 5 deletions
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/lib/types/oas3.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare type ExternalDocumentationObject = {
88
export declare type SchemaObject = {
99
$ref?: string;
1010
title?: string;
11-
type: 'string' | 'number' | 'object' | 'array' | 'boolean' | 'integer';
11+
type?: 'string' | 'number' | 'object' | 'array' | 'boolean' | 'integer';
1212
format?: string;
1313
nullable?: boolean;
1414
description?: string;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,12 @@ export function getSchemaType(
403403
schema: SchemaObject,
404404
data: PreprocessingData
405405
): string | null {
406-
// CASE: enum
407-
if (Array.isArray(schema.enum)) {
408-
return 'enum'
409-
}
410-
411406
// CASE: object
412-
if (schema.type === 'object' || 'properties' in schema) {
407+
if (
408+
schema.type === 'object' ||
409+
'properties' in schema ||
410+
Array.isArray(schema.allOf)
411+
) {
413412
// CASE: arbitrary JSON
414413
if (typeof schema.additionalProperties === 'object') {
415414
return 'json'
@@ -423,6 +422,11 @@ export function getSchemaType(
423422
return 'array'
424423
}
425424

425+
// CASE: enum
426+
if (Array.isArray(schema.enum)) {
427+
return 'enum'
428+
}
429+
426430
// CASE: a type is present
427431
if (typeof schema.type === 'string') {
428432
// Special edge cases involving the schema format

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ExternalDocumentationObject = {
1515
export type SchemaObject = {
1616
$ref?: string
1717
title?: string
18-
type: 'string' | 'number' | 'object' | 'array' | 'boolean' | 'integer'
18+
type?: 'string' | 'number' | 'object' | 'array' | 'boolean' | 'integer'
1919
format?: string
2020
nullable?: boolean
2121
description?: string

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,42 @@ test('Properly treat null values during sanitization', () => {
184184
})
185185
})
186186
})
187+
188+
test('Identify allOf as an object', () => {
189+
const schema = {
190+
allOf: [
191+
{
192+
$ref: '#/components/schemas/User'
193+
}
194+
]
195+
}
196+
197+
expect(
198+
Oas3Tools.getSchemaType(schema, {
199+
operations: {},
200+
usedOTNames: [],
201+
defs: [],
202+
security: {},
203+
saneMap: {},
204+
options: {
205+
strict: false,
206+
report: {
207+
warnings: [],
208+
numOps: 0,
209+
numOpsQuery: 0,
210+
numOpsMutation: 0,
211+
numQueriesCreated: 0,
212+
numMutationsCreated: 0
213+
},
214+
operationIdFieldNames: false,
215+
fillEmptyResponses: false,
216+
addLimitArgument: false,
217+
viewer: true,
218+
sendOAuthTokenInQuery: false,
219+
provideErrorExtensions: true,
220+
equivalentToMessages: true
221+
},
222+
oass: []
223+
})
224+
).toEqual('object')
225+
})

0 commit comments

Comments
 (0)