lib/converters/v1.0.0/converter-v1-to-v2.js
function (requestV1) {
        var queryParams = [],
            pathVariables = [],
            traversedVars = {},
            queryParamAltered,
            traversedQueryParams = {},
            parsed = util.urlparse(requestV1.url),
            retainEmpty = this.options.retainEmptyValues;

        // Merge query params
        _.forEach(requestV1.queryParams, function (queryParam) {
            (queryParam.enabled === false) && (queryParam.disabled = true);

            delete queryParam.enabled;

            util.cleanEmptyValue(queryParam, 'description', retainEmpty);

            if (_.has(queryParam, 'equals')) {
                if (queryParam.equals) {
                    (queryParam.value === null) && (queryParam.value = '');
                    queryParamAltered = true;
                }
                else {
                    // = is not appended when the value is null
                    (queryParam.value === '') && (queryParam.value = null);
                    queryParamAltered = true;
                }
                delete queryParam.equals;
            }

            queryParams.push(queryParam);
            traversedQueryParams[queryParam.key] = true;
        });
        // parsed query params are taken from the url, so no descriptions are available from them
        _.forEach(parsed.query, function (queryParam) {
            !traversedQueryParams[queryParam.key] && queryParams.push(queryParam);
        });

        // Merge path variables
        _.forEach(requestV1.pathVariableData, function (pathVariable) {
            pathVariable = _.clone(pathVariable);
            util.cleanEmptyValue(pathVariable, 'description', retainEmpty);

            pathVariables.push(pathVariable);
            traversedVars[pathVariable.key] = true;
        });
        // pathVariables in v1 are of the form  {foo: bar}, so no descriptions can be obtained from them
        _.forEach(requestV1.pathVariables, function (value, id) {
            !traversedVars[id] && pathVariables.push({
                value: value,
                id: id
            });
        });

        !_.isEmpty(queryParams) && (parsed.query = queryParams);
        !_.isEmpty(pathVariables) && (parsed.variable = pathVariables);

        // If the query params have been altered, update the raw stringified URL
        queryParamAltered && (parsed.raw = util.urlunparse(parsed));

        // return the objectified URL only if query param or path variable descriptions are present, string otherwise
        return (parsed.query || parsed.variable) ? parsed : (parsed.raw || requestV1.url);
    }
function (requestV1) {
        var queryParams = [],
            pathVariables = [],
            traversedVars = {},
            queryParamAltered,
            traversedQueryParams = {},
            parsed = util.urlparse(requestV1.url),
            retainEmpty = this.options.retainEmptyValues;

        // Merge query params
        _.forEach(requestV1.queryParams, function (queryParam) {
            (queryParam.enabled === false) && (queryParam.disabled = true);

            delete queryParam.enabled;

            util.cleanEmptyValue(queryParam, 'description', retainEmpty);

            if (_.has(queryParam, 'equals')) {
                if (queryParam.equals) {
                    (queryParam.value === null) && (queryParam.value = '');
                    queryParamAltered = true;
                }
                else {
                    // = is not appended when the value is null
                    (queryParam.value === '') && (queryParam.value = null);
                    queryParamAltered = true;
                }
                delete queryParam.equals;
            }

            queryParams.push(queryParam);
            traversedQueryParams[queryParam.key] = true;
        });
        // parsed query params are taken from the url, so no descriptions are available from them
        _.forEach(parsed.query, function (queryParam) {
            !traversedQueryParams[queryParam.key] && queryParams.push(queryParam);
        });

        // Merge path variables
        _.forEach(requestV1.pathVariableData, function (pathVariable) {
            pathVariable = _.clone(pathVariable);
            util.cleanEmptyValue(pathVariable, 'description', retainEmpty);

            pathVariables.push(pathVariable);
            traversedVars[pathVariable.key] = true;
        });
        // pathVariables in v1 are of the form  {foo: bar}, so no descriptions can be obtained from them
        _.forEach(requestV1.pathVariables, function (value, id) {
            !traversedVars[id] && pathVariables.push({
                value: value,
                id: id
            });
        });

        !_.isEmpty(queryParams) && (parsed.query = queryParams);
        !_.isEmpty(pathVariables) && (parsed.variable = pathVariables);

        // If the query params have been altered, update the raw stringified URL
        queryParamAltered && (parsed.raw = util.urlunparse(parsed));

        // return the objectified URL only if query param or path variable descriptions are present, string otherwise
        return (parsed.query || parsed.variable) ? parsed : (parsed.raw || requestV1.url);
    }
function ( requestV1 ) { var queryParams = [ ] , pathVariables = [ ] , traversedVars = { } , queryParamAltered , traversedQueryParams = { } , parsed = util . urlparse ( requestV1 . url ) , retainEmpty = this . options . retainEmptyValues ; // Merge query params _ . forEach ( requestV1 . queryParams , function ( queryParam ) { ( queryParam . enabled === false ) && ( queryParam . disabled = true ) ; delete queryParam . enabled ; util . cleanEmptyValue ( queryParam , 'description' , retainEmpty ) ; if ( _ . has ( queryParam , 'equals' ) ) { if ( queryParam . equals ) { ( queryParam . value === null ) && ( queryParam . value = '' ) ; queryParamAltered = true ; } else { // = is not appended when the value is null ( queryParam . value === '' ) && ( queryParam . value = null ) ; queryParamAltered = true ; } delete queryParam . equals ; } queryParams . push ( queryParam ) ; traversedQueryParams [ queryParam . key ] = true ; } ) ; // parsed query params are taken from the url, so no descriptions are available from them _ . forEach ( parsed . query , function ( queryParam ) { ! traversedQueryParams [ queryParam . key ] && queryParams . push ( queryParam ) ; } ) ; // Merge path variables _ . forEach ( requestV1 . pathVariableData , function ( pathVariable ) { pathVariable = _ . clone ( pathVariable ) ; util . cleanEmptyValue ( pathVariable , 'description' , retainEmpty ) ; pathVariables . push ( pathVariable ) ; traversedVars [ pathVariable . key ] = true ; } ) ; // pathVariables in v1 are of the form  {foo: bar}, so no descriptions can be obtained from them _ . forEach ( requestV1 . pathVariables , function ( value , id ) { ! traversedVars [ id ] && pathVariables . push ( { value : value , id : id } ) ; } ) ; ! _ . isEmpty ( queryParams ) && ( parsed . query = queryParams ) ; ! _ . isEmpty ( pathVariables ) && ( parsed . variable = pathVariables ) ; // If the query params have been altered, update the raw stringified URL queryParamAltered && ( parsed . raw = util . urlunparse ( parsed ) ) ; // return the objectified URL only if query param or path variable descriptions are present, string otherwise return ( parsed . query || parsed . variable ) ? parsed : ( parsed . raw || requestV1 . url ) ; }
Constructs a V2 compatible URL object from a V1 request

@param {Object} requestV1 - The source v1 request to extract the URL from.
@returns {String|Object} - The resultant URL.
Constructs a V2 compatible URL object from a V1 request