Skip to content

Commit

Permalink
Several fixes and improvements (#7)
Browse files Browse the repository at this point in the history
* feat: alphabetize definitions

Signed-off-by: Eric Dobbertin <eric@dairystatedesigns.com>

* fix: remove duplicate request body contents

Signed-off-by: Eric Dobbertin <eric@dairystatedesigns.com>

* feat: update to latest graphql-2-json-schema

Adds rendering of built-in and custom scalars

Signed-off-by: Eric Dobbertin <eric@dairystatedesigns.com>

* fix: fix extra params being shown in some examples

Signed-off-by: Eric Dobbertin <eric@dairystatedesigns.com>

* fix: guard against undefined definitions

Signed-off-by: Eric Dobbertin <eric@dairystatedesigns.com>
  • Loading branch information
aldeed authored and offbeatful committed Dec 16, 2019
1 parent cf0e5c8 commit ec6f12a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
16 changes: 11 additions & 5 deletions app/dociql/generate-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
const space = ' '.repeat(depth)
var queryStr = space + field.name

// It's important to clone the array here. Otherwise we would
// be pushing arguments into the array passed by reference,
// which results in arguments from one query being incorrectly
// shown on another query's example.
const fieldArgs = [...arguments];

if (field.args.length > 0) {
arguments.push(...field.args);
fieldArgs.push(...field.args);
const argsStr = field.args.map(arg => `${arg.name}: $${arg.name}`).join(', ');
queryStr += `(${argsStr})`;
}
Expand All @@ -31,7 +37,7 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
if (!expandedField)
return {
query: "",
args: arguments
args: fieldArgs
};

if (depth > 1) {
Expand All @@ -53,7 +59,7 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts
return generateQueryInternal(
childFields[key],
expandGraph,
arguments,
fieldArgs,
depth + 1,
typeCounts).query
}).join("");
Expand All @@ -63,7 +69,7 @@ function generateQueryInternal(field, expandGraph, arguments, depth, typeCounts

return {
query: queryStr + "\n",
args: arguments
args: fieldArgs
};
}

Expand Down Expand Up @@ -106,7 +112,7 @@ function generateExampleSchema(name, type, expandGraph, depth) {
if (type instanceof GraphQLNonNull)
return generateExampleSchema(name, type.ofType, expandGraph, depth + 1);
if (type instanceof GraphQLList) {
var schema = generateExampleSchema(name, type.ofType, expandGraph, depth) // do not increment depth
var schema = generateExampleSchema(name, type.ofType, expandGraph, depth) // do not increment depth
return schema ? {
type: 'array',
items: schema
Expand Down
10 changes: 10 additions & 0 deletions app/lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ module.exports = function(options, specData) {
var replaceRefs = require("./resolve-references").replaceRefs;
replaceRefs(path.dirname(copy["x-spec-path"]), copy, copy, "")

if (copy.definitions) {
var names = Object.keys(copy.definitions);
names.sort();
var sortedDefinitions = {};
for (const name of names) {
sortedDefinitions[name] = copy.definitions[name];
}
copy.definitions = sortedDefinitions;
}

return copy;
}

Expand Down
2 changes: 1 addition & 1 deletion app/views/partials/swagger/request-body.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{{else if schema.description}}
{{md schema.description}}
{{/if}}
{{>json-schema/body schema}}
{{!-- {{>json-schema/body schema}} --}}
{{/if}}
{{/with}}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"commander": "*",
"foundation-sites": "^6.5.0-rc.4",
"graphql": "^14.1.1",
"graphql-2-json-schema": "^0.1.1",
"graphql-2-json-schema": "^0.2.0",
"graphql-json-schema": "^0.1.2",
"grunt": "^1.0.4",
"grunt-compile-handlebars": "^2.0.2",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1348,10 +1348,10 @@ graphlib@^2.1.7:
dependencies:
lodash "^4.17.15"

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

0 comments on commit ec6f12a

Please sign in to comment.