OpenAPI v3 import robustness (#2007)

* Make openapi3 import more robust by checking if the server tag exists before consuming it

* Fix formating
This commit is contained in:
Opender Singh 2020-03-27 05:56:11 +13:00 committed by GitHub
parent daef7806c8
commit 0b0c5baa0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 224 additions and 2 deletions

View File

@ -0,0 +1,162 @@
openapi: '3.0.0'
info:
title: Simple API overview
version: 2.0.0
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"
}]
}
}

View File

@ -0,0 +1,59 @@
{
"__export_date": "2020-03-24T06:16:20.516Z",
"__export_format": 4,
"__export_source": "insomnia.importers:v0.1.0",
"_type": "export",
"resources": [
{
"_id": "__WORKSPACE_ID__",
"_type": "workspace",
"description": "",
"name": "Simple API overview 2.0.0",
"parentId": null
},
{
"_id": "__BASE_ENVIRONMENT_ID__",
"_type": "environment",
"data": {
"base_url": "{{ scheme }}://{{ host }}{{ base_path }}"
},
"name": "Base environment",
"parentId": "__WORKSPACE_ID__"
},
{
"_id": "env___BASE_ENVIRONMENT_ID___sub",
"_type": "environment",
"data": {
"base_path": "",
"host": "example.com",
"scheme": "http"
},
"name": "OpenAPI env",
"parentId": "__BASE_ENVIRONMENT_ID__"
},
{
"_id": "req___WORKSPACE_ID__316fc296",
"_type": "request",
"authentication": {},
"body": {},
"headers": [],
"method": "GET",
"name": "List API versions",
"parameters": [],
"parentId": "__WORKSPACE_ID__",
"url": "{{ base_url }}/"
},
{
"_id": "req___WORKSPACE_ID__4dd01204",
"_type": "request",
"authentication": {},
"body": {},
"headers": [],
"method": "GET",
"name": "Show API version details",
"parameters": [],
"parentId": "__WORKSPACE_ID__",
"url": "{{ base_url }}/v2"
}
]
}

View File

@ -65,8 +65,9 @@ module.exports.convert = async function(rawData) {
},
};
const servers = api.servers.map(s => urlParse(s.url));
const defaultServer = servers[0] || urlParse('http://example.com/');
const servers = api.servers || [];
const serverUrls = servers.map(s => urlParse(s.url));
const defaultServer = serverUrls[0] || urlParse('http://example.com/');
const securityVariables = getSecurityEnvVariables(
api.components && api.components.securitySchemes,
);