Skip to content

Commit ec6f12a

Browse files
aldeedoffbeatful
authored andcommitted
Several fixes and improvements (#7)
* feat: alphabetize definitions Signed-off-by: Eric Dobbertin <[email protected]> * fix: remove duplicate request body contents Signed-off-by: Eric Dobbertin <[email protected]> * feat: update to latest graphql-2-json-schema Adds rendering of built-in and custom scalars Signed-off-by: Eric Dobbertin <[email protected]> * fix: fix extra params being shown in some examples Signed-off-by: Eric Dobbertin <[email protected]> * fix: guard against undefined definitions Signed-off-by: Eric Dobbertin <[email protected]>
1 parent cf0e5c8 commit ec6f12a

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

app/dociql/generate-example.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
1616
const space = ' '.repeat(depth)
1717
var queryStr = space + field.name
1818

19+
// It's important to clone the array here. Otherwise we would
20+
// be pushing arguments into the array passed by reference,
21+
// which results in arguments from one query being incorrectly
22+
// shown on another query's example.
23+
const fieldArgs = [...arguments];
24+
1925
if (field.args.length > 0) {
20-
arguments.push(...field.args);
26+
fieldArgs.push(...field.args);
2127
const argsStr = field.args.map(arg => `${arg.name}: $${arg.name}`).join(', ');
2228
queryStr += `(${argsStr})`;
2329
}
@@ -31,7 +37,7 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
3137
if (!expandedField)
3238
return {
3339
query: "",
34-
args: arguments
40+
args: fieldArgs
3541
};
3642

3743
if (depth > 1) {
@@ -53,7 +59,7 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
5359
return generateQueryInternal(
5460
childFields[key],
5561
expandGraph,
56-
arguments,
62+
fieldArgs,
5763
depth + 1,
5864
typeCounts).query
5965
}).join("");
@@ -63,7 +69,7 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
6369

6470
return {
6571
query: queryStr + "\n",
66-
args: arguments
72+
args: fieldArgs
6773
};
6874
}
6975

@@ -106,7 +112,7 @@ function generateExampleSchema(name, type, expandGraph, depth) {
106112
if (type instanceof GraphQLNonNull)
107113
return generateExampleSchema(name, type.ofType, expandGraph, depth + 1);
108114
if (type instanceof GraphQLList) {
109-
var schema = generateExampleSchema(name, type.ofType, expandGraph, depth) // do not increment depth
115+
var schema = generateExampleSchema(name, type.ofType, expandGraph, depth) // do not increment depth
110116
return schema ? {
111117
type: 'array',
112118
items: schema

app/lib/preprocessor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ module.exports = function(options, specData) {
7777
var replaceRefs = require("./resolve-references").replaceRefs;
7878
replaceRefs(path.dirname(copy["x-spec-path"]), copy, copy, "")
7979

80+
if (copy.definitions) {
81+
var names = Object.keys(copy.definitions);
82+
names.sort();
83+
var sortedDefinitions = {};
84+
for (const name of names) {
85+
sortedDefinitions[name] = copy.definitions[name];
86+
}
87+
copy.definitions = sortedDefinitions;
88+
}
89+
8090
return copy;
8191
}
8292

app/views/partials/swagger/request-body.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{{else if schema.description}}
4141
{{md schema.description}}
4242
{{/if}}
43-
{{>json-schema/body schema}}
43+
{{!-- {{>json-schema/body schema}} --}}
4444
{{/if}}
4545
{{/with}}
4646
{{/if}}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"commander": "*",
4141
"foundation-sites": "^6.5.0-rc.4",
4242
"graphql": "^14.1.1",
43-
"graphql-2-json-schema": "^0.1.1",
43+
"graphql-2-json-schema": "^0.2.0",
4444
"graphql-json-schema": "^0.1.2",
4545
"grunt": "^1.0.4",
4646
"grunt-compile-handlebars": "^2.0.2",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,10 +1348,10 @@ graphlib@^2.1.7:
13481348
dependencies:
13491349
lodash "^4.17.15"
13501350

1351-
graphql-2-json-schema@^0.1.1:
1352-
version "0.1.1"
1353-
resolved "https://registry.yarnpkg.com/graphql-2-json-schema/-/graphql-2-json-schema-0.1.1.tgz#77e1f9b2b9513bd38ac9e751e7e6f1096399a89f"
1354-
integrity sha512-Vy4gafvd1se+06QJgoVqjBwGrdpcp+MQ4t08U9Bb9FHvLJm3ZauISp72yXVyT9bj+BUkomaBeayGyedGiFfUOA==
1351+
graphql-2-json-schema@^0.2.0:
1352+
version "0.2.0"
1353+
resolved "https://registry.npmjs.org/graphql-2-json-schema/-/graphql-2-json-schema-0.2.0.tgz#ef02d7d422071be199bfb4d3c6719f3431005661"
1354+
integrity sha512-INEySjzTCb+oI8RTVBGQDHBgOiXtHlcR47MKvyWtaiJbptUBUXHlfO1njI89NeU+KIF6cUnAqmKgyYgyJVYwbA==
13551355
dependencies:
13561356
functional-json-schema "0.0.2-3"
13571357
lodash "^4.17.10"

0 commit comments

Comments
 (0)