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
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.9.16 to 0.9.17

4

CHANGELOG.md
### 0.9.16
### 0.9.17
- fix: mergining imports (#88)
- fix: null check of swagger.json nodes
### 0.9.15

@@ -8,0 +8,0 @@

@@ -14,38 +14,39 @@ "use strict";

}
for (const [k, v] of Object.entries(definitions.schemas)) {
let className = utils_1.refClassName(k);
// 如果已经转为泛型类型,则不需要重新定义
if (utils_1.isGenerics(className))
continue;
let result = null;
// is an enum definition,just in swagger openAPI v2
if (v.enum) {
const enumDef = createDefinitionEnum_1.createDefinitionEnum(className, v.enum, v.type);
definitionEnums[`#/components/schemas/${k}`] = {
name: enumDef.name,
value: enumDef
};
}
else if (v.type === 'array') {
// #TODO
}
else {
// default definition generate
const { enums, model } = createDefinitionClass_1.createDefinitionClass(className, v.properties, v.required);
// console.log('createDefinitionClass', enums)
enums.forEach(item => {
// definitionModels[item.name] = {
// value: item.text
// }
definitionEnums[`#/components/schemas/${item.name}`] = {
name: item.name,
content: item.text
if (!!definitions)
for (const [k, v] of Object.entries(definitions.schemas)) {
let className = utils_1.refClassName(k);
// 如果已经转为泛型类型,则不需要重新定义
if (utils_1.isGenerics(className))
continue;
let result = null;
// is an enum definition,just in swagger openAPI v2
if (v.enum) {
const enumDef = createDefinitionEnum_1.createDefinitionEnum(className, v.enum, v.type);
definitionEnums[`#/components/schemas/${k}`] = {
name: enumDef.name,
value: enumDef
};
});
definitionModels[`#/components/schemas/${k}`] = {
value: model,
name: className
};
}
else if (v.type === 'array') {
// #TODO
}
else {
// default definition generate
const { enums, model } = createDefinitionClass_1.createDefinitionClass(className, v.properties, v.required);
// console.log('createDefinitionClass', enums)
enums.forEach(item => {
// definitionModels[item.name] = {
// value: item.text
// }
definitionEnums[`#/components/schemas/${item.name}`] = {
name: item.name,
content: item.text
};
});
definitionModels[`#/components/schemas/${k}`] = {
value: model,
name: className
};
}
}
}
return { models: definitionModels, enums: definitionEnums };

@@ -52,0 +53,0 @@ }

@@ -9,39 +9,40 @@ "use strict";

let definitionEnums = {};
for (const [k, v] of Object.entries(definitions)) {
let className = utils_1.refClassName(k);
// 如果已经转为泛型类型,则不需要重新定义
if (utils_1.isGenerics(className)) {
continue;
}
let result = null;
// is an enum definition,just in swagger openAPI v2
if (v.enum) {
const enumDef = createDefinitionEnum_1.createDefinitionEnum(className, v.enum, v.type);
definitionEnums[`#/definitions/${k}`] = {
name: enumDef.name,
value: enumDef
};
}
else if (v.type === 'array') {
// #TODO
}
else {
// default definition generate
const { enums, model } = createDefinitionClass_1.createDefinitionClass(className, v.properties, v.required);
// console.log('createDefinitionClass', enums)
enums.forEach(item => {
// definitionModels[item.name] = {
// value: item.text
// }
definitionEnums[`#/definitions/${item.name}`] = {
name: item.name,
content: item.text
if (!!definitions)
for (const [k, v] of Object.entries(definitions)) {
let className = utils_1.refClassName(k);
// 如果已经转为泛型类型,则不需要重新定义
if (utils_1.isGenerics(className)) {
continue;
}
let result = null;
// is an enum definition,just in swagger openAPI v2
if (v.enum) {
const enumDef = createDefinitionEnum_1.createDefinitionEnum(className, v.enum, v.type);
definitionEnums[`#/definitions/${k}`] = {
name: enumDef.name,
value: enumDef
};
});
definitionModels[`#/definitions/${k}`] = {
value: model,
name: className
};
}
else if (v.type === 'array') {
// #TODO
}
else {
// default definition generate
const { enums, model } = createDefinitionClass_1.createDefinitionClass(className, v.properties, v.required);
// console.log('createDefinitionClass', enums)
enums.forEach(item => {
// definitionModels[item.name] = {
// value: item.text
// }
definitionEnums[`#/definitions/${item.name}`] = {
name: item.name,
content: item.text
};
});
definitionModels[`#/definitions/${k}`] = {
value: model,
name: className
};
}
}
}
return { models: definitionModels, enums: definitionEnums };

@@ -48,0 +49,0 @@ }

@@ -14,84 +14,85 @@ "use strict";

const requestClasses = {};
for (const [path, request] of Object.entries(paths)) {
let methodName = utils_1.getMethodName(path);
for (const [method, reqProps] of Object.entries(request)) {
methodName = options.methodNameMode === 'operationId' ? reqProps.operationId : methodName;
const contentType = reqProps.consumes && reqProps.consumes.includes('multipart/form-data')
? 'multipart/form-data'
: 'application/json';
let formData = '';
let pathReplace = '';
// 获取类名
if (!reqProps.tags)
continue;
const className = camelcase_1.default(utils_1.RemoveSpecialCharacters(reqProps.tags[0]), { pascalCase: true });
if (className === '')
continue;
// 是否存在
if (!requestClasses[className]) {
requestClasses[className] = [];
}
let parameters = '';
let handleNullParameters = '';
let parsedParameters = {
requestParameters: ''
};
if (reqProps.parameters) {
// 获取到接口的参数
parsedParameters = getRequestParameters_1.getRequestParameters(reqProps.parameters);
formData = parsedParameters.requestFormData ? 'data = new FormData();\n' + parsedParameters.requestFormData : '';
pathReplace = parsedParameters.requestPathReplace;
}
let imports = parsedParameters.imports || [];
let parsedRequestBody = {};
if (reqProps.requestBody) {
parsedRequestBody = getRequestBody_1.getRequestBody(reqProps.requestBody);
// 合并imports
if (parsedParameters.imports) {
imports.push(...parsedRequestBody.imports);
if (!!paths)
for (const [path, request] of Object.entries(paths)) {
let methodName = utils_1.getMethodName(path);
for (const [method, reqProps] of Object.entries(request)) {
methodName = options.methodNameMode === 'operationId' ? reqProps.operationId : methodName;
const contentType = reqProps.consumes && reqProps.consumes.includes('multipart/form-data')
? 'multipart/form-data'
: 'application/json';
let formData = '';
let pathReplace = '';
// 获取类名
if (!reqProps.tags)
continue;
const className = camelcase_1.default(utils_1.RemoveSpecialCharacters(reqProps.tags[0]), { pascalCase: true });
if (className === '')
continue;
// 是否存在
if (!requestClasses[className]) {
requestClasses[className] = [];
}
parsedParameters.requestParameters = parsedParameters.requestParameters
? parsedParameters.requestParameters + parsedRequestBody.bodyType
: parsedRequestBody.bodyType;
}
parameters =
((_a = parsedParameters.requestParameters) === null || _a === void 0 ? void 0 : _a.length) > 0
? `params: {
let parameters = '';
let handleNullParameters = '';
let parsedParameters = {
requestParameters: ''
};
if (reqProps.parameters) {
// 获取到接口的参数
parsedParameters = getRequestParameters_1.getRequestParameters(reqProps.parameters);
formData = parsedParameters.requestFormData ? 'data = new FormData();\n' + parsedParameters.requestFormData : '';
pathReplace = parsedParameters.requestPathReplace;
}
let imports = parsedParameters.imports || [];
let parsedRequestBody = {};
if (reqProps.requestBody) {
parsedRequestBody = getRequestBody_1.getRequestBody(reqProps.requestBody);
// 合并imports
if (parsedParameters.imports) {
imports.push(...parsedRequestBody.imports);
}
parsedParameters.requestParameters = parsedParameters.requestParameters
? parsedParameters.requestParameters + parsedRequestBody.bodyType
: parsedRequestBody.bodyType;
}
parameters =
((_a = parsedParameters.requestParameters) === null || _a === void 0 ? void 0 : _a.length) > 0
? `params: {
${parsedParameters.requestParameters}
} = {} as any,`
: '';
const { responseType, isRef: refResponseType } = getResponseType_1.getResponseType(reqProps, isV3);
// 如果返回值也是引用类型,则加入到类的引用里面
// console.log('refResponseType', responseType, refResponseType)
if (refResponseType) {
imports.push(responseType);
: '';
const { responseType, isRef: refResponseType } = getResponseType_1.getResponseType(reqProps, isV3);
// 如果返回值也是引用类型,则加入到类的引用里面
// console.log('refResponseType', responseType, refResponseType)
if (refResponseType) {
imports.push(responseType);
}
parsedParameters.imports = imports;
// TODO 待优化,目前简单处理同名方法
let uniqueMethodName = camelcase_1.default(methodName);
var uniqueMethodNameReg = new RegExp(`^${uniqueMethodName}[0-9]*$`);
const methodCount = requestClasses[className].filter(item => uniqueMethodName === item.name || uniqueMethodNameReg.test(item.name)).length;
// console.log(uniqueMethodName, methodCount)
if (methodCount >= 1) {
uniqueMethodName = uniqueMethodName + methodCount;
// console.log(uniqueMethodName)
}
requestClasses[className].push({
name: uniqueMethodName,
operationId: uniqueMethodName,
requestSchema: {
summary: reqProps.summary,
path,
pathReplace,
parameters,
parsedParameters,
method,
contentType,
responseType,
formData,
requestBody: parsedRequestBody.bodyType
}
});
}
parsedParameters.imports = imports;
// TODO 待优化,目前简单处理同名方法
let uniqueMethodName = camelcase_1.default(methodName);
var uniqueMethodNameReg = new RegExp(`^${uniqueMethodName}[0-9]*$`);
const methodCount = requestClasses[className].filter(item => uniqueMethodName === item.name || uniqueMethodNameReg.test(item.name)).length;
// console.log(uniqueMethodName, methodCount)
if (methodCount >= 1) {
uniqueMethodName = uniqueMethodName + methodCount;
// console.log(uniqueMethodName)
}
requestClasses[className].push({
name: uniqueMethodName,
operationId: uniqueMethodName,
requestSchema: {
summary: reqProps.summary,
path,
pathReplace,
parameters,
parsedParameters,
method,
contentType,
responseType,
formData,
requestBody: parsedRequestBody.bodyType
}
});
}
}
return requestClasses;

@@ -98,0 +99,0 @@ }

{
"name": "swagger-axios-codegen",
"version": "0.9.16",
"version": "0.9.17",
"main": "./dist/index",

@@ -5,0 +5,0 @@ "typings": "./dist/",

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

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