diff --git a/OpenApi.vue b/OpenApi.vue index 9791114..e368a2b 100644 --- a/OpenApi.vue +++ b/OpenApi.vue @@ -26,7 +26,6 @@ - @@ -56,93 +55,11 @@

Implementation Notes

{{selectedEntry.description}} --> -

Parameters

- - - - Name - Description - Type - Values - Location - Required - - - - - - Payload - Request body - - - - {{content}} - - - - - open_in_new - - body - - - - - - - - {{parameter.name}} - - {{parameter.schema.type}} - {{parameter.schema.items.type}} array - {{parameter.schema.enum.join(', ')}} - - -
{{(parameter.schema.items.enum || []).join(', ')}}
-
- {{parameter.in}} - - - -
-
-
- +

Responses

- - - - HTTP Code - Response - Type - Schema - Examples - - - - - - {{code}} - - - - - {{content}} - - - - - open_in_new - - - - open_in_new - - - - + @@ -164,40 +81,7 @@

Request

-
- - - - - -
- - - - - - - - - {{val}} - - - - - - - {{val}} - - - - - - - - {{parameter.name}} - -
-
+ Request @@ -213,7 +97,6 @@ + + diff --git a/RequestForm.vue b/RequestForm.vue new file mode 100644 index 0000000..c400440 --- /dev/null +++ b/RequestForm.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/ResponsesTable.vue b/ResponsesTable.vue new file mode 100644 index 0000000..b00f0ac --- /dev/null +++ b/ResponsesTable.vue @@ -0,0 +1,46 @@ + + + + + diff --git a/request.js b/request.js new file mode 100644 index 0000000..02b288f --- /dev/null +++ b/request.js @@ -0,0 +1,37 @@ +exports.reset = (request, entry) => { + request.params = Object.assign({}, ...(entry.parameters || []).map(p => ({ + [p.name]: p.schema.enum ? p.schema.enum[0] : (p.schema.type === 'array' ? [] : null) + }))) + if (entry.requestBody) { + request.contentType = Object.keys(entry.requestBody.content)[0] + request.requestBody = entry.requestBody.content[request.contentType].example || '' + } +} + +exports.fetch = (request, entry, api) => { + let params = Object.assign({}, ...(entry.parameters || []).filter(p => p.in === 'query' && (p.schema.type === 'array' ? request.params[p.name].length : request.params[p.name])) + .map(p => ({ + // TODO : join character for array should depend of p.style + [p.name]: p.schema.type === 'array' ? request.params[p.name].join(',') : request.params[p.name] + })) + ) + let headers = Object.assign({}, ...(entry.parameters || []).filter(p => p.in === 'header' && (p.schema.type === 'array' ? request.params[p.name].length : request.params[p.name])) + .map(p => ({ + // TODO : join character for array should depend of p.style + [p.name]: p.schema.type === 'array' ? request.params[p.name].join(',') : request.params[p.name] + })) + ) + const httpRequest = { + method: entry.method, + url: api.servers[0].url + entry.path.replace(/{(\w*)}/g, (m, key) => { + return request.params[key] + }), + params, + headers + } + if (entry.requestBody) { + httpRequest.headers['Content-type'] = request.contentType + httpRequest.body = request.requestBody + } + $http(httpRequest).then(response => response.body) +} diff --git a/tags.js b/tags.js new file mode 100644 index 0000000..21f8789 --- /dev/null +++ b/tags.js @@ -0,0 +1,81 @@ +import _get from 'lodash.get' + +const defaultStyle = { + query: 'form', + path: 'simple', + header: 'simple', + cookie: 'form' +} + +function processContent(contentType, api) { + // Spec allow an item or an array, we always fall back on an array of examples + if (contentType.example) { + contentType.examples = contentType.examples || [] + 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) { + if (contentType.schema.$ref) { + contentType.schema = _get(api, contentType.schema.$ref.split('#/').pop().replace(/\//g, '.')) + } else if (contentType.schema.items && contentType.schema.items.$ref) { + contentType.schema.items = _get(api, contentType.schema.items.$ref.split('#/').pop().replace(/\//g, '.')) + } + if (typeof contentType.schema !== 'string') { + contentType.schemaHTML = '
' + JSON.stringify(contentType.schema, null, 2) + '
' + } + } +} + +exports.get = api => { + var tags = {} + Object.keys(api.paths).forEach(function(path) { + Object.keys(api.paths[path]).forEach(function(method) { + let entry = api.paths[path][method] + entry.method = method + entry.path = path + // Filling tags entries + entry.tags = entry.tags || [] + if (!entry.tags.length) { + entry.tags.push('No category') + } + entry.tags.forEach(function(tag) { + tags[tag] = tags[tag] || [] + tags[tag].push(entry) + }) + if (entry.parameters) { + entry.parameters.forEach(p => { + p.style = p.style || defaultStyle[p.in] + p.explode = p.explode || (p.style === 'form') + p.schema = p.schema || { + type: 'string' + } + }) + } + if (entry.requestBody) { + if (entry.requestBody.$ref) { + entry.requestBody = _get(api, entry.requestBody.$ref.split('#/').pop().replace(/\//g, '.')) + } + if (entry.requestBody.content) { + entry.requestBody.selectedType = Object.keys(entry.requestBody.content)[0] + entry.requestBody.required = true + Object.values(entry.requestBody.content).forEach(contentType => processContent(contentType, api)) + } + } + + // Some preprocessing with responses + Object.values(entry.responses).forEach(response => { + if (response.content) { + // preselecting responses mime-type + response.selectedType = Object.keys(response.content)[0] + Object.values(response.content).forEach(contentType => processContent(contentType, api)) + } + }) + }) + }) + return tags +}