Gathering detailed insights and metrics for swagger-vue-codegen
Gathering detailed insights and metrics for swagger-vue-codegen
Gathering detailed insights and metrics for swagger-vue-codegen
Gathering detailed insights and metrics for swagger-vue-codegen
@tcatche/swagger-api
Swagger to axios api codegen, fork from https://github.com/Lvison/swagger-vue
@tcatche/swagger-vue
Swagger to JS & Vue & Axios Codegen,fork from https://github.com/Lvison/swagger-vue
@hey-api/client-fetch
🚀 Fetch API client for `@hey-api/openapi-ts` codegen.
swagger-vue
Swagger to JS & Vue & Axios Codegen
npm install swagger-vue-codegen
Typescript
Module System
Node Version
NPM Version
73.2
Supply Chain
97.1
Quality
74.5
Maintenance
100
Vulnerability
100
License
TypeScript (97.65%)
JavaScript (2.35%)
Total Downloads
3,249
Last Day
3
Last Week
17
Last Month
85
Last Year
877
MIT License
5 Stars
262 Commits
1 Forks
4 Branches
1 Contributors
Updated on Feb 21, 2025
Minified
Minified + Gzipped
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
Published on
Jun 26, 2023
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
0%
17
Compared to previous week
Last Month
51.8%
85
Compared to previous month
Last Year
-36.4%
877
Compared to previous year
4
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... ⭐️ ⭐️ ⭐️ ⭐️ ⭐️
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
1 2const { codegen } = require('swagger-axios-codegen') 3codegen({ 4 methodNameMode: 'operationId', 5 source: require('./swagger.json') 6}) 7 8
1 2const { codegen } = require('swagger-axios-codegen') 3codegen({ 4 methodNameMode: 'operationId', 5 remoteUrl:'You remote Url' 6}) 7 8
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
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
1import YourLib from '<Your lib>' 2import { serviceOptions } from './service' 3 4serviceOptions.axios = YourLib 5
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
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
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
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
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 More