This repository has been archived by the owner on Nov 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple response codes
- Loading branch information
Wojciech Możejko
committed
Oct 19, 2016
1 parent
8c3f498
commit 362d831
Showing
6 changed files
with
104 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<method-responses> | ||
<div class="ui secondary pointing menu js-tab"> | ||
<a class="ui dropdown item"> | ||
<span>{ responses[0].code().value() }</span> | ||
<i class="dropdown icon"></i> | ||
<div class="menu"> | ||
<div class="item" each={ response in responses } data-response-code={ response.code().value() } }> | ||
{ response.code().value() } | ||
</div> | ||
</div> | ||
</a> | ||
|
||
<a class="item active" data-tab="schema-{ methodId }"> | ||
<i class="code disabled icon"></i> Schema | ||
</a> | ||
|
||
<a class="item" data-tab="example-{ methodId }"> | ||
<i class="info disabled icon"></i> Example | ||
</a> | ||
|
||
<a class="item" data-tab="try-{ methodId }"> | ||
<i class="eyedropper disabled icon"></i> Try | ||
</a> | ||
</div> | ||
|
||
<div class="ui bottom attached tab active" data-tab="schema-{ methodId }"> | ||
<div class={ ui: true, tab: true, 'js-json': true, active: isFirstResponse(response) } | ||
each={ response in responses } | ||
data-response-code={ response.code().value() } }> | ||
{ parseSchema(response.body()[0].schemaContent()) } | ||
</div> | ||
</div> | ||
|
||
<div class="ui bottom attached tab" data-tab="example-{ methodId }"> | ||
<div class={ ui: true, tab: true, 'js-json': true, active: isFirstResponse(response) } | ||
each={ response in responses } | ||
data-response-code={ response.code().value() } }> | ||
{ response.body()[0].example().value() } | ||
</div> | ||
</div> | ||
|
||
<div class="ui bottom attached tab" data-tab="try-{ methodId }"> | ||
</div> | ||
|
||
<script> | ||
this.$RefParser = require('json-schema-ref-parser') | ||
this.method = opts.method | ||
|
||
this.dereference = (schema) => { | ||
var data, done = false | ||
var resolver = this.parent.app.make('schema-resolver') | ||
|
||
this.$RefParser.dereference(schema, { resolve: { raml: resolver }}, function(err, schema) { | ||
if (err) { | ||
console.error(err) | ||
return done = true | ||
} | ||
|
||
data = schema | ||
done = true | ||
}) | ||
|
||
require('deasync').loopWhile(function(){ return !done }) | ||
|
||
return data | ||
} | ||
|
||
this.parseSchema = (schema) => { | ||
this.jsonSchema = schema | ||
|
||
try { | ||
this.jsonSchema = JSON.parse(schema) | ||
} catch(e) {} | ||
|
||
let derefenced = this.dereference(this.jsonSchema) | ||
|
||
return JSON.stringify(derefenced) | ||
} | ||
|
||
this.isFirstResponse = (response) => { | ||
return this.responses[0].code().value() == response.code().value() | ||
} | ||
|
||
this.on('update', () => { | ||
this.responses = this.method.responses() | ||
this.methodId = this.method.methodId().replace(/[\W]/g, '_') | ||
}) | ||
</script> | ||
</method-responses> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters