Installations
npm install swagger-vue-codegen
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.14.2
NPM Version
8.5.0
Score
72.3
Supply Chain
97.1
Quality
74.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (97.65%)
JavaScript (2.35%)
Developer
jerrytang67
Download Statistics
Total Downloads
3,077
Last Day
2
Last Week
12
Last Month
110
Last Year
1,189
GitHub Statistics
4 Stars
262 Commits
1 Forks
1 Watching
4 Branches
1 Contributors
Bundle Size
5.91 MB
Minified
1.40 MB
Minified + Gzipped
Package Meta Information
Latest Version
0.15.11
Package Id
swagger-vue-codegen@0.15.11
Unpacked Size
262.59 kB
Size
51.76 kB
File Count
79
NPM Version
8.5.0
Node Version
16.14.2
Publised On
26 Jun 2023
Total Downloads
Cumulative downloads
Total Downloads
3,077
Last day
-75%
2
Compared to previous day
Last week
-52%
12
Compared to previous week
Last month
139.1%
110
Compared to previous month
Last year
26%
1,189
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
swagger-axios-codegen
A swagger client uses axios and typescript
require node > v8.0.0
it will always resolve axios.response.data
or reject axios.error
with Promise
support other similar to axios
library, for example Fly.js, required setting ISwaggerOptions.useCustomerRequestInstance = true
the es6 version is generated by calling typescript
Welcome PRs and commit issue
By the way. you can support this repo via Star star sta st s... ⭐️ ⭐️ ⭐️ ⭐️ ⭐️
Example
ChangeLog
Get Started
yarn add swagger-axios-codegen
1 2export interface ISwaggerOptions { 3 serviceNameSuffix?: string 4 enumNamePrefix?: string 5 methodNameMode?: 'operationId' | 'path' 6 outputDir?: string 7 fileName?: string 8 remoteUrl?: string 9 source?: any 10 useStaticMethod?: boolean | undefined 11 useCustomerRequestInstance?: boolean | undefined 12 include?: Array<string | IInclude> 13 format?: (s: string) => string 14 /** match with tsconfig */ 15 strictNullChecks?: boolean | undefined 16 /** definition Class mode */ 17 modelMode?: 'class' | 'interface' 18 /** use class-transformer to transform the results */ 19 useClassTransformer?: boolean, 20 // force the specified swagger or openAPI version, 21 openApi?: string | undefined, 22 // extend file url. It will be inserted in front of the service method 23 extendDefinitionFile?: string | undefined 24 // mark generic type 25 extendGenericType?: string[] | undefined 26} 27 28const defaultOptions: ISwaggerOptions = { 29 serviceNameSuffix: 'Service', 30 enumNamePrefix: 'Enum', 31 methodNameMode: 'operationId', 32 outputDir: './service', 33 fileName: 'index.ts', 34 useStaticMethod: true, 35 useCustomerRequestInstance: false, 36 include: [], 37 strictNullChecks: true, 38 /** definition Class mode ,auto use interface mode to streamlined code*/ 39 modelMode?: 'interface' 40 useClassTransformer: false 41} 42
use local swagger api json
1 2const { codegen } = require('swagger-axios-codegen') 3codegen({ 4 methodNameMode: 'operationId', 5 source: require('./swagger.json') 6}) 7 8
use remote swagger api json
1 2const { codegen } = require('swagger-axios-codegen') 3codegen({ 4 methodNameMode: 'operationId', 5 remoteUrl:'You remote Url' 6}) 7 8
use static method
1codegen({ 2 methodNameMode: 'operationId', 3 remoteUrl: 'http://localhost:22742/swagger/v1/swagger.json', 4 outputDir: '.', 5 useStaticMethod: true 6}); 7
before
1 2import { UserService } from './service' 3const userService = new UserService() 4await userService.GetAll(); 5
after
1 2import { UserService } from './service' 3 4await UserService.GetAll(); 5
use custom axios.instance
1import axios from 'axios' 2import { serviceOptions } from './service' 3const instance = axios.create({ 4 baseURL: 'https://some-domain.com/api/', 5 timeout: 1000, 6 headers: {'X-Custom-Header': 'foobar'} 7}); 8 9serviceOptions.axios = instance 10
use other library
1import YourLib from '<Your lib>' 2import { serviceOptions } from './service' 3 4serviceOptions.axios = YourLib 5
filter service and method
1 2let include = [ 3 'Products', // tagName 4 'Estimates',//tagName 5 { 'User': ['history'] } 6] 7codegen({ 8 methodNameMode: 'path', 9 source: require('../swagger.json'), 10 outputDir: './swagger/services', 11 include 12}) 13
use class transformer to transform results
This is helpful if you want to transform dates to real date
objects. Swagger can define string formats for different types. Two if these formats are date
and date-time
If a class-transformer
is enabled and a format is set on a string, the result string will be transformed to a Date
instance
// swagger.json
1{ 2 "ObjectWithDate": { 3 "type": "object", 4 "properties": { 5 "date": { 6 "type": "string", 7 "format": "date-time" 8 } 9 } 10 } 11}
1 2const { codegen } = require('swagger-axios-codegen') 3codegen({ 4 methodNameMode: 'operationId', 5 source:require('./swagger.json'), 6 useClassTransformer: true, 7})
Resulting class:
1export class ObjectWithDate { 2 @Expose() 3 @Type(() => Date) 4 public date: Date; 5}
The service method will transform the json response and return an instance of this class
use validation model
1codegen({ 2 ... 3 modelMode: 'class', 4 generateValidationModel: true 5});
The option above among with class model mode allows to render the model validation rules. The result of this will be as follows:
1export class FooFormVm { 2 'name'?: string; 3 'description'?: string; 4 5 constructor(data: undefined | any = {}) { 6 this['name'] = data['name']; 7 this['description'] = data['description']; 8 } 9 10 public static validationModel = { 11 name: { required: true, maxLength: 50 }, 12 description: { maxLength: 250 }, 13 }; 14}
So you can use the validation model in your application:
1function isRequired(vm: any, fieldName: string): boolean {
2 return (vm && vm[fieldName] && vm[fieldName].required === true);
3}
4function maxLength(vm: any, fieldName: string): number {
5 return (vm && vm[fieldName] && vm[fieldName].maxLength ? vm[fieldName].maxLength : 4000);
6}
Now you can use the functions
1var required = isRequired(FooFormVm.validationModel, 'name'); 2var maxLength = maxLength(FooFormVm.validationModel, 'description');
At the moment there are only two rules are supported - required
and maxLength
.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/jerrytang67/swagger-axios-codegen/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/jerrytang67/swagger-axios-codegen/nodejs.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:22
- Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:27
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
12 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-4w2v-q235-vp99
- Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Score
2.5
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreGathering detailed insights and metrics for swagger-vue-codegen