-
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
132 additions
and
4 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,127 @@ | ||
import { Printer } from '../../src/printer'; | ||
|
||
test('upload root', () => { | ||
const printer = new Printer({ | ||
openapi: '3.1.0', | ||
info: { | ||
title: 'test', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/upload': { | ||
post: { | ||
tags: ['upload'], | ||
summary: 'upload', | ||
description: 'upload', | ||
operationId: 'upload', | ||
requestBody: { | ||
content: { | ||
'multipart/form-data': { | ||
schema: { | ||
type: 'string', | ||
format: 'binary', | ||
description: 'A file', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const output = printer.print({ | ||
hideComponents: true, | ||
hideInfo: true, | ||
hideFooters: true, | ||
hideHeaders: true, | ||
hideImports: true, | ||
hideHelpers: true, | ||
}); | ||
|
||
expect(output).toMatchInlineSnapshot(` | ||
"/** | ||
* @description upload | ||
* @summary upload | ||
* @param data A file | ||
* @param [config] request config | ||
*/ | ||
export async function upload(data:Blob,config?:AxiosRequestConfig): AxiosPromise<unknown> { | ||
return axios({ | ||
method: "post", | ||
url: \`/upload\`, | ||
data: data, | ||
...config | ||
}); | ||
}" | ||
`); | ||
}); | ||
|
||
test('upload single', () => { | ||
const printer = new Printer({ | ||
openapi: '3.1.0', | ||
info: { | ||
title: 'test', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/upload': { | ||
post: { | ||
tags: ['upload'], | ||
summary: 'upload', | ||
description: 'upload', | ||
operationId: 'upload', | ||
requestBody: { | ||
content: { | ||
'multipart/form-data': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
file: { | ||
type: 'string', | ||
format: 'binary', | ||
description: 'A file', | ||
required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const output = printer.print({ | ||
hideComponents: true, | ||
hideInfo: true, | ||
hideFooters: true, | ||
hideHeaders: true, | ||
hideImports: true, | ||
hideHelpers: true, | ||
}); | ||
|
||
expect(output).toMatchInlineSnapshot(` | ||
"/** | ||
* @description upload | ||
* @summary upload | ||
* @param data request param | ||
* @param [config] request config | ||
*/ | ||
export async function upload(data:{ | ||
/** | ||
* @description A file | ||
* @format binary | ||
*/ | ||
"file":Blob; | ||
},config?:AxiosRequestConfig): AxiosPromise<unknown> { | ||
return axios({ | ||
method: "post", | ||
url: \`/upload\`, | ||
data: data, | ||
...config | ||
}); | ||
}" | ||
`); | ||
}); |