Skip to content

Commit 0c01bf5

Browse files
Merge pull request #2 from peterhan92/fix-swagger-errors
fix swagger doc errors
2 parents 5127f12 + 409ff8b commit 0c01bf5

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

OpenApi.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ function buildScalarDefinition(node: any): any {
5656

5757
const scalarDoc: any = {
5858
type: scalarType,
59-
description: node.description,
6059
};
6160

61+
if (node.description) {
62+
scalarDoc.description = node.description;
63+
}
64+
6265
return scalarDoc;
6366
}
6467

@@ -68,11 +71,13 @@ function buildObjectDefinition(node: any): any {
6871
objectDoc.type = 'object';
6972
objectDoc.properties = {};
7073

71-
node.inputFields.forEach((field: any) => {
72-
const { type: fieldNode } = field;
74+
if (node.inputFields) {
75+
node.inputFields.forEach((field: any) => {
76+
const { type: fieldNode } = field;
7377

74-
objectDoc.properties[field.name] = buildDefinition(fieldNode);
75-
});
78+
objectDoc.properties[field.name] = buildDefinition(fieldNode);
79+
});
80+
}
7681

7782
return objectDoc;
7883
}
@@ -92,10 +97,13 @@ function buildDefinition(node: any): any {
9297
function buildEnumDefinition(node: any): any {
9398
const enumDoc: any = {
9499
type: 'string',
95-
description: node.description,
96100
enum: [],
97101
};
98102

103+
if (node.description) {
104+
enumDoc.description = node.description;
105+
}
106+
99107
node.enumValues.forEach((enumValue: any) => {
100108
enumDoc.enum.push(enumValue.name);
101109
});

describeRouteVariables.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@ import Route from './Route';
33

44
const TYPE_FRAGMENT = `
55
fragment TypeFragment on __Type {
6-
description
7-
kind
8-
name
9-
enumValues {
10-
name
11-
description
12-
}
6+
...InputField
137
inputFields {
148
name
159
type {
16-
kind
17-
name
18-
description
19-
enumValues {
10+
...InputField
11+
inputFields {
2012
name
21-
description
13+
type {
14+
...InputField
15+
}
2216
}
2317
}
2418
}
2519
}
20+
21+
fragment InputField on __Type {
22+
kind
23+
name
24+
description
25+
enumValues {
26+
name
27+
description
28+
}
29+
}
2630
`;
2731

2832
function buildQueryForVariable(variableName: string): string {

0 commit comments

Comments
 (0)