-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
115 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Printer } from '../../src/printer'; | ||
|
||
it('axios 模块导入名称默认', () => { | ||
const printer = new Printer({ | ||
openapi: '3.1.0', | ||
info: { | ||
title: 'test', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/': { | ||
get: {}, | ||
}, | ||
}, | ||
}, { | ||
}); | ||
expect(printer.print({ | ||
hideInfo: true, | ||
hideHelpers: true, | ||
})).toMatchInlineSnapshot(` | ||
"import {axios as axios} from "axios"; | ||
import type {AxiosRequestConfig, AxiosPromise} from "axios"; | ||
/** | ||
* @param [config] request config | ||
*/ | ||
export async function get_2(config?:AxiosRequestConfig): AxiosPromise<unknown> { | ||
return axios({ | ||
method: "get", | ||
url: \`/\`, | ||
...config | ||
}); | ||
}" | ||
`); | ||
}); | ||
|
||
it('axios 模块导入名称指定', () => { | ||
const printer = new Printer({ | ||
openapi: '3.1.0', | ||
info: { | ||
title: 'test', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/': { | ||
get: {}, | ||
}, | ||
}, | ||
}, { | ||
axiosImportName: 'axios2', | ||
}); | ||
expect(printer.print({ | ||
hideInfo: true, | ||
hideHelpers: true, | ||
})).toMatchInlineSnapshot(` | ||
"import {axios2 as axios} from "axios"; | ||
import type {AxiosRequestConfig, AxiosPromise} from "axios"; | ||
/** | ||
* @param [config] request config | ||
*/ | ||
export async function get_2(config?:AxiosRequestConfig): AxiosPromise<unknown> { | ||
return axios({ | ||
method: "get", | ||
url: \`/\`, | ||
...config | ||
}); | ||
}" | ||
`); | ||
}); | ||
|
||
it('axios 默认导入名称为空', () => { | ||
const printer = new Printer({ | ||
openapi: '3.1.0', | ||
info: { | ||
title: 'test', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/': { | ||
get: {}, | ||
}, | ||
}, | ||
}, { | ||
axiosImportName: '', | ||
}); | ||
expect(printer.print({ | ||
hideInfo: true, | ||
hideHelpers: true, | ||
})).toMatchInlineSnapshot(` | ||
"import axios from "axios"; | ||
import type {AxiosRequestConfig, AxiosPromise} from "axios"; | ||
/** | ||
* @param [config] request config | ||
*/ | ||
export async function get_2(config?:AxiosRequestConfig): AxiosPromise<unknown> { | ||
return axios({ | ||
method: "get", | ||
url: \`/\`, | ||
...config | ||
}); | ||
}" | ||
`); | ||
}); |