Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
fix(converter): ignore x-swagger-router-controller folders (#27)
Browse files Browse the repository at this point in the history
fixes #26
  • Loading branch information
derevnjuk authored Apr 16, 2020
1 parent 8bbe0f9 commit d0ee788
Show file tree
Hide file tree
Showing 21 changed files with 4,124 additions and 4,137 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"quotes": [2, "single"]
},
"env": {
"browser": true,
"browser": false,
"node": true
}
}
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"printWidth": 100,
"semi": false
"semi": false,
"singleQuote": true
}
69 changes: 69 additions & 0 deletions __tests__/base-url.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { getBaseUrl } = require('../src/converter')

describe('OAS3', () => {
test('should return https url', () => {
const url = getBaseUrl({
servers: [
{ url: 'https://example.com' },
{ url: 'https://sub.example.com' },
{ url: 'http://example.com' },
],
})

expect(url).toContain('https://')
})

test('should return http url for backward compatibility', () => {
const url = getBaseUrl({
servers: [{ url: 'http://example.com' }, { url: 'http://sub.example.com' }],
})

expect(url).toContain('http://')
})

test('should return url without trailing slash', () => {
const url = getBaseUrl({
servers: [{ url: 'https://example.com/' }, { url: 'http://example.com' }],
})

expect(url).toContain('https://')
})
})

describe('OAS2', () => {
test('should return https url', () => {
const url = getBaseUrl({
schemes: [
'https',
'http',
],
host: 'example.com'
})

expect(url).toEqual('https://example.com')
})

test('should return http url for backward compatibility', () => {
const url = getBaseUrl({
schemes: [
'http',
],
host: 'example.com'
})

expect(url).toContain('http://example.com')
})

test('should return url with path', () => {
const url = getBaseUrl({
schemes: [
'http',
'https'
],
host: 'example.com',
basePath: '/api/v1'
})

expect(url).toContain('https://example.com/api/v1')
})
})
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions __tests__/image_sample.js → __tests__/image.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { encodePayload } = require('../src');
const { encodePayload } = require('../src/converter');

test('Test encodePayload for image/*', function() {
test('Test encodePayload for image/*', () => {
const pngSample = encodePayload({}, 'image/png', {});
const jpgSample = encodePayload({}, 'image/jpg', {});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/application_json.js → __tests__/json.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { encodePayload } = require('../src');
const { encodePayload } = require('../src/converter');

test('Test encodePayload for application/json', function() {
test('Test encodePayload for application/json', () => {
const jsonSample = {
name: 'Tom',
surname: 'Trailer',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {encodePayload} = require('../src');
const {encodePayload} = require('../src/converter');

test('Test encodePayload for multipart/form-data', function () {
test('Test encodePayload for multipart/form-data', () => {
const multiPartFormData = {
name: 'Tom',
surname: 'Trailer',
Expand Down Expand Up @@ -33,7 +33,7 @@ test('Test encodePayload for multipart/form-data', function () {
});


test('Test encodePayload for multipart/form-data', function () {
test('Test encodePayload for multipart/form-data', () => {
const multiPartFormData = {
person: {
name: 'John',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { encodePayload } = require('../src')
const { encodePayload } = require('../src/converter')

test('Test encodePayload for multipart/form-data', function() {
test('Test encodePayload for multipart/form-data', () => {
const multipartMixin = {
user: {
username: 'john',
Expand Down
10 changes: 5 additions & 5 deletions __tests__/oas2har.js → __tests__/oas2har.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { oasToHarList } = require('../src');
const githubSwagger = require('./github_swagger');
const { oasToHarList } = require('../src/converter');
const githubSwagger = require('./fixtures/github_swagger.json');

test('GitHub swagger v2 JSON to HAR', async function() {
test('GitHub swagger v2 JSON to HAR', async () => {
const [firstRequest] = await oasToHarList(githubSwagger);
const { har } = firstRequest;

Expand All @@ -10,8 +10,8 @@ test('GitHub swagger v2 JSON to HAR', async function() {
expect(har.httpVersion).toEqual('HTTP/1.1');
});

test('Petstore OpenApi v3 YAML to JSON converts to HAR', async function() {
const [firstRequest] = await oasToHarList(process.cwd() + '/__tests__/petstore_oas.yaml');
test('Petstore OpenApi v3 YAML to JSON converts to HAR', async () => {
const [firstRequest] = await oasToHarList(process.cwd() + '/__tests__/fixtures/petstore_oas.yaml');
const { har } = firstRequest;

expect(har.method).toEqual('PUT');
Expand Down
38 changes: 38 additions & 0 deletions __tests__/parse-swagger-doc.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { parseSwaggerDoc } = require('../src/converter')

test('should return empty entries', () => {
const swagger = {
paths: {
'x-swagger-router-controller': 'health',
},
}
const entries = parseSwaggerDoc(swagger, 'https://example.com')
expect(entries.length).toEqual(0)
})

test('should skip x-swagger-router-controller from paths', () => {
const swagger = {
paths: {
'x-swagger-router-controller': 'health',
'/emojis': {
get: {
parameters: [
{
description: 'You can check the current version of media type in responses.',
in: 'header',
name: 'X-Media-Type',
type: 'string',
},
],
},
},
},
}
const entries = parseSwaggerDoc(swagger, 'https://example.com')
expect(entries.length).toEqual(1)
expect(entries).toEqual(
expect.arrayContaining([
expect.objectContaining({ url: 'https://example.com/emojis' })
])
)
})
4 changes: 2 additions & 2 deletions __tests__/text_plain.js → __tests__/plain-text.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { encodePayload } = require('../src');
const { encodePayload } = require('../src/converter');

test('Test encodePayload for text/plain', function() {
test('Test encodePayload for text/plain', () => {
const primitiveSample = 'primitive';
const primitiveEncoded = encodePayload(primitiveSample, '*/*');
expect(primitiveEncoded.text).toEqual(primitiveSample);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { encodePayload } = require('../src');
const { encodePayload } = require('../src/converter');
const querystring = require('querystring');

test('Test encodePayload for application/x-www-form-urlencoded', function() {
test('Test encodePayload for application/x-www-form-urlencoded', () => {
const querystringSample = {
name: 'Tom',
surname: 'Trailer',
Expand Down
4 changes: 2 additions & 2 deletions __tests__/application_xml.js → __tests__/xml.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { encodePayload } = require('../src');
const { encodePayload } = require('../src/converter');
const { toXML } = require('jstoxml');

test('Test encodePayload for application/xml', function() {
test('Test encodePayload for application/xml', () => {
const xmlSample = {
name: 'Tom',
surname: 'Trailer',
Expand Down
Loading

0 comments on commit d0ee788

Please sign in to comment.