Skip to content

Commit 54cd89a

Browse files
p787567ErikWittern
authored andcommitted
Added support for $ref in allOf
Signed-off-by: p787567 <[email protected]>
1 parent a33923f commit 54cd89a

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

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

Lines changed: 3 additions & 0 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/types/oas3.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export declare type SchemaObject = {
2121
items?: SchemaObject | ReferenceObject;
2222
additionalItems?: boolean | string[];
2323
enum?: string[];
24+
allOf?: object[];
2425
};
2526
export declare type ReferenceObject = {
2627
$ref: string;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ export function createDataDef(
415415

416416
// Resolve allOf element in schema if applicable
417417
if ('allOf' in schema) {
418+
schema.allOf = schema.allOf.map((entry: SchemaObject) => {
419+
return entry.$ref ? Oas3Tools.resolveRef(entry.$ref, oas) : entry
420+
})
418421
schema = mergeAllOf(schema)
419422
} else if ('anyOf' in schema) {
420423
throw new Error(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type SchemaObject = {
2828
items?: SchemaObject | ReferenceObject // MUST be a single schema object in OAS, see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#properties
2929
additionalItems?: boolean | string[]
3030
enum?: string[]
31+
allOf?: object[]
3132
}
3233

3334
export type ReferenceObject = {

packages/openapi-to-graphql/test/fixtures/example_oas.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,14 @@
11081108
},
11091109
"components": {
11101110
"schemas": {
1111+
"suborderObject": {
1112+
"type": "object",
1113+
"properties": {
1114+
"suborder": {
1115+
"type": "string"
1116+
}
1117+
}
1118+
},
11111119
"address": {
11121120
"type": "object",
11131121
"description": "The legal address of a user",
@@ -1332,11 +1340,7 @@
13321340
"type": "object",
13331341
"allOf": [
13341342
{
1335-
"properties": {
1336-
"suborder": {
1337-
"type": "string"
1338-
}
1339-
}
1343+
"$ref": "#/components/schemas/suborderObject"
13401344
},
13411345
{
13421346
"properties": {

0 commit comments

Comments
 (0)