🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

openapi-typescript-codegen

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-typescript-codegen - npm Package Compare versions

Comparing version

to
0.1.12

14

package.json
{
"name": "openapi-typescript-codegen",
"version": "0.1.11",
"version": "0.1.12",
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",

@@ -64,5 +64,5 @@ "author": "Ferdi Koomen",

"devDependencies": {
"@babel/core": "7.8.0",
"@babel/preset-env": "7.8.2",
"@babel/preset-typescript": "7.8.0",
"@babel/core": "7.8.3",
"@babel/preset-env": "7.8.3",
"@babel/preset-typescript": "7.8.3",
"@types/jest": "24.0.25",

@@ -73,4 +73,4 @@ "@types/js-yaml": "3.12.1",

"@types/rimraf": "2.0.3",
"@typescript-eslint/eslint-plugin": "2.15.0",
"@typescript-eslint/parser": "2.15.0",
"@typescript-eslint/eslint-plugin": "2.16.0",
"@typescript-eslint/parser": "2.16.0",
"camelcase": "5.3.1",

@@ -85,3 +85,3 @@ "chalk": "3.0.0",

"glob": "7.1.6",
"handlebars": "4.7.1",
"handlebars": "4.7.2",
"jest": "24.9.0",

@@ -88,0 +88,0 @@ "jest-cli": "24.9.0",

@@ -9,2 +9,28 @@ /* istanbul ignore file */

/**
* Try to parse the content for any response status code.
* We check the "Content-Type" header to see if we need to parse the
* content as json or as plain text.
* @param response Response object from fetch
*/
async function parseBody(response: Response): Promise<any> {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return await response.json();
default:
return await response.text();
}
}
} catch (e) {
console.error(e);
}
return null;
}
/**
* Request content using the new Fetch API. This is the default API that is used and

@@ -22,3 +48,3 @@ * is create for all JSON, XML and text objects. However it is limited to UTF-8.

// Create result object.
const result: Result = {
return {
url,

@@ -28,26 +54,4 @@ ok: response.ok,

statusText: response.statusText,
body: null,
body: await parseBody(response),
};
// Try to parse the content for any response status code.
// We check the "Content-Type" header to see if we need to parse the
// content as json or as plain text.
const contentType = response.headers.get('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
result.body = await response.json();
break;
case 'text/plain':
case 'text/xml':
case 'text/xml; charset=utf-8':
case 'text/xml; charset=utf-16':
result.body = await response.text();
break;
}
}
return result;
}

@@ -6,6 +6,32 @@ /* istanbul ignore file */

import { isSuccess } from './isSuccess';
import { Result } from './Result';
import { isSuccess } from './isSuccess';
/**
* Try to parse the content for any response status code.
* We check the "Content-Type" header to see if we need to parse the
* content as json or as plain text.
* @param xhr XHR request object
*/
function parseBody(xhr: XMLHttpRequest): any {
try {
const contentType = xhr.getResponseHeader('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
return JSON.parse(xhr.responseText);
default:
return xhr.responseText;
}
}
} catch (e) {
console.error(e);
}
return null;
}
/**
* Request content using the new legacy XMLHttpRequest API. This method is useful

@@ -42,25 +68,6 @@ * when we want to request UTF-16 content, since it natively supports loading UTF-16.

statusText: xhr.statusText,
body: null,
body: parseBody(xhr),
};
// Try to parse the content for any response status code.
// We check the "Content-Type" header to see if we need to parse the
// content as json or as plain text.
const contentType = xhr.getResponseHeader('Content-Type');
if (contentType) {
switch (contentType.toLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
result.body = JSON.parse(xhr.responseText);
break;
case 'text/plain':
case 'text/xml':
case 'text/xml; charset=utf-8':
case 'text/xml; charset=utf-16':
result.body = xhr.responseText;
break;
}
}
// Done!

@@ -67,0 +74,0 @@ resolve(result);