Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

var program = require('commander');
var SwaggerParser = require('swagger-parser');
var RefParser = require('json-schema-ref-parser');

var openapi2slate = require('./openapi2slate.js');

program
.arguments('<file>')
.option('--dereference', 'Do not generate Markdown, just dereference to single JSON')
.option('--validate', 'Validate the API')
.option('--include-internal', 'Include Internal API calls')
.action(function(file) {
Expand All @@ -19,6 +21,18 @@ if(typeof apiFilePath === 'undefined') {
process.exit(1);
}

if(program.dereference) {
RefParser.dereference(apiFilePath)
.then(function(deRefApi) {
console.log(JSON.stringify(deRefApi));
process.exit(0);
})
.catch(function(err) {
console.error('API dereference failed: ' + err);
process.exit(1);
});
}

if(program.validate) {
SwaggerParser.validate(apiFilePath)
.then(function(api) {
Expand Down
10 changes: 10 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ echo "# $out matches"
./main.js $input/basic.yaml > $output/$out
diff $check/$out $output/$out

out=basic.json
echo "# $out matches"
./main.js --dereference $input/basic.yaml > $output/$out
diff $check/$out $output/$out

out=scrive_api.md
echo "# $out matches"
./main.js $input/scrive-apidocs/scrive_api.yaml > $output/$out
Expand All @@ -27,5 +32,10 @@ echo "# $out matches"
./main.js --include-internal $input/scrive-apidocs/scrive_api.yaml > $output/$out
diff $check/$out $output/$out

out=scrive_api.json
echo "# $out matches"
./main.js --dereference $input/scrive-apidocs/scrive_api.yaml > $output/$out
diff $check/$out $output/$out

# TODO add more example conversions
# TODO add a run with validate flag
1 change: 1 addition & 0 deletions test/check/basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"title":"Title\n","version":"0.0.1","description":"# First heading\n\nSome description, with `monospace`, _italic_, and **bold**.\n\n<aside class=\"success\">\nCustom HTML\n</aside>\n\n## Second level heading\n\n> Multi\n> line\n> quote\n\nAnd also some code with syntax highlighting\n```json\n{ \"foo\" :\n [ \"bar\", \"baz\" ]\n}\n```\n","contact":{"name":"Contact name","url":"https://example.com/","email":"[email protected]"},"termsOfService":"Here goes the terms of service.\n","license":{"name":"Whatever you want"}},"host":"example.com","basePath":"/base/path","schemes":["https"],"tags":[{"name":"Tag1"},{"name":"Tag2"}],"paths":{"/foo/bar":{"get":{"summary":"Summary text","tags":["Tag1","Tag2"],"description":"Description text\n","responses":{"200":{"description":"Response description `HTTP 200`\n"}}}}},"parameters":{"Parameter1":{"name":"parameter_1_name","in":"path","required":true,"description":"Parameter1 description\n","type":"integer","format":"int64"}},"responses":{"Response1":{"description":"Response description","schema":{"$schema":"http://json-schema.org/draft-04/schema#","title":"Response schema title","type":"object","description":"Response schema description","properties":{"id":{"description":"Foobar","type":"string","readOnly":true}},"example":{"id":"bazbaz"}}}}}
1 change: 1 addition & 0 deletions test/check/help
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Usage: main [options] <file>

Options:
--dereference Do not generate Markdown, just dereference to single JSON
--validate Validate the API
--include-internal Include Internal API calls
-h, --help output usage information
1 change: 1 addition & 0 deletions test/check/scrive_api.json

Large diffs are not rendered by default.