New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swagger-axios-codegen

Package Overview
Dependencies
Maintainers
1
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-axios-codegen - npm Package Compare versions

Comparing version

to
0.1.6

1

dist/baseInterfaces.d.ts

@@ -80,2 +80,3 @@ export interface ISwaggerOptions {

items: IDefinitionProperty;
description: string;
}

70

dist/definitionCodegen.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const camelcase_1 = __importDefault(require("camelcase"));
function propTrueType(v, isGenericType) {
let propType = '';
let isEnum = false;
if (v.$ref) {

@@ -27,3 +32,6 @@ // 是引用类型

else if (v.enum) {
propType = v.type === 'string' ? v.enum.map(item => `'${item}'`).join('|') : v.enum.join('|');
isEnum = true;
propType = v.type === 'string' ?
v.enum.map(item => `${item}='${item}'`).join(',') :
v.enum.map(item => `${item}=${item}`).join(',');
}

@@ -34,3 +42,3 @@ // 基本类型

}
return propType;
return { propType, isEnum };
}

@@ -47,31 +55,20 @@ /**

let genericsType = '';
/** 枚举值 */
let enums = [];
const propertiesEntities = Object.entries(properties);
for (const [k, v] of propertiesEntities) {
let propType = propTrueType(v, isGenericType);
// if (v.$ref) {
// // 是引用类型
// propType = refClassName(v.$ref)
// }
// //是个数组
// else if (v.items) {
// if (v.items.$ref) {
// // 是个引用类型
// propType = isGenericType ? 'T[]' : refClassName(v.items.$ref) + '[]'
// } else {
// propType = toBaseType(v.items.type) + '[]'
// }
// }
// // 是个枚举
// else if (v.enum) {
// propType = v.type === 'string' ? v.enum.map(item => `'${item}'`).join('|') : v.enum.join('|')
// }
// // 基本类型
// else {
// propType = isGenericType && propertiesEntities.length === 1 ? 'T' : toBaseType(v.type)
// }
let { propType, isEnum } = propTrueType(v, isGenericType);
if (isEnum) {
let enumName = `Enum${className}${camelcase_1.default(k, { pascalCase: true })}`;
enums.push({
name: enumName, text: `export enum ${enumName}{
${propType}
}`
});
propType = enumName;
}
propsStr += `
/**
*
* ${v.description}
* @type {${propType}}
* @memberof ${className}
*/

@@ -81,2 +78,3 @@ ${k}:${propType};\n

constructorStr += `this['${k}'] = data['${k}'];\n`;
// 判断是不是泛型类型
genericsType = isGenericType

@@ -88,3 +86,5 @@ ? hasDefaultGenericType && propertiesEntities.length

}
return `
return {
enums,
model: `
export class ${className}${genericsType} {

@@ -98,3 +98,4 @@ ${propsStr}

}
`;
`
};
}

@@ -121,5 +122,16 @@ function definitionsCodeGen(definitions) {

let className = utils_1.refClassName(k);
const { enums, model } = createDefinitionClass(className, v.properties);
enums.forEach(item => {
definitionsModels[item.name] = {
isGeneric: false,
value: item.text
};
});
if (className == 'ChatMessageDto') {
console.log(className, enums);
// console.log('definitionsModels', definitionsModels);
}
definitionsModels[k] = {
isGeneric: false,
value: createDefinitionClass(className, v.properties)
value: model
};

@@ -126,0 +138,0 @@ // }

{
"name": "swagger-axios-codegen",
"version": "0.1.5",
"version": "0.1.6",
"main": "./dist/index",

@@ -13,3 +13,4 @@ "typings": "./dist/",

"scripts": {
"prestart": "tsc -p ./src",
"build": "tsc -p ./src",
"prestart": "npm run build",
"precommit": "prettier --write --config .prettierrc ./src/*.ts",

@@ -26,5 +27,5 @@ "start": "node ./dist/index"

"@types/node": "^9.6.0",
"@types/prettier": "^1.12.0",
"@types/prettier": "^1.12.2",
"typescript": "^2.8.1"
}
}