Skip to content

Commit

Permalink
fix: handling docs when no server is set
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-bonnel committed Jul 3, 2018
1 parent 2a3399c commit e30753d
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/OpenApi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
<md-layout md-column md-flex-offset="5" md-flex="true" v-if="selectedEntry">
<h2 class="md-title">{{selectedEntry.title || selectedEntry.summary}}</h2>
<p class="entry-description" v-if="selectedEntry.description" v-html="marked(selectedEntry.description || '')"></p>
<h3 class="md-subheading">{{selectedEntry.method.toUpperCase()}} {{api.servers[0].url + selectedEntry.path}}</h3>
<h3 class="md-subheading">{{selectedEntry.method.toUpperCase()}} {{ (api.servers && api.servers.length ? api.servers[0].url : '') + selectedEntry.path}}</h3>
<md-tabs md-right class="md-transparent" style="margin-top:-54px">
<md-tab md-label="Documentation">
<h4 v-if="(selectedEntry.parameters && selectedEntry.parameters.length) || selectedEntry.requestBody">Parameters</h4>
<parameters-table :selectedEntry="selectedEntry" :openSchemaDialog="openSchemaDialog" :openExamplesDialog="openExamplesDialog"></parameters-table>
<h4>Responses</h4>
<responses-table :selectedEntry="selectedEntry" :openSchemaDialog="openSchemaDialog" :openExamplesDialog="openExamplesDialog"></responses-table>
</md-tab>
<md-tab md-label="Make request">
<md-tab v-if="api.servers && api.servers.length" md-label="Make request">
<md-layout md-row>
<md-layout md-column md-flex="40">
<h2>Request</h2>
Expand Down Expand Up @@ -274,9 +274,9 @@ function fetch(request, entry, api) {
)
const httpRequest = {
method: entry.method,
url: api.servers[0].url + entry.path.replace(/{(\w*)}/g, (m, key) => {
url: api.servers.length && (api.servers[0].url + entry.path.replace(/{(\w*)}/g, (m, key) => {
return request.params[key]
}),
})),
params,
headers
}
Expand Down
2 changes: 1 addition & 1 deletion test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OpenApi from '../src/OpenApi.vue'
import 'vue-material/dist/vue-material.css'
import VueResource from 'vue-resource'

import jsonApi from './geocoder.json'
import jsonApi from './official-examples/api-with-examples.json'

Vue.use(VueResource)
Vue.use(VueMaterial)
Expand Down
163 changes: 163 additions & 0 deletions test/official-examples/api-with-examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "v2"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}]
}, {
"status": "EXPERIMENTAL",
"updated": "2013-07-23T11:33:21Z",
"id": "v3.0",
"links": [{
"href": "http://127.0.0.1:8774/v3/",
"rel": "self"
}]
}]
}
}
}
}
}
},
"300": {
"description": "300 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}]
}, {
"status": "EXPERIMENTAL",
"updated": "2013-07-23T11:33:21Z",
"id": "v3.0",
"links": [{
"href": "http://127.0.0.1:8774/v3/",
"rel": "self"
}]
}]
}
}
}
}
}
}
}
}
},
"/v2": {
"get": {
"operationId": "getVersionDetailsv2",
"summary": "Show API version details",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"version": {
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"media-types": [{
"base": "application/xml",
"type": "application/vnd.openstack.compute+xml;version=2"
}, {
"base": "application/json",
"type": "application/vnd.openstack.compute+json;version=2"
}],
"id": "v2.0",
"links": [{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}, {
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
"type": "application/pdf",
"rel": "describedby"
}, {
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
"type": "application/vnd.sun.wadl+xml",
"rel": "describedby"
}, {
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
"type": "application/vnd.sun.wadl+xml",
"rel": "describedby"
}]
}
}
}
}
}
}
},
"203": {
"description": "203 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"version": {
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"media-types": [{
"base": "application/xml",
"type": "application/vnd.openstack.compute+xml;version=2"
}, {
"base": "application/json",
"type": "application/vnd.openstack.compute+json;version=2"
}],
"id": "v2.0",
"links": [{
"href": "http://23.253.228.211:8774/v2/",
"rel": "self"
}, {
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
"type": "application/pdf",
"rel": "describedby"
}, {
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
"type": "application/vnd.sun.wadl+xml",
"rel": "describedby"
}]
}
}
}
}
}
}
}
}
}
}
}
}

0 comments on commit e30753d

Please sign in to comment.