FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi-typescript-codegen/src/utils/writeClientCore.ts at main · thulium/openapi-typescript-codegen · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
thulium
/
openapi-typescript-codegen
Public
forked from
ferdikoomen/openapi-typescript-codegen
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
21
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openapi-typescript-codegen
/
src
/
utils
/
writeClientCore.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (55 loc) · 2.62 KB
Breadcrumbs
openapi-typescript-codegen
/
src
/
utils
/
writeClientCore.ts
Copy path
File metadata and controls
60 lines (55 loc) · 2.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import
{
resolve
}
from
'path'
;
import
type
{
Client
}
from
'../client/interfaces/Client'
;
import
type
{
HttpClient
}
from
'../HttpClient'
;
import
type
{
Indent
}
from
'../Indent'
;
import
{
copyFile
,
exists
,
writeFile
}
from
'./fileSystem'
;
import
{
formatIndentation
as
i
}
from
'./formatIndentation'
;
import
{
getHttpRequestName
}
from
'./getHttpRequestName'
;
import
{
isDefined
}
from
'./isDefined'
;
import
type
{
Templates
}
from
'./registerHandlebarTemplates'
;
/**
* Generate OpenAPI core files, this includes the basic boilerplate code to handle requests.
*
@param
client Client object, containing, models, schemas and services
*
@param
templates The loaded handlebar templates
*
@param
outputPath Directory to write the generated files to
*
@param
httpClient The selected httpClient (fetch, xhr, node or axios)
*
@param
indent Indentation options (4, 2 or tab)
*
@param
clientName Custom client class name
*
@param
request Path to custom request file
*/
export
const
writeClientCore
=
async
(
client
:
Client
,
templates
:
Templates
,
outputPath
:
string
,
httpClient
:
HttpClient
,
indent
:
Indent
,
clientName
?:
string
,
request
?:
string
)
:
Promise
<
void
>
=>
{
const
httpRequest
=
getHttpRequestName
(
httpClient
)
;
const
context
=
{
httpClient
,
clientName
,
httpRequest
,
server
:
client
.
server
,
version
:
client
.
version
,
}
;
await
writeFile
(
resolve
(
outputPath
,
'OpenAPI.ts'
)
,
i
(
templates
.
core
.
settings
(
context
)
,
indent
)
)
;
await
writeFile
(
resolve
(
outputPath
,
'ApiError.ts'
)
,
i
(
templates
.
core
.
apiError
(
context
)
,
indent
)
)
;
await
writeFile
(
resolve
(
outputPath
,
'ApiRequestOptions.ts'
)
,
i
(
templates
.
core
.
apiRequestOptions
(
context
)
,
indent
)
)
;
await
writeFile
(
resolve
(
outputPath
,
'ApiResult.ts'
)
,
i
(
templates
.
core
.
apiResult
(
context
)
,
indent
)
)
;
await
writeFile
(
resolve
(
outputPath
,
'CancelablePromise.ts'
)
,
i
(
templates
.
core
.
cancelablePromise
(
context
)
,
indent
)
)
;
await
writeFile
(
resolve
(
outputPath
,
'request.ts'
)
,
i
(
templates
.
core
.
request
(
context
)
,
indent
)
)
;
if
(
isDefined
(
clientName
)
)
{
await
writeFile
(
resolve
(
outputPath
,
'BaseHttpRequest.ts'
)
,
i
(
templates
.
core
.
baseHttpRequest
(
context
)
,
indent
)
)
;
await
writeFile
(
resolve
(
outputPath
,
`
${
httpRequest
}
.ts`
)
,
i
(
templates
.
core
.
httpRequest
(
context
)
,
indent
)
)
;
}
if
(
request
)
{
const
requestFile
=
resolve
(
process
.
cwd
(
)
,
request
)
;
const
requestFileExists
=
await
exists
(
requestFile
)
;
if
(
!
requestFileExists
)
{
throw
new
Error
(
`Custom request file "
${
requestFile
}
" does not exists`
)
;
}
await
copyFile
(
requestFile
,
resolve
(
outputPath
,
'request.ts'
)
)
;
}
}
;
Back
|
FazBrowse Home
|
New Git URL