Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@odit/swagger-axios-codegen
Advanced tools
A swagger client using axios and typescript
it will always resolve axios.response.data
or reject axios.error
with Promise
pnpm i -D @odit/swagger-axios-codegen
export interface ISwaggerOptions {
/** service name suffix eg. 'Service' **/
serviceNameSuffix?: string
/** enum prefix eg. 'Enum' **/
enumNamePrefix?: string
methodNameMode?: 'operationId' | 'path'
/** path of the generated file eg. './src/service' **/
outputDir?: string
/** generated file name eg. 'index.ts' **/
fileName?: string
/** path to remote source file eg. 'https://localhost:8080/api/v1/swagger.json' **/
remoteUrl?: string
/** path to local source file eg. './swagger.json' **/
source?: any
useStaticMethod?: boolean | undefined
/** client can pass custom headers to the service methods **/
useCustomerRequestInstance?: boolean | undefined
/** filter by service name (first tag) or method name using multimatch (https://github.com/sindresorhus/multimatch) **/
include?: Array<string | IInclude>
/** include extra types which are not included during the filtering Eg. ["Foo", "Bar"] **/
includeTypes?: Array<string>
/** filter urls by following clauses **/
urlFilters?: Array<string>
/** custom function to format the output file (default: prettier.format()) **/
format?: (s: string) => string
/** match with tsconfig */
strictNullChecks?: boolean | undefined
/** definition Class mode */
modelMode?: 'class' | 'interface'
/** use class-transformer to transform the results */
useClassTransformer?: boolean,
// force the specified swagger or openAPI version,
openApi?: string | undefined,
// extend file url. It will be inserted in front of the service method
extendDefinitionFile?: string | undefined
// mark generic type
extendGenericType?: string[] | undefined
/** split request service. Can't use with sharedServiceOptions*/
multipleFileMode?: boolean | undefined
/** shared service options to multiple service. Can't use with MultipleFileMode */
sharedServiceOptions?: boolean | undefined
}
const defaultOptions: ISwaggerOptions = {
serviceNameSuffix: 'Service',
enumNamePrefix: 'Enum',
methodNameMode: 'operationId',
outputDir: './service',
fileName: 'index.ts',
useStaticMethod: true,
useCustomerRequestInstance: false,
include: [],
strictNullChecks: true,
/** definition Class mode ,auto use interface mode to streamlined code*/
modelMode?: 'interface',
useClassTransformer: false
}
const { codegen } = require('@odit/swagger-axios-codegen')
codegen({
methodNameMode: 'operationId',
source: require('./swagger.json')
})
const { codegen } = require('@odit/swagger-axios-codegen')
codegen({
methodNameMode: 'operationId',
remoteUrl:'You remote Url'
})
codegen({
methodNameMode: 'operationId',
remoteUrl: 'http://localhost:22742/swagger/v1/swagger.json',
outputDir: '.',
useStaticMethod: true
});
before
import { UserService } from './service'
const userService = new UserService()
await userService.GetAll();
after
import { UserService } from './service'
await UserService.GetAll();
import axios from 'axios'
import { serviceOptions } from './service'
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
serviceOptions.axios = instance
FAQs
A swagger client using axios and typescript
The npm package @odit/swagger-axios-codegen receives a total of 20 weekly downloads. As such, @odit/swagger-axios-codegen popularity was classified as not popular.
We found that @odit/swagger-axios-codegen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.