Fix importer test fixtures to comply with OpenAPI specs (#4095) (#4151)

This commit is contained in:
Gareth Oakley 2022-02-22 19:45:52 +00:00 committed by GitHub
parent 2401788509
commit 3a944d9dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 332 additions and 34 deletions

View File

@ -27,6 +27,8 @@
"apiKey": "apiKey",
"base_path": "/v2",
"host": "petstore.swagger.io",
"oauth2ClientId": "clientId",
"oauth2RedirectUrl": "http://localhost/",
"scheme": "http"
},
"name": "OpenAPI env",
@ -35,7 +37,14 @@
{
"_id": "req___WORKSPACE_ID__23acbe44",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -50,7 +59,14 @@
{
"_id": "req___WORKSPACE_ID__74a7a059",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -65,7 +81,14 @@
{
"_id": "req___WORKSPACE_ID__80ab0d08",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -83,7 +106,14 @@
{
"_id": "req___WORKSPACE_ID__42a17980",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -119,7 +149,14 @@
{
"_id": "req___WORKSPACE_ID__a4608701",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/x-www-form-urlencoded"
},
@ -133,7 +170,14 @@
{
"_id": "req___WORKSPACE_ID__e804bd05",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [
{
@ -151,7 +195,14 @@
{
"_id": "req___WORKSPACE_ID__8081fb6f",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "multipart/form-data"
},

View File

@ -27,6 +27,8 @@
"apiKey": "apiKey",
"base_path": "/v2",
"host": "petstore.swagger.io",
"oauth2ClientId": "clientId",
"oauth2RedirectUrl": "http://localhost/",
"scheme": "http"
},
"name": "OpenAPI env",
@ -59,7 +61,14 @@
{
"_id": "req___WORKSPACE_ID__23acbe44",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -74,7 +83,14 @@
{
"_id": "req___WORKSPACE_ID__74a7a059",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -89,7 +105,14 @@
{
"_id": "req___WORKSPACE_ID__80ab0d08",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -107,7 +130,14 @@
{
"_id": "req___WORKSPACE_ID__42a17980",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -143,7 +173,14 @@
{
"_id": "req___WORKSPACE_ID__a4608701",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/x-www-form-urlencoded"
},
@ -157,7 +194,14 @@
{
"_id": "req___WORKSPACE_ID__e804bd05",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [
{
@ -175,7 +219,14 @@
{
"_id": "req___WORKSPACE_ID__8081fb6f",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "multipart/form-data"
},

View File

@ -39,7 +39,6 @@ components:
in: query
OAuth2-AuthorizationCode:
type: oauth2
scheme: bearer
flows:
authorizationCode:
authorizationUrl: https://api.server.test/v1/auth
@ -49,7 +48,6 @@ components:
write:something: Write all the data
OAuth2-Implicit:
type: oauth2
scheme: bearer
flows:
implicit:
authorizationUrl: https://api.server.test/v1/auth
@ -58,7 +56,6 @@ components:
write:something: Write all the data
OAuth2-ClientCredentials:
type: oauth2
scheme: bearer
flows:
clientCredentials:
tokenUrl: https://api.server.test/v1/token
@ -67,7 +64,6 @@ components:
write:something: Write all the data
OAuth2-Password:
type: oauth2
scheme: bearer
flows:
password:
tokenUrl: https://api.server.test/v1/token

View File

@ -34,6 +34,7 @@
"httpUsername": "username",
"oauth2ClientId": "clientId",
"oauth2ClientSecret": "clientSecret",
"oauth2RedirectUrl": "http://localhost/",
"oauth2Username": "username",
"oauth2Password": "password",
"key": "key",
@ -174,6 +175,7 @@
"authentication": {
"clientId": "{{ oauth2ClientId }}",
"clientSecret": "{{ oauth2ClientSecret }}",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"accessTokenUrl": "https://api.server.test/v1/token",
"authorizationUrl": "https://api.server.test/v1/auth",
"grantType": "authorization_code",
@ -193,6 +195,7 @@
"_type": "request",
"authentication": {
"clientId": "{{ oauth2ClientId }}",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"authorizationUrl": "https://api.server.test/v1/auth",
"grantType": "implicit",
"scope": "read:something write:something",

View File

@ -0,0 +1,27 @@
openapi: '3.0.2'
info:
title: Endpoint Security
version: '1.2'
servers:
- url: https://api.server.test/v1
components:
securitySchemes:
OAuth2-AuthorizationCode:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://api.server.test/v1/auth
tokenUrl: https://api.server.test/v1/token
scopes:
read:something: Read all the data
write:something: Write all the data
paths:
/oauth2/authorization-code:
get:
security:
- OAuth2-AuthorizationCode: []
responses:
'200':
description: OK

View File

@ -0,0 +1,59 @@
{
"__export_date": "2020-05-13T23:55:24.712Z",
"__export_format": 4,
"__export_source": "insomnia.importers:v0.1.0",
"_type": "export",
"resources": [
{
"_id": "__WORKSPACE_ID__",
"_type": "workspace",
"description": "",
"name": "Endpoint Security 1.2",
"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": "/v1",
"host": "api.server.test",
"oauth2ClientId": "clientId",
"oauth2ClientSecret": "clientSecret",
"oauth2RedirectUrl": "http://localhost/",
"scheme": "https"
},
"name": "OpenAPI env",
"parentId": "__BASE_ENVIRONMENT_ID__"
},
{
"_id": "req___WORKSPACE_ID__028b5fb7",
"_type": "request",
"authentication": {
"clientId": "{{ oauth2ClientId }}",
"clientSecret": "{{ oauth2ClientSecret }}",
"accessTokenUrl": "https://api.server.test/v1/token",
"authorizationUrl": "https://api.server.test/v1/auth",
"grantType": "authorization_code",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "read:something write:something",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
"name": "/oauth2/authorization-code",
"parameters": [],
"parentId": "__WORKSPACE_ID__",
"url": "{{ base_url }}/oauth2/authorization-code"
}
]
}

View File

@ -27,6 +27,8 @@
"apiKey": "apiKey",
"base_path": "/v2",
"host": "petstore.swagger.io",
"oauth2ClientId": "clientId",
"oauth2RedirectUrl": "http://localhost/",
"scheme": "http"
},
"name": "OpenAPI env",
@ -35,7 +37,14 @@
{
"_id": "req___WORKSPACE_ID__23acbe44",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -50,7 +59,14 @@
{
"_id": "req___WORKSPACE_ID__74a7a059",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -65,7 +81,14 @@
{
"_id": "req___WORKSPACE_ID__80ab0d08",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -83,7 +106,14 @@
{
"_id": "req___WORKSPACE_ID__42a17980",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -119,7 +149,14 @@
{
"_id": "req___WORKSPACE_ID__a4608701",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/x-www-form-urlencoded"
},
@ -133,7 +170,14 @@
{
"_id": "req___WORKSPACE_ID__e804bd05",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [
{
@ -151,7 +195,14 @@
{
"_id": "req___WORKSPACE_ID__8081fb6f",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "multipart/form-data"
},

View File

@ -27,6 +27,8 @@
"apiKey": "apiKey",
"base_path": "/v2",
"host": "petstore.swagger.io",
"oauth2ClientId": "clientId",
"oauth2RedirectUrl": "http://localhost/",
"scheme": "http"
},
"name": "OpenAPI env",
@ -59,7 +61,14 @@
{
"_id": "req___WORKSPACE_ID__23acbe44",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -74,7 +83,14 @@
{
"_id": "req___WORKSPACE_ID__74a7a059",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/json",
"text": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"string\"\n}"
@ -89,7 +105,14 @@
{
"_id": "req___WORKSPACE_ID__80ab0d08",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -107,7 +130,14 @@
{
"_id": "req___WORKSPACE_ID__42a17980",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [],
"method": "GET",
@ -143,7 +173,14 @@
{
"_id": "req___WORKSPACE_ID__a4608701",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "application/x-www-form-urlencoded"
},
@ -157,7 +194,14 @@
{
"_id": "req___WORKSPACE_ID__e804bd05",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {},
"headers": [
{
@ -175,7 +219,14 @@
{
"_id": "req___WORKSPACE_ID__8081fb6f",
"_type": "request",
"authentication": {},
"authentication": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"clientId": "{{ oauth2ClientId }}",
"grantType": "implicit",
"redirectUrl": "{{ oauth2RedirectUrl }}",
"scope": "write:pets read:pets",
"type": "oauth2"
},
"body": {
"mimeType": "multipart/form-data"
},

View File

@ -339,7 +339,7 @@ const parseSecurity = (
const authScheme = supportedSchemes.find(
scheme =>
[SECURITY_TYPE.HTTP, SECURITY_TYPE.OAUTH].includes(scheme.type) &&
SUPPORTED_HTTP_AUTH_SCHEMES.includes(scheme.scheme),
(scheme.type === SECURITY_TYPE.OAUTH || SUPPORTED_HTTP_AUTH_SCHEMES.includes(scheme.scheme)),
);
if (!authScheme) {
@ -402,10 +402,17 @@ const getSecurityEnvVariables = (securitySchemeObject?: OpenAPIV3.SecurityScheme
}
const oauth2Variables = securitySchemes.reduce((accumulator, scheme) => {
if (scheme.type === SECURITY_TYPE.OAUTH && scheme.scheme === 'bearer') {
if (scheme.type === SECURITY_TYPE.OAUTH) {
accumulator.oauth2ClientId = 'clientId';
const flows = scheme.flows || {};
if (
flows.authorizationCode ||
flows.implicit
) {
accumulator.oauth2RedirectUrl = 'http://localhost/';
}
if (
flows.authorizationCode ||
flows.clientCredentials ||
@ -657,6 +664,7 @@ const parseOAuth2 = (scheme: OpenAPIV3.OAuth2SecurityScheme) => {
return {
...base,
clientSecret: '{{ oauth2ClientSecret }}',
redirectUrl: '{{ oauth2RedirectUrl }}',
accessTokenUrl: (flow as OpenAPIV3.OAuth2SecurityScheme['flows'][typeof OAUTH_FLOWS.AUTHORIZATION_CODE])?.tokenUrl,
authorizationUrl: (flow as OpenAPIV3.OAuth2SecurityScheme['flows'][typeof OAUTH_FLOWS.AUTHORIZATION_CODE])?.authorizationUrl,
};
@ -671,6 +679,7 @@ const parseOAuth2 = (scheme: OpenAPIV3.OAuth2SecurityScheme) => {
case OAUTH_FLOWS.IMPLICIT:
return {
...base,
redirectUrl: '{{ oauth2RedirectUrl }}',
authorizationUrl: (flow as OpenAPIV3.OAuth2SecurityScheme['flows'][typeof OAUTH_FLOWS.IMPLICIT])?.authorizationUrl,
};