Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ lib/
.DS_Store
deploy-script.sh
coverage/
.nyc_output/
12 changes: 9 additions & 3 deletions configs/node/api-flow-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@ import Environment from '../../src/environments/node/Environment'

import SwaggerLoader from '../../src/loaders/swagger/Loader'
import RAMLLoader from '../../src/loaders/raml/Loader'
import PostmanV2Loader from '../../src/loaders/postman/v2.0/Loader'

import SwaggerV2Parser from '../../src/parsers/swagger/v2.0/Parser'
import RAMLV1Parser from '../../src/parsers/raml/v1.0/Parser'
import PostmanV2Parser from '../../src/loaders/postman/v2.0/Parser'

import SwaggerV2Serializer from '../../src/serializers/swagger/v2.0/Serializer'
import RAMLV1Serializer from '../../src/serializers/raml/v1.0/Serializer'
import PostmanV2Serializer from '../../src/serializers/postman/v2.0/Serializer'
import InternalSerializer from '../../src/serializers/internal/Serializer'

export const loaders = [
SwaggerLoader,
RAMLLoader
RAMLLoader,
PostmanV2Loader
]

export const parsers = [
SwaggerV2Parser,
RAMLV1Parser
RAMLV1Parser,
PostmanV2Parser
]

export const serializers = [
SwaggerV2Serializer,
RAMLV1Serializer,
InternalSerializer
InternalSerializer,
PostmanV2Serializer
]

export const environment = Environment
12 changes: 9 additions & 3 deletions configs/web/api-flow-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@ import Environment from '../../src/environments/web/Environment'

import SwaggerLoader from '../../src/loaders/swagger/Loader'
import RAMLLoader from '../../src/loaders/raml/Loader'
import PostmanV2Loader from '../../src/loaders/postman/v2.0/Loader'

import SwaggerV2Parser from '../../src/parsers/swagger/v2.0/Parser'
import RAMLV1Parser from '../../src/parsers/raml/v1.0/Parser'
import PostmanV2Parser from '../../src/loaders/postman/v2.0/Parser'

import SwaggerV2Serializer from '../../src/serializers/swagger/v2.0/Serializer'
import RAMLV1Serializer from '../../src/serializers/raml/v1.0/Serializer'
import PostmanV2Serializer from '../../src/serializers/postman/v2.0/Serializer'
import InternalSerializer from '../../src/serializers/internal/Serializer'

export const loaders = [
SwaggerLoader,
RAMLLoader
RAMLLoader,
PostmanV2Loader
]

export const parsers = [
SwaggerV2Parser,
RAMLV1Parser
RAMLV1Parser,
PostmanV2Parser
]

export const serializers = [
SwaggerV2Serializer,
RAMLV1Serializer,
InternalSerializer
InternalSerializer,
PostmanV2Serializer
]

export const environment = Environment
12 changes: 9 additions & 3 deletions configs/webworker/api-flow-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@ import Environment from '../../src/environments/web/Environment'

import SwaggerLoader from '../../src/loaders/swagger/Loader'
import RAMLLoader from '../../src/loaders/raml/Loader'
import PostmanV2Loader from '../../src/loaders/postman/v2.0/Loader'

import SwaggerV2Parser from '../../src/parsers/swagger/v2.0/Parser'
import RAMLV1Parser from '../../src/parsers/raml/v1.0/Parser'
import PostmanV2Parser from '../../src/loaders/postman/v2.0/Parser'

import SwaggerV2Serializer from '../../src/serializers/swagger/v2.0/Serializer'
import RAMLV1Serializer from '../../src/serializers/raml/v1.0/Serializer'
import PostmanV2Serializer from '../../src/serializers/postman/v2.0/Serializer'
import InternalSerializer from '../../src/serializers/internal/Serializer'

export const loaders = [
SwaggerLoader,
RAMLLoader
RAMLLoader,
PostmanV2Loader
]

export const parsers = [
SwaggerV2Parser,
RAMLV1Parser
RAMLV1Parser,
PostmanV2Parser
]

export const serializers = [
SwaggerV2Serializer,
RAMLV1Serializer,
InternalSerializer
InternalSerializer,
PostmanV2Serializer
]

