🚀 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.0.3

dist/openApi/v3/parser/getModelDefault.d.ts

1

dist/openApi/v2/parser/constants.d.ts
export declare enum PrimaryType {
FILE = "File",
OBJECT = "any",
ARRAY = "any",
BOOLEAN = "boolean",

@@ -5,0 +6,0 @@ NUMBER = "number",

3

dist/openApi/v2/parser/constants.js

@@ -7,2 +7,3 @@ "use strict";

PrimaryType["OBJECT"] = "any";
PrimaryType["ARRAY"] = "any";
PrimaryType["BOOLEAN"] = "boolean";

@@ -16,5 +17,5 @@ PrimaryType["NUMBER"] = "number";

['file', PrimaryType.FILE],
['binary', PrimaryType.FILE],
['any', PrimaryType.OBJECT],
['object', PrimaryType.OBJECT],
['array', PrimaryType.ARRAY],
['boolean', PrimaryType.BOOLEAN],

@@ -21,0 +22,0 @@ ['byte', PrimaryType.NUMBER],

@@ -22,3 +22,2 @@ "use strict";

description: getComment_1.getComment(parameter.description),
default: getOperationParameterDefault_1.getOperationParameterDefault(parameter.default),
isProperty: false,

@@ -41,2 +40,4 @@ isReadOnly: false,

operationParameter.imports.push(...definitionRef.imports);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -51,2 +52,4 @@ }

operationParameter.enum.push(...enumerators);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -62,2 +65,4 @@ }

operationParameter.enum.push(...enumerators);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -73,2 +78,4 @@ }

operationParameter.imports.push(...items.imports);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -84,2 +91,4 @@ }

operationParameter.imports.push('Dictionary');
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -95,2 +104,4 @@ }

operationParameter.imports.push(...model.imports);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -110,2 +121,4 @@ }

operationParameter.properties.push(...model.properties);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -122,2 +135,4 @@ }

operationParameter.imports.push(...definitionType.imports);
operationParameter.default = getOperationParameterDefault_1.getOperationParameterDefault(parameter, operationParameter);
operationParameter.isRequired = operationParameter.default || operationParameter.isRequired;
return operationParameter;

@@ -124,0 +139,0 @@ }

@@ -1,1 +0,3 @@

export declare function getOperationParameterDefault(value: any): string | null;
import { OpenApiParameter } from '../interfaces/OpenApiParameter';
import { OperationParameter } from '../../../client/interfaces/OperationParameter';
export declare function getOperationParameterDefault(parameter: OpenApiParameter, operationParameter: OperationParameter): string | null;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getOperationParameterDefault(value) {
if (value === null) {
function getOperationParameterDefault(parameter, operationParameter) {
if (parameter.default === null) {
return 'null';
}
switch (typeof value) {
switch (typeof parameter.default) {
case 'number':
if (operationParameter.export == 'enum' && operationParameter.enum.length && operationParameter.enum[parameter.default]) {
return operationParameter.enum[parameter.default].value;
}
return JSON.stringify(parameter.default);
case 'boolean':
return JSON.stringify(value);
return JSON.stringify(parameter.default);
case 'string':
return `'${value}'`;
return `'${parameter.default}'`;
case 'object':
try {
return JSON.stringify(parameter.default, null, 4);
}
catch (e) {
// Ignore
}
}

@@ -14,0 +25,0 @@ return null;

@@ -24,3 +24,8 @@ "use strict";

const match2 = getType(matches[2]);
if (match2.type) {
if (match1.type === constants_1.PrimaryType.ARRAY) {
result.type = `${match2.type}[]`;
result.base = `${match2.type}`;
match1.imports = [];
}
else if (match2.type) {
result.type = `${match1.type}<${match2.type}>`;

@@ -27,0 +32,0 @@ result.base = match1.type;

export declare enum PrimaryType {
FILE = "File",
OBJECT = "any",
ARRAY = "any[]",
BOOLEAN = "boolean",

@@ -5,0 +6,0 @@ NUMBER = "number",

@@ -7,2 +7,3 @@ "use strict";

PrimaryType["OBJECT"] = "any";
PrimaryType["ARRAY"] = "any[]";
PrimaryType["BOOLEAN"] = "boolean";

@@ -16,5 +17,5 @@ PrimaryType["NUMBER"] = "number";

['file', PrimaryType.FILE],
['binary', PrimaryType.FILE],
['any', PrimaryType.OBJECT],
['object', PrimaryType.OBJECT],
['array', PrimaryType.ARRAY],
['boolean', PrimaryType.BOOLEAN],

@@ -21,0 +22,0 @@ ['byte', PrimaryType.NUMBER],

@@ -7,2 +7,3 @@ "use strict";

const getEnumFromDescription_1 = require("./getEnumFromDescription");
const getModelDefault_1 = require("./getModelDefault");
const getModelProperties_1 = require("./getModelProperties");

@@ -36,2 +37,3 @@ const getType_1 = require("./getType");

model.imports.push(...definitionRef.imports);
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -46,2 +48,3 @@ }

model.enum.push(...enumerators);
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -57,2 +60,3 @@ }

model.enum.push(...enumerators);
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -69,2 +73,3 @@ }

model.imports.push(...arrayItems.imports);
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -80,2 +85,3 @@ }

model.imports.push(...arrayItems.imports);
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -93,2 +99,3 @@ }

model.imports.push('Dictionary');
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -105,2 +112,3 @@ }

model.imports.push('Dictionary');
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -113,2 +121,3 @@ }

