Skip to content

Commit

Permalink
v0.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mittsh committed Jul 19, 2018
1 parent 643b703 commit b098c9c
Showing 1 changed file with 65 additions and 45 deletions.
110 changes: 65 additions & 45 deletions SwaggerGenerator.js
Expand Up @@ -13257,10 +13257,25 @@ methods.isPartOfBaseUrl = function (defaultUrl, defaultSecureUrl, urlPart) {
return defaultUrl.indexOf(urlPart) >= 0 || defaultSecureUrl.indexOf(urlPart) >= 0;
};

// NOTE: we assume that the urlPart is after the protocol
methods.findIntersection = function (defaultUrl, urlPart) {
var match = (defaultUrl + '####' + urlPart).match(/^.*?(.*)####\1(.*)$/);
/**
* finds the intersection between two strings, and returns the intersection, as well as the right-
* most exclusion. This is used to find the overlap between a host url and a part of a url
* associated with that host.
* @param {string} defaultUrl: the default url to test against.
* @param {string} defaultSecureUrl: the default secure url to test against.
* @param {string} urlPart: the part of url to test
* @returns {{ inside: string, outside: string }}
*
* Note: this assumes Paw only supports http and https.
* Note: this may work incorrectly if url is as follow: http://example.com/example.com/ (not tested)
*/
methods.findIntersection = function (defaultUrl, defaultSecureUrl, urlPart) {
var baseUrl = defaultUrl;
if (urlPart.match(/^[^:]*s:\/\//)) {
baseUrl = defaultSecureUrl;
}

var match = (baseUrl + '####' + urlPart).match(/^.*?(.*)####\1(.*)$/);
// always matches
return { inside: match[1], outside: match[2] };
};
Expand Down Expand Up @@ -13288,15 +13303,15 @@ methods.addComponentToBaseOrPath = function (defaultUrl, defaultSecureUrl, _ref5
var urlPart = _ref6.key,
component = _ref6.value;

if (methods.isPartOfBaseUrl(defaultUrl, defaultSecureUrl, urlPart)) {
if (pathComponents.length === 0 && methods.isPartOfBaseUrl(defaultUrl, defaultSecureUrl, urlPart)) {
// component is member of base url
baseComponents.push({ key: urlPart, value: component });
return { baseComponents: baseComponents, pathComponents: pathComponents };
}

if (pathComponents.length === 0) {
// component may be split between base url and path
var _methods$findIntersec = methods.findIntersection(defaultUrl, urlPart),
var _methods$findIntersec = methods.findIntersection(defaultUrl, defaultSecureUrl, urlPart),
inside = _methods$findIntersec.inside,
outside = _methods$findIntersec.outside;

Expand Down Expand Up @@ -13410,7 +13425,7 @@ methods.convertBaseComponentsIntoVariable = function (context, defaultHost, base

return new _Variable2.default({
name: defaultHost,
values: (0, _immutable.OrderedMap)(variableValues)
values: new _immutable.OrderedMap(variableValues)
});
};

Expand Down Expand Up @@ -13487,7 +13502,7 @@ methods.convertComponentEntryIntoStringOrParam = function (request, _ref12) {
return key;
}

var _methods$convertReque = methods.convertRequestVariableDVIntoParameter(request, 'path', (0, _immutable.List)(), value, key),
var _methods$convertReque = methods.convertRequestVariableDVIntoParameter(request, 'path', new _immutable.List(), value, key),
param = _methods$convertReque.value;

return param;
Expand Down Expand Up @@ -13579,7 +13594,7 @@ methods.createPathEndpoint = function (sequence) {
in: 'path',
type: 'string',
superType: 'sequence',
value: (0, _immutable.List)(sequence)
value: new _immutable.List(sequence)
})
});

Expand Down Expand Up @@ -13630,7 +13645,7 @@ methods.extractResourceFromPawRequest = function (context, reference, _ref13) {
value: new _Resource2.default({
name: (request.parent || {}).name || null,
description: (request.parent || {}).description || null,
endpoints: (0, _immutable.OrderedMap)(endpoints),
endpoints: new _immutable.OrderedMap(endpoints),
path: path,
methods: methods.extractRequestMapFromPawRequest(context, request, endpoints)
})
Expand Down Expand Up @@ -13676,7 +13691,7 @@ methods.createDefaultHostEndpoint = function (defaultHost, hostEntries) {
url: defaultUrl
});

var protocols = (0, _immutable.Set)(hostEntries.map(function (_ref14) {
var protocols = new _immutable.Set(hostEntries.map(function (_ref14) {
var urlObject = _ref14.urlObject;
return urlObject.protocol;
})).toList();
Expand Down Expand Up @@ -13769,7 +13784,7 @@ methods.isRequestVariableDynamicValue = function (component) {
* @returns {boolean} true if it only holds a request variable, false otherwise
*/
methods.isRequestVariableDS = function (ds) {
return ds.length === 1 && methods.isRequestVariableDynamicValue(ds.components[0]);
return ds && ds.length === 1 && methods.isRequestVariableDynamicValue(ds.components[0]);
};

/**
Expand Down Expand Up @@ -13813,7 +13828,7 @@ methods.convertRequestVariableDVIntoParameter = function (request, location, con
description: description || null,
required: required || false,
default: defaultValue,
constraints: (0, _immutable.List)([new _Constraint2.default.JSONSchema(schema)]),
constraints: new _immutable.List([new _Constraint2.default.JSONSchema(schema)]),
applicableContexts: contexts
});

Expand Down Expand Up @@ -13843,7 +13858,7 @@ methods.convertRequestVariableDSIntoParameter = function (request, location, con
* @returns {Parameter} the corresponding parameter
*/
methods.convertStandardDSIntoParameter = function (location, contexts, paramDS, paramName) {
var value = paramDS.getEvaluatedString();
var value = paramDS ? paramDS.getEvaluatedString() : '';
var param = new _Parameter2.default({
in: location,
key: paramName,
Expand Down Expand Up @@ -13897,12 +13912,12 @@ methods.isRequestBodyMultipart = function (request) {
* @returns {Array<Parameter>} the corresponding applicable contexts
*/
methods.getContentTypeContexts = function (contentType) {
return (0, _immutable.List)([new _Parameter2.default({
return new _immutable.List([new _Parameter2.default({
key: 'Content-Type',
name: 'Content-Type',
in: 'headers',
type: 'string',
constraints: (0, _immutable.List)([new _Constraint2.default.Enum([contentType])])
constraints: new _immutable.List([new _Constraint2.default.Enum([contentType])])
})]);
};

Expand Down Expand Up @@ -13937,15 +13952,15 @@ methods.createDefaultArrayParameter = function (contexts, name) {
* @returns {OrderedMap<string, Parameter>} the corresponding OrderedMap of body Parameters
*/
methods.createUrlEncodedOrMultipartBodyParameters = function (dsMap, contexts, request) {
var bodyParams = (0, _immutable.OrderedMap)(dsMap).map(function (value, name) {
var bodyParams = new _immutable.OrderedMap(dsMap).map(function (value, name) {
if (Array.isArray(value)) {
return methods.createDefaultArrayParameter(contexts, name);
}

return methods.convertParameterDynamicStringIntoParameter(request, 'body', contexts, value, name);
}).reduce(_fpUtils.convertEntryListInMap, {});

return (0, _immutable.OrderedMap)(bodyParams);
return new _immutable.OrderedMap(bodyParams);
};

/**
Expand Down Expand Up @@ -13981,15 +13996,15 @@ methods.createStandardBodyParameters = function (request) {
var bodyDS = request.getBody(true);

if (!bodyDS) {
return (0, _immutable.OrderedMap)();
return new _immutable.OrderedMap();
}

var _methods$convertParam = methods.convertParameterDynamicStringIntoParameter(request, 'body', (0, _immutable.List)(), bodyDS, null),
var _methods$convertParam = methods.convertParameterDynamicStringIntoParameter(request, 'body', new _immutable.List(), bodyDS, null),
key = _methods$convertParam.key,
value = _methods$convertParam.value;

var body = (0, _defineProperty3.default)({}, key, value);
return (0, _immutable.OrderedMap)(body);
return new _immutable.OrderedMap(body);
};

/**
Expand All @@ -14015,13 +14030,15 @@ methods.getBodyParameters = function (request) {
* @returns {OrderedMap<string, Parameter>} the corresponding OrderedMap of header parameters
*/
methods.getHeadersMapFromRequest = function (request) {
var extractHeaders = (0, _fpUtils.currify)(methods.convertParameterDynamicStringIntoParameter, request, 'headers', (0, _immutable.List)());
var extractHeaders = (0, _fpUtils.currify)(
// request, location, contexts, paramDS, paramName
methods.convertParameterDynamicStringIntoParameter, request, 'headers', new _immutable.List());

var headers = (0, _immutable.OrderedMap)(request.getHeaders(true)).filter(function (_, name) {
var headers = new _immutable.OrderedMap(request.getHeaders(true)).filter(function (_, name) {
return name !== 'Authorization';
}).map(extractHeaders).reduce(_fpUtils.convertEntryListInMap, {});

return (0, _immutable.OrderedMap)(headers);
return new _immutable.OrderedMap(headers);
};

/**
Expand All @@ -14030,11 +14047,11 @@ methods.getHeadersMapFromRequest = function (request) {
* @returns {OrderedMap<string, Parameter>} the corresponding OrderedMap of query parameters
*/
methods.getQueriesMapFromRequest = function (request) {
var extractUrlParams = (0, _fpUtils.currify)(methods.convertParameterDynamicStringIntoParameter, request, 'queries', (0, _immutable.List)());
var extractUrlParams = (0, _fpUtils.currify)(methods.convertParameterDynamicStringIntoParameter, request, 'queries', new _immutable.List());

var queryParams = (0, _immutable.OrderedMap)(request.getUrlParameters(true)).map(extractUrlParams).reduce(_fpUtils.convertEntryListInMap, {});
var queryParams = new _immutable.OrderedMap(request.getUrlParameters(true)).map(extractUrlParams).reduce(_fpUtils.convertEntryListInMap, {});

return (0, _immutable.OrderedMap)(queryParams);
return new _immutable.OrderedMap(queryParams);
};

/**
Expand Down Expand Up @@ -14169,12 +14186,12 @@ methods.getAuthNameFromAuth = function (context, request, authDS) {
methods.extractAuthReferencesFromRequest = function (context, request) {
var auth = request.getHeaderByName('Authorization', true);
if (!auth) {
return (0, _immutable.List)();
return new _immutable.List();
}

var authName = methods.getAuthNameFromAuth(context, request, auth);

return (0, _immutable.List)([new _Reference2.default({
return new _immutable.List([new _Reference2.default({
type: 'auth',
uuid: authName
})]);
Expand All @@ -14194,15 +14211,15 @@ methods.extractRequestMapFromPawRequest = function (context, pawReq, endpoints)

var request = new _Request2.default({
id: pawReq.id,
endpoints: (0, _immutable.OrderedMap)(endpoints),
endpoints: new _immutable.OrderedMap(endpoints),
name: pawReq.name,
description: pawReq.description,
method: method,
parameters: parameters,
auths: auths
});

return (0, _immutable.OrderedMap)((0, _defineProperty3.default)({}, method, request));
return new _immutable.OrderedMap((0, _defineProperty3.default)({}, method, request));
};

/**
Expand All @@ -14220,13 +14237,13 @@ methods.extractRequestMapFromPawRequest = function (context, pawReq, endpoints)
* @param {URL?} entry.endpoint: the endpoint associated with the host, if it exists
* @returns {object} acc, the updated accumulator
*/
methods.groupResourcesVariablesAndEndpoints = function (_ref16, _ref17) {
var resources = _ref16.resources,
variables = _ref16.variables,
endpoints = _ref16.endpoints;
var hostResources = _ref17.resources,
variable = _ref17.variable,
endpoint = _ref17.endpoint;
methods.groupResourcesVariablesAndEndpoints = function (_ref17, _ref18) {
var resources = _ref17.resources,
variables = _ref17.variables,
endpoints = _ref17.endpoints;
var hostResources = _ref18.resources,
variable = _ref18.variable,
endpoint = _ref18.endpoint;

if (variable) {
variables.push(variable);
Expand Down Expand Up @@ -14388,7 +14405,7 @@ methods.extractResources = function (context, reqs) {
variables = _hosts$map$reduce.variables,
endpoints = _hosts$map$reduce.endpoints;

var resourceMap = (0, _immutable.OrderedMap)(resources.reduce(_fpUtils.convertEntryListInMap, {}));
var resourceMap = new _immutable.OrderedMap(resources.reduce(_fpUtils.convertEntryListInMap, {}));

return { resources: resourceMap, variables: variables, endpoints: endpoints };
};
Expand All @@ -14406,14 +14423,14 @@ methods.extractStore = function (context, variables, endpoints, reqs) {
return request.getHeaderByName('Authorization', true);
}).map(function (request) {
return methods.extractAuthsFromRequest(context, request);
}).filter(function (_ref18) {
var key = _ref18.key;
}).filter(function (_ref19) {
var key = _ref19.key;
return !!key;
});

var variableStore = (0, _immutable.OrderedMap)(variables.reduce(_fpUtils.convertEntryListInMap, {}));
var endpointStore = (0, _immutable.OrderedMap)(endpoints.reduce(_fpUtils.convertEntryListInMap, {}));
var authStore = (0, _immutable.OrderedMap)(auths.reduce(_fpUtils.convertEntryListInMap, {}));
var variableStore = new _immutable.OrderedMap(variables.reduce(_fpUtils.convertEntryListInMap, {}));
var endpointStore = new _immutable.OrderedMap(endpoints.reduce(_fpUtils.convertEntryListInMap, {}));
var authStore = new _immutable.OrderedMap(auths.reduce(_fpUtils.convertEntryListInMap, {}));

var store = new _Store2.default({
variable: variableStore,
Expand Down Expand Up @@ -14453,8 +14470,8 @@ methods.extractResourcesAndStore = function (context, reqs) {
* @param {PawRequest} parserOptions.reqs: the array of requests to import
* @returns {Api} the corresponding Api
*/
methods.parse = function (_ref19) {
var options = _ref19.options;
methods.parse = function (_ref20) {
var options = _ref20.options;
var context = options.context,
reqs = options.reqs;

Expand Down Expand Up @@ -14986,6 +15003,9 @@ methods.getMostCommonEndpoint = function (api) {
* @return {string} the normalized protocol
*/
methods.removeDotsFromProtocol = function (protocol) {
if (!protocol) {
return null;
}
if (protocol[protocol.length - 1] === ':') {
return protocol.slice(0, protocol.length - 1);
}
Expand Down

0 comments on commit b098c9c

Please sign in to comment.