FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi-typescript-codegen/src/utils/writeClient.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
/
writeClient.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
118 lines (109 loc) · 4.08 KB
Breadcrumbs
openapi-typescript-codegen
/
src
/
utils
/
writeClient.ts
Copy path
File metadata and controls
118 lines (109 loc) · 4.08 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import
{
resolve
}
from
'path'
;
import
type
{
Client
}
from
'../client/interfaces/Client'
;
import
type
{
HttpClient
}
from
'../HttpClient'
;
import
type
{
Indent
}
from
'../Indent'
;
import
{
mkdir
,
rmdir
}
from
'./fileSystem'
;
import
{
isDefined
}
from
'./isDefined'
;
import
{
isSubDirectory
}
from
'./isSubdirectory'
;
import
type
{
Templates
}
from
'./registerHandlebarTemplates'
;
import
{
writeClientClass
}
from
'./writeClientClass'
;
import
{
writeClientCore
}
from
'./writeClientCore'
;
import
{
writeClientModels
}
from
'./writeClientModels'
;
import
{
writeClientSchemas
}
from
'./writeClientSchemas'
;
import
{
writeClientServices
}
from
'./writeClientServices'
;
/**
* Write our OpenAPI client, using the given templates at the given output
*
@param
client Client object with all the models, services, etc.
*
@param
templates Templates wrapper with all loaded Handlebars templates
*
@param
output The relative location of the output directory
*
@param
httpClient The selected httpClient (fetch, xhr, node or axios)
*
@param
useOptions Use options or arguments functions
*
@param
useUnionTypes Use union types instead of enums
*
@param
exportCore Generate core client classes
*
@param
exportServices Generate services
*
@param
exportModels Generate models
*
@param
exportSchemas Generate schemas
*
@param
exportSchemas Generate schemas
*
@param
indent Indentation options (4, 2 or tab)
*
@param
postfixServices Service name postfix
*
@param
postfixModels Model name postfix
*
@param
clientName Custom client class name
*
@param
request Path to custom request file
*/
export
const
writeClient
=
async
(
client
:
Client
,
templates
:
Templates
,
output
:
string
,
httpClient
:
HttpClient
,
useOptions
:
boolean
,
useUnionTypes
:
boolean
,
exportCore
:
boolean
,
exportServices
:
boolean
,
exportModels
:
boolean
,
exportSchemas
:
boolean
,
indent
:
Indent
,
postfixServices
:
string
,
postfixModels
:
string
,
clientName
?:
string
,
request
?:
string
)
:
Promise
<
void
>
=>
{
const
outputPath
=
resolve
(
process
.
cwd
(
)
,
output
)
;
const
outputPathCore
=
resolve
(
outputPath
,
'core'
)
;
const
outputPathModels
=
resolve
(
outputPath
,
'models'
)
;
const
outputPathSchemas
=
resolve
(
outputPath
,
'schemas'
)
;
const
outputPathServices
=
resolve
(
outputPath
,
'services'
)
;
if
(
!
isSubDirectory
(
process
.
cwd
(
)
,
output
)
)
{
throw
new
Error
(
`Output folder is not a subdirectory of the current working directory`
)
;
}
if
(
exportCore
)
{
await
rmdir
(
outputPathCore
)
;
await
mkdir
(
outputPathCore
)
;
await
writeClientCore
(
client
,
templates
,
outputPathCore
,
httpClient
,
indent
,
clientName
,
request
)
;
}
if
(
exportServices
)
{
await
rmdir
(
outputPathServices
)
;
await
mkdir
(
outputPathServices
)
;
await
writeClientServices
(
client
.
services
,
templates
,
outputPathServices
,
httpClient
,
useUnionTypes
,
useOptions
,
indent
,
postfixServices
,
clientName
)
;
}
if
(
exportSchemas
)
{
await
rmdir
(
outputPathSchemas
)
;
await
mkdir
(
outputPathSchemas
)
;
await
writeClientSchemas
(
client
.
models
,
templates
,
outputPathSchemas
,
httpClient
,
useUnionTypes
,
indent
)
;
}
if
(
exportModels
)
{
await
rmdir
(
outputPathModels
)
;
await
mkdir
(
outputPathModels
)
;
await
writeClientModels
(
client
.
models
,
templates
,
outputPathModels
,
httpClient
,
useUnionTypes
,
indent
)
;
}
if
(
isDefined
(
clientName
)
)
{
await
mkdir
(
outputPath
)
;
await
writeClientClass
(
client
,
templates
,
outputPath
,
httpClient
,
clientName
,
indent
,
postfixServices
)
;
}
// We do not need index.ts
/* if (exportCore || exportServices || exportSchemas || exportModels) {
await mkdir(outputPath);
await writeClientIndex(
client,
templates,
outputPath,
useUnionTypes,
exportCore,
exportServices,
exportModels,
exportSchemas,
postfixServices,
postfixModels,
clientName
);
}*/
}
;
Back
|
FazBrowse Home
|
New Git URL