export const environment = Environment
7 changes: 4 additions & 3 deletions src/loaders/internal/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ methods.parseJSON = (str) => {

methods.resolve = (options, uri, { $ref = '' } = {}) => {
const uriToLoad = resolve(uri, $ref)
if (parse(uriToLoad).protocol === 'file:') {
return options.fsResolver.resolve(uriToLoad.split('#')[0])
const protocol = parse(uriToLoad).protocol
if (protocol && protocol.substr(0, 4) === 'http') {
return options.httpResolver.resolve(uriToLoad.split('#')[0])
}

return options.httpResolver.resolve(uriToLoad.split('#')[0])
return options.fsResolver.resolve(uriToLoad.split('#')[0])
}


Expand Down
6 changes: 3 additions & 3 deletions src/loaders/postman/v2.0/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ methods.isParsable = (content) => {
methods.resolve = (options, uri, { $ref = '' } = {}) => {
const uriToLoad = resolve(uri, $ref)
const protocol = parse(uriToLoad).protocol
if (protocol === 'file:' || protocol === 'file') {
return options.fsResolver.resolve(uriToLoad.split('#')[0])
if (protocol && protocol.substr(0, 4) === 'http') {
return options.httpResolver.resolve(uriToLoad.split('#')[0])
}

return options.httpResolver.resolve(uriToLoad.split('#')[0])
return options.fsResolver.resolve(uriToLoad.split('#')[0])
}

methods.normalizeRequestItem = (item) => {
Expand Down
7 changes: 4 additions & 3 deletions src/loaders/swagger/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ methods.traverse = (content, { $ref = '#/' } = {}) => {

methods.resolve = (options, uri, { $ref = '' } = {}) => {
const uriToLoad = resolve(uri, $ref)
if (parse(uriToLoad).protocol === 'file:') {
return options.fsResolver.resolve(uriToLoad.split('#')[0])
const protocol = parse(uriToLoad).protocol
if (protocol && protocol.substr(0, 4) === 'http') {
return options.httpResolver.resolve(uriToLoad.split('#')[0])
}

return options.httpResolver.resolve(uriToLoad.split('#')[0])
return options.fsResolver.resolve(uriToLoad.split('#')[0])
}

methods.objectMap = (obj, func) => {
Expand Down
6 changes: 3 additions & 3 deletions src/loaders/template/v1.0/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ methods.isParsable = (content) => {
methods.resolve = (options, uri, { $ref = '' } = {}) => {
const uriToLoad = resolve(uri, $ref)
const protocol = parse(uriToLoad).protocol
if (protocol === 'file:' || protocol === 'file' || !protocol) {
return options.fsResolver.resolve(uriToLoad.split('#')[0])
if (protocol && protocol.substr(0, 4) === 'http') {
return options.httpResolver.resolve(uriToLoad.split('#')[0])
}

return options.httpResolver.resolve(uriToLoad.split('#')[0])
return options.fsResolver.resolve(uriToLoad.split('#')[0])
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/postman/v2.0/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ methods.addHostEntryToHostMap = (hostMap, { key, value }) => {
const hostname = key.get('hostname') ? key.get('hostname').generate(List([ '{{', '}}' ])) : ''
const port = key.get('port') ? ':' + key.get('port').generate(List([ '{{', '}}' ])) : ''
const host = hostname + port
const pathname = key.get('pathname').generate(List([ '{{', '}}' ]))
const pathname = key.get('pathname') ? key.get('pathname').generate(List([ '{{', '}}' ])) : ''

if (!hostMap[host]) {
hostMap[host] = { entries: [], lcPathname: pathname.split('/') }
Expand Down
19 changes: 19 additions & 0 deletions src/parsers/postman/v2.0/__tests__/Parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,13 @@ describe('parsers/postman/v2.0/Parser.js', () => {
variableDelimiters: List([ '{{', '}}', ':' ])
}),
value: 321
},
{
key: new URL({
url: 'staging.paw.cloud',
variableDelimiters: List([ '{{', '}}', ':' ])
}),
value: 123
}
]
const expected = {
Expand Down Expand Up @@ -1017,6 +1024,18 @@ describe('parsers/postman/v2.0/Parser.js', () => {
}
],
lcPathname: [ '', 'users', '321' ]
},
'staging.paw.cloud': {
entries: [
{
key: new URL({
url: 'staging.paw.cloud',
variableDelimiters: List([ '{{', '}}', ':' ])
}),
value: 123
}
],
lcPathname: [ '' ]
}
}

Expand Down
21 changes: 14 additions & 7 deletions src/serializers/paw/Serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,15 @@ methods.convertAuthIntoDynamicValue = (auth) => {
* @param {Environment} environment: the environment in which this auth value is applicable.
* @param {Auth} auth: the auth to add to the domain
* @param {string} key: the name of the auth
* @returns {EnvironmentVariable} the newly created environment variable.
* @returns {{ variable: EnvironmentVariable, auth: Auth }} the newly created environment variable.
*/
methods.addAuthToDomain = (domain, environment, auth, key) => {
const variable = domain.createEnvironmentVariable(key)
const dv = methods.convertAuthIntoDynamicValue(auth)
const ds = methods.wrapDV(dv)
variable.setValue(ds, environment)

return variable
return { variable, auth }
}

/**
Expand Down Expand Up @@ -1041,26 +1041,33 @@ methods.convertAuthFromReference = (store, reference) => {
* converts a reference or an auth into a DynamicString Entry.
* @param {Store} store: the store used to resolve references
* @param {Auth|Reference} authOrReference: the record to convert into a DynamicString
* @returns {DynamicString} the corresponding DynamicString
* @returns {{ variable: DynamicString, auth: Auth }} the corresponding DynamicString
*/
methods.convertReferenceOrAuthToDsEntry = (store, authOrReference) => {
if (authOrReference instanceof Reference) {
return methods.convertAuthFromReference(store, authOrReference)
}

const dv = methods.convertAuthIntoDynamicValue(authOrReference)
return methods.wrapDV(dv)
return { variable: methods.wrapDV(dv), auth: authOrReference }
}

// TODO create Variable DS that has enum with all auth possible
/**
* sets the Auth DynamicString as am Authorization Header.
* @param {PawRequest} pawRequest: the paw request to update
* @param {DynamicString} auth: the DynamicString representing an auth
* @param {Objecti} authData: the object containing the auth representation as a DynamicString and
* the original auth Record.
* @param {DynamicString} variable: the DynamicString representing an auth
* @param {Auth} auth: the original auth
* @returns {PawRequest} the update paw request
*/
methods.addAuthToRequest = (pawRequest, auth) => {
pawRequest.setHeader('Authorization', auth)
methods.addAuthToRequest = (pawRequest, { variable, auth }) => {
let authName = 'Authorization'
if (auth instanceof Auth.ApiKey) {
authName = auth.get('name')
}
pawRequest.setHeader(authName, variable)
return pawRequest
}

Expand Down
25 changes: 20 additions & 5 deletions src/serializers/paw/__tests__/Serializer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ describe('serializers/paw/Serializer.js', () => {
spyOn(__internals__, 'convertAuthIntoDynamicValue').andReturn(123)
spyOn(__internals__, 'wrapDV').andReturn('123')

const expected = variable
const expected = { variable, auth }
const actual = __internals__.addAuthToDomain(domain, environment, auth, key)

expect(domain.createEnvironmentVariable).toHaveBeenCalledWith(key)
Expand Down Expand Up @@ -2040,7 +2040,7 @@ describe('serializers/paw/Serializer.js', () => {
const store = new Store()
const auth = new Auth.Basic()

const expected = '123'
const expected = { variable: '123', auth }
const actual = __internals__.convertReferenceOrAuthToDsEntry(store, auth)

expect(actual).toEqual(expected)
Expand All @@ -2051,12 +2051,27 @@ describe('serializers/paw/Serializer.js', () => {
it('should work', () => {
const pawReq = { setHeader: () => {} }
spyOn(pawReq, 'setHeader').andReturn(123)
const auth = 'some dynamic string'
const authData = { variable: 'some dynamic string', auth: new Auth.Basic() }

const expected = pawReq
const actual = __internals__.addAuthToRequest(pawReq, authData)

expect(pawReq.setHeader).toHaveBeenCalledWith('Authorization', authData.variable)
expect(actual).toEqual(expected)
})

it('should work with ApiKeys custom headers', () => {
const pawReq = { setHeader: () => {} }
spyOn(pawReq, 'setHeader').andReturn(123)
const authData = {
variable: 'some dynamic string',
auth: new Auth.ApiKey({ name: 'X-Auth-Token' })
}

const expected = pawReq
const actual = __internals__.addAuthToRequest(pawReq, auth)
const actual = __internals__.addAuthToRequest(pawReq, authData)

expect(pawReq.setHeader).toHaveBeenCalledWith('Authorization', auth)
expect(pawReq.setHeader).toHaveBeenCalledWith('X-Auth-Token', authData.variable)
expect(actual).toEqual(expected)
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/postman/v2.0/Serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Auth from '../../../models/Auth'
import { convertEntryListInMap } from '../../../utils/fp-utils'

const __meta__ = {
format: 'postman',
format: 'postman-collection',
version: 'v2.0'
}

Expand Down