model.base = constants_1.PrimaryType.OBJECT;
model.default = getModelDefault_1.getModelDefault(definition, model);
if (definition.allOf) {

@@ -153,2 +162,3 @@ definition.allOf.forEach(parent => {

model.imports.push(...definitionType.imports);
model.default = getModelDefault_1.getModelDefault(definition, model);
return model;

@@ -155,0 +165,0 @@ }

@@ -6,2 +6,3 @@ "use strict";

const getModel_1 = require("./getModel");
const getModelDefault_1 = require("./getModelDefault");
const getOperationParameterName_1 = require("./getOperationParameterName");

@@ -20,3 +21,2 @@ const getType_1 = require("./getType");

description: getComment_1.getComment(parameter.description),
default: undefined,
isProperty: false,

@@ -49,2 +49,3 @@ isReadOnly: false,

operationParameter.imports.push(...model.imports);
operationParameter.default = getModelDefault_1.getModelDefault(parameter.schema);
return operationParameter;

@@ -59,2 +60,3 @@ }

operationParameter.link = model.link;
operationParameter.default = model.default;
operationParameter.imports.push(...model.imports);

@@ -61,0 +63,0 @@ operationParameter.extends.push(...model.extends);

@@ -24,3 +24,8 @@ "use strict";

const match2 = getType(matches[2]);
if (match2.type) {
if (match1.type === constants_1.PrimaryType.ARRAY) {
result.type = `${match2.type}[]`;
result.base = `${match2.type}`;
match1.imports = [];
}
else if (match2.type) {
result.type = `${match1.type}<${match2.type}>`;

@@ -27,0 +32,0 @@ result.base = match1.type;

@@ -19,14 +19,14 @@ "use strict";

const fileName = getFileName_1.getFileName('index', language);
try {
fs.writeFileSync(path.resolve(outputPath, fileName), templates.index({
server: client.server,
version: client.version,
models: getModelNames_1.getModelNames(client.models),
services: getServiceNames_1.getServiceNames(client.services),
}));
}
catch (e) {
throw new Error(`Could not write index: "${fileName}"`);
}
// try {
console.log(fileName);
fs.writeFileSync(path.resolve(outputPath, fileName), templates.index({
server: client.server,
version: client.version,
models: getModelNames_1.getModelNames(client.models),
services: getServiceNames_1.getServiceNames(client.services),
}));
// } catch (e) {
// throw new Error(`Could not write index: "${fileName}"`);
// }
}
exports.writeClientIndex = writeClientIndex;

@@ -18,12 +18,12 @@ "use strict";

const fileName = getFileName_1.getFileName(model.name, language);
try {
const templateData = exportModel_1.exportModel(model);
const templateResult = templates.model(templateData);
fs.writeFileSync(path.resolve(outputPath, fileName), format_1.format(templateResult));
}
catch (e) {
throw new Error(`Could not write model: "${fileName}"`);
}
// try {
console.log(fileName);
const templateData = exportModel_1.exportModel(model);
const templateResult = templates.model(templateData);
fs.writeFileSync(path.resolve(outputPath, fileName), format_1.format(templateResult));
// } catch (e) {
// throw new Error(`Could not write model: "${fileName}"`);
// }
});
}
exports.writeClientModels = writeClientModels;

@@ -18,12 +18,12 @@ "use strict";

const fileName = getFileName_1.getFileName(service.name, language);
try {
const templateData = exportService_1.exportService(service);
const templateResult = templates.service(templateData);
fs.writeFileSync(path.resolve(outputPath, fileName), format_1.format(templateResult));
}
catch (e) {
throw new Error(`Could not write service: "${fileName}"`);
}
// try {
console.log(fileName);
const templateData = exportService_1.exportService(service);
const templateResult = templates.service(templateData);
fs.writeFileSync(path.resolve(outputPath, fileName), format_1.format(templateResult));
// } catch (e) {
// throw new Error(`Could not write service: "${fileName}"`);
// }
});
}
exports.writeClientServices = writeClientServices;
{
"name": "openapi-typescript-codegen",
"version": "0.0.2",
"version": "0.0.3",
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",

@@ -65,17 +65,17 @@ "author": "Ferdi Koomen",

"devDependencies": {
"@babel/core": "7.7.2",
"@babel/preset-env": "7.7.1",
"@babel/preset-typescript": "7.7.2",
"@babel/core": "7.7.4",
"@babel/preset-env": "7.7.4",
"@babel/preset-typescript": "7.7.4",
"@types/jest": "24.0.23",
"@types/js-yaml": "3.12.1",
"@types/mkdirp": "0.5.2",
"@types/node": "12.12.11",
"@types/node": "12.12.14",
"@types/rimraf": "2.0.3",
"@types/yup": "0.26.24",
"@typescript-eslint/eslint-plugin": "2.8.0",
"@typescript-eslint/parser": "2.8.0",
"@types/yup": "0.26.26",
"@typescript-eslint/eslint-plugin": "2.10.0",
"@typescript-eslint/parser": "2.10.0",
"camelcase": "5.3.1",
"chalk": "3.0.0",
"commander": "4.0.1",
"eslint": "6.6.0",
"eslint": "6.7.2",
"eslint-config-prettier": "6.7.0",

@@ -82,0 +82,0 @@ "eslint-plugin-prettier": "3.1.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet