Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-axios-codegen

Package Overview
Dependencies
Maintainers
1
Versions
149
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 0.2.5 to 0.2.6

dist/template.d.ts

5

.vscode/settings.json
{
"editor.formatOnSave": true
"editor.formatOnSave": true,
"cSpell.words": [
"codegen"
]
}

3

CHANGELOG.md

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

## 0.2.6
- 调整生成的class name的名称
## 0.2.5
- 使用 `Promise` 代替 `AxiosPromise`。如果接口调用成功,默认返回response.data
- 修改README.md

@@ -48,9 +48,3 @@ export interface ISwaggerOptions {

required: string;
schema: {
$ref: string;
items: {
type: string;
$ref: string;
};
};
schema: IParameterSchema;
items: {

@@ -63,2 +57,11 @@ type: string;

}
export interface IParameterSchema {
$ref: string;
items?: IParameterItems;
}
export interface IParameterItems {
type?: string;
$ref: string;
item?: IParameterItems;
}
export interface IDefinitions {

@@ -65,0 +68,0 @@ [key: string]: IDefinition;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
import { IDefinitions } from './baseInterfaces';
export interface IDefinitionsClasses {
[key: string]: {
isGeneric: boolean;
value: string;

@@ -6,0 +5,0 @@ };

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

const pascalcase_1 = __importDefault(require("pascalcase"));
function propTrueType(v, isGenericType) {
function propTrueType(v) {
let propType = '';

@@ -24,3 +24,3 @@ let isEnum = false;

if (v.items.type === "array") {
propType = propTrueType(v.items, isGenericType) + '[]';
propType = propTrueType(v.items) + '[]';
}

@@ -52,3 +52,3 @@ else {

*/
function createDefinitionClass(className, properties, isGenericType = false, hasDefaultGenericType = false) {
function createDefinitionClass(className, properties) {
let propsStr = '';

@@ -61,3 +61,3 @@ let constructorStr = '';

for (const [k, v] of propertiesEntities) {
let { propType, isEnum } = propTrueType(v, isGenericType);
let { propType, isEnum } = propTrueType(v);
if (isEnum) {

@@ -77,8 +77,2 @@ let enumName = `Enum${className}${pascalcase_1.default(k)}`;

constructorStr += `this['${k}'] = data['${k}'];\n`;
// 判断是不是泛型类型
genericsType = isGenericType
? hasDefaultGenericType && propertiesEntities.length
? `<T=${utils_1.toBaseType(v.type)}>`
: '<T>'
: '';
}

@@ -88,3 +82,3 @@ return {

model: `
export class ${className}${genericsType} {
export class ${className} {
${propsStr}

@@ -103,18 +97,2 @@ constructor(data?:any){

for (const [k, v] of Object.entries(definitions)) {
// 是否是泛型类型 PagedResultDto[UserListDto]
// if (isGenerics(k) && v.type === 'object') {
// const { interfaceClassName, TClassName } = getGenericsClassNames(k)
// // if (definitionsModels[interfaceClassName] == null) {
// definitionsModels[interfaceClassName] = {
// isGeneric: true,
// value: createDefinitionClass(interfaceClassName, v.properties, true)
// }
// // }
// } else {
// if (definitionsModels[k] && definitionsModels[k].isGeneric) {
// definitionsModels[k] = {
// isGeneric: true,
// value: createDefinitionClass(k, v.properties, true, true)
// }
// } else {
let className = utils_1.refClassName(k);

@@ -124,3 +102,2 @@ const { enums, model } = createDefinitionClass(className, v.properties);

definitionsModels[item.name] = {
isGeneric: false,
value: item.text

@@ -130,7 +107,4 @@ };

definitionsModels[k] = {
isGeneric: false,
value: model
};
// }
// }
}

@@ -137,0 +111,0 @@ let definitionsClasses = Object.values(definitionsModels)

import { ISwaggerOptions } from './baseInterfaces';
export declare function codegen(params: ISwaggerOptions): Promise<void>;

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { IPaths, ISwaggerOptions } from './baseInterfaces';

@@ -0,0 +0,0 @@ "use strict";

@@ -18,1 +18,2 @@ export declare const GENERIC_SPLIT_KEY = "[";

export declare function getMethodName(path: string): string;
export declare function trimString(str: string, char: string, type: string): string;

@@ -28,3 +28,3 @@ "use strict";

// return `${interfaceClassName}<${toBaseType(TClassName)}>`
return propType.replace(/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/g, '');
return trimString(propType.replace(/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/g, '_'), '_', 'right');
}

@@ -74,1 +74,15 @@ else {

exports.getMethodName = getMethodName;
function trimString(str, char, type) {
if (char) {
if (type == 'left') {
return str.replace(new RegExp('^\\' + char + '+', 'g'), '');
}
else if (type == 'right') {
return str.replace(new RegExp('\\' + char + '+$', 'g'), '');
}
return str.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), '');
}
return str.replace(/^\s+|\s+$/g, '');
}
exports.trimString = trimString;
;
{
"name": "swagger-axios-codegen",
"version": "0.2.5",
"version": "0.2.6",
"main": "./dist/index",

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

"precommit": "prettier --write --config .prettierrc ./src/*.ts",
"start": "node ./dist/index"
"start": "node ./dist/index",
"watch": "tsc --watch -p ./src "
},

@@ -29,4 +30,5 @@ "dependencies": {

"@types/prettier": "^1.12.2",
"typescript": "^2.8.3"
"tslint": "^5.10.0",
"typescript": "^2.9.1"
}
}

@@ -7,5 +7,7 @@ # swagger-axios-codegen

it will always resolve `axios.response.data` or reject `axios.error` with Promise
## Get Started
[Example](./test)
[Example](./example)

@@ -96,1 +98,3 @@ ```

```
Welcome PR an commit issue

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc