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.8.3 to 0.9.0

.github/workflows/nodejs.yml

12

CHANGELOG.md
##0.9.0
- Support OpenApi3.0
## 0.8.3
- add docs for the `useClassTransformer` option by arkraft
- fix: useCustomerRequestInstance template by xxbld
- fix #48 by nbytes
## 0.8.1

@@ -3,0 +15,0 @@

2

dist/baseInterfaces.d.ts

@@ -19,2 +19,4 @@ export interface ISwaggerOptions {

useClassTransformer?: boolean;
openApi?: string | undefined;
extendFile?: string | undefined;
}

@@ -21,0 +23,0 @@ export interface IPropDef {

6

dist/componentsCodegen/index.js

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

const enumDef = createDefinitionEnum_1.createDefinitionEnum(className, v.enum, v.type);
definitionEnums[`#/definitions/${k}`] = {
definitionEnums[`#/components/schemas/${k}`] = {
name: enumDef.name,

@@ -32,3 +32,3 @@ value: enumDef,

// }
definitionEnums[`#/definitions/${item.name}`] = {
definitionEnums[`#/components/schemas/${item.name}`] = {
name: item.name,

@@ -38,3 +38,3 @@ content: item.text

});
definitionModels[`#/definitions/${k}`] = {
definitionModels[`#/components/schemas/${k}`] = {
value: model,

@@ -41,0 +41,0 @@ name: className

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

const utils_1 = require("./utils");
const componentsCodegen_1 = require("./componentsCodegen");
const defaultOptions = {

@@ -34,3 +35,3 @@ serviceNameSuffix: 'Service',

strictNullChecks: true,
useClassTransformer: false,
useClassTransformer: false
};

@@ -41,2 +42,3 @@ async function codegen(params) {

let swaggerSource;
// 获取接口定义文件
if (params.remoteUrl) {

@@ -65,2 +67,7 @@ const { data: swaggerJson } = await axios_1.default({ url: params.remoteUrl, responseType: 'text' });

: template_1.serviceHeader(options);
// 判断是否是openApi3.0或者swagger3.0
const isV3 = utils_1.isOpenApi3(params.openApi || swaggerSource.openapi || swaggerSource.openapi);
console.log('isV3', isV3);
let requestClasses = Object.entries(requestCodegen_1.requestCodegen(swaggerSource.paths));
const { models, enums } = isV3 ? componentsCodegen_1.componentsCodegen(swaggerSource.components) : definitionCodegen_1.definitionsCodeGen(swaggerSource.definitions);
// TODO: next next next time

@@ -102,6 +109,5 @@ // if (options.multipleFileMode) {

else if (options.include && options.include.length > 0) {
// 接口过滤入口
let reqSource = '';
let defSource = '';
let requestClasses = Object.entries(requestCodegen_1.requestCodegen(swaggerSource.paths));
const { models, enums } = definitionCodegen_1.definitionsCodeGen(swaggerSource.definitions);
let allModel = Object.values(models);

@@ -111,2 +117,3 @@ // console.log(allModel)

let allImport = [];
// 处理接口
options.include.forEach(item => {

@@ -150,2 +157,3 @@ let includeClassName = '';

});
// 处理类和枚举
allModel.forEach(item => {

@@ -180,4 +188,6 @@ if (allImport.includes(item.name)) {

else {
// 常规入口
try {
Object.entries(requestCodegen_1.requestCodegen(swaggerSource.paths)).forEach(([className, requests]) => {
// 处理接口
requestClasses.forEach(([className, requests]) => {
let text = '';

@@ -193,3 +203,3 @@ requests.forEach(req => {

});
const { models, enums } = definitionCodegen_1.definitionsCodeGen(swaggerSource.definitions);
// 处理类和枚举
Object.values(models).forEach(item => {

@@ -196,0 +206,0 @@ const text = params.modelMode === 'interface'

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

else if (p.schema.type) {
propType = p.schema.type;
propType = utils_1.toBaseType(p.schema.type);
}

@@ -53,0 +53,0 @@ else {

@@ -54,4 +54,10 @@ "use strict";

}
// TODO 待优化,目前简单处理同名方法
let uniqueMethodName = method + camelcase_1.default(methodName, { pascalCase: true });
const methodCount = requestClasses[className].filter(item => item.name === uniqueMethodName).length;
if (methodCount >= 1) {
uniqueMethodName = uniqueMethodName + (methodCount + 1);
}
requestClasses[className].push({
name: methodName,
name: uniqueMethodName,
operationId: reqProps.operationId,

@@ -58,0 +64,0 @@ requestSchema: {

export interface ISwaggerSource {
swagger: string;
swagger?: string | undefined;
openapi?: string | undefined;
info: string;

@@ -7,2 +8,3 @@ paths: IPaths;

definitions: IDefinitions;
components: IComponents;
externalDocs: string;

@@ -83,1 +85,9 @@ }

}
export interface IComponents {
schemas: {
[key: string]: IDefinition;
};
}
export interface IDictionary<T> {
[key: string]: T;
}

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

const { useClassTransformer } = options;
const { queryParameters = [], bodyParameter } = parsedParameters;
const { queryParameters = [], bodyParameter = [] } = parsedParameters;
const nonArrayType = responseType.replace('[', '').replace(']', '');

@@ -102,0 +102,0 @@ const isArrayType = responseType.indexOf('[') > 0;

@@ -22,1 +22,2 @@ import { IDefinitionClass, IDefinitionEnum } from "./baseInterfaces";

export declare function findDeepRefs(imports: string[], allDefinition: IDefinitionClass[], allEnums: IDefinitionEnum[]): string[];
export declare function isOpenApi3(version: string): boolean;

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

function isBaseType(s) {
return ['boolean', 'number', 'string', 'string', 'Date'].includes(s);
return ['boolean', 'number', 'string', 'string', 'Date', 'any'].includes(s);
}

@@ -63,2 +63,3 @@ exports.isBaseType = isBaseType;

case 'string':
case 'uuid':
switch (format) {

@@ -80,2 +81,5 @@ case 'date':

}
if (s === "integer") {
console.log(s, result);
}
return result;

@@ -128,2 +132,7 @@ }

exports.findDeepRefs = findDeepRefs;
function isOpenApi3(version) {
console.log('openApi version:', version);
return version.startsWith("3.", 0);
}
exports.isOpenApi3 = isOpenApi3;
//# sourceMappingURL=utils.js.map
{
"name": "swagger-axios-codegen",
"version": "0.8.3",
"version": "0.9.0",
"main": "./dist/index",

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

@@ -7,3 +7,2 @@ # swagger-axios-codegen

[![npm](https://img.shields.io/npm/dm/swagger-axios-codegen.svg)](https://www.npmjs.com/package/swagger-axios-codegen)
[![Build Status](https://dev.azure.com/manweill/swagger-axios-codegen/_apis/build/status/Manweill.swagger-axios-codegen?branchName=master)](https://dev.azure.com/manweill/swagger-axios-codegen/_build/latest?definitionId=1&branchName=master)
[![open issues](https://img.shields.io/github/issues-raw/manweill/swagger-axios-codegen.svg)](https://img.shields.io/github/issues-raw/manweill/swagger-axios-codegen.svg)

@@ -10,0 +9,0 @@

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

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