Request
@@ -210,6 +214,9 @@ function processContent(contentType, api) {
contentType.examples.push(contentType.example)
}
if (contentType.examples) {
+ if(!contentType.example && contentType.examples.length){
+ contentType.example = contentType.examples[0]
+ }
contentType.examples = contentType.examples.map(e => '' + JSON.stringify(e, null, 2) + '
')
}
if (contentType.schema) {
@@ -219,7 +226,7 @@ function processContent(contentType, api) {
contentType.schema.items = get(api, contentType.schema.items.$ref.split('#/').pop().replace(/\//g, '.'))
}
if (typeof contentType.schema !== 'string') {
- contentType.schema = '' + JSON.stringify(contentType.schema, null, 2) + '
'
+ contentType.schemaHTML = '' + JSON.stringify(contentType.schema, null, 2) + '
'
}
}
}
@@ -304,10 +311,15 @@ export default {
},
methods: {
resetRequest(entry) {
- for (var p in this.currentRequest) delete this.currentRequest[p]
- this.currentRequest = Object.assign({}, this.currentRequest, ...(entry.parameters || []).map(p => ({
+ // for (var p in this.currentRequest) delete this.currentRequest[p]
+
+ this.currentRequest.params = Object.assign({}, ...(entry.parameters || []).map(p => ({
[p.name]: p.schema.enum ? p.schema.enum[0] : (p.schema.type === 'array' ? [] : null)
})))
+ if(entry.requestBody){
+ this.currentRequest.contentType = Object.keys(entry.requestBody.content)[0]
+ this.currentRequest.requestBody = entry.requestBody.content[this.currentRequest.contentType].example || ''
+ }
},
select(entry) {
this.resetRequest(entry)
@@ -331,19 +343,31 @@ export default {
},
request() {
this.currentResponse = ''
- let params = Object.assign({}, ...(this.selectedEntry.parameters || []).filter(p => p.in === 'query' && (p.schema.type === 'array' ? this.currentRequest[p.name].length : this.currentRequest[p.name]))
+ let params = Object.assign({}, ...(this.selectedEntry.parameters || []).filter(p => p.in === 'query' && (p.schema.type === 'array' ? this.currentRequest.params[p.name].length : this.currentRequest.params[p.name]))
.map(p => ({
// TODO : join character for array should depend of p.style
- [p.name]: p.schema.type === 'array' ? this.currentRequest[p.name].join(',') : this.currentRequest[p.name]
+ [p.name]: p.schema.type === 'array' ? this.currentRequest.params[p.name].join(',') : this.currentRequest.params[p.name]
}))
)
- this.$http({
+ let headers = Object.assign({}, ...(this.selectedEntry.parameters || []).filter(p => p.in === 'header' && (p.schema.type === 'array' ? this.currentRequest.params[p.name].length : this.currentRequest.params[p.name]))
+ .map(p => ({
+ // TODO : join character for array should depend of p.style
+ [p.name]: p.schema.type === 'array' ? this.currentRequest.params[p.name].join(',') : this.currentRequest.params[p.name]
+ }))
+ )
+ let request = {
method: this.selectedEntry.method,
url: this.api.servers[0].url + this.selectedEntry.path.replace(/{(\w*)}/g, (m, key) => {
- return this.currentRequest[key]
+ return this.currentRequest.params[key]
}),
- params
- }).then(response => {
+ params,
+ headers
+ }
+ if(this.selectedEntry.requestBody){
+ request.headers['Content-type'] = this.currentRequest.contentType
+ request.body = this.currentRequest.requestBody
+ }
+ this.$http(request).then(response => {
this.currentResponse = JSON.stringify(response.body, null, 2)
}, response => {
this.currentResponse = JSON.stringify(response.body, null, 2)