@penkov/swagger-code-gen 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -43
- package/dist/templates/index.ejs +2 -2
- package/dist/templates/method.ejs +1 -1
- package/dist/templates/scats-method.ejs +17 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,19 +148,7 @@ export async function findPetsByStatus(
|
|
|
148
148
|
...option(requestOptions.headers).getOrElseValue({}),
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
|
-
|
|
152
|
-
const resp = await fetch(preProcessed);
|
|
153
|
-
if (resp.ok) {
|
|
154
|
-
const postProcessed = option(requestOptions.postProcessResponse)
|
|
155
|
-
.map(cb => cb(preProcessed, resp))
|
|
156
|
-
.getOrElseValue(resp);
|
|
157
|
-
const json = option(resp.headers.get('content-length'))
|
|
158
|
-
.map(x => parseInt(x))
|
|
159
|
-
.getOrElseValue(0) > 0 ? await postProcessed.json() : null;
|
|
160
|
-
return json as ReadonlyArray<Pet>;
|
|
161
|
-
} else {
|
|
162
|
-
throw resp;
|
|
163
|
-
}
|
|
151
|
+
return requestImpl<Pet>(request, requestOptions);
|
|
164
152
|
}
|
|
165
153
|
|
|
166
154
|
|
|
@@ -170,48 +158,53 @@ export async function findPetsByStatus(
|
|
|
170
158
|
|
|
171
159
|
// scats wrappers
|
|
172
160
|
|
|
173
|
-
|
|
161
|
+
|
|
162
|
+
export class PetDto {
|
|
174
163
|
|
|
175
164
|
constructor(
|
|
176
165
|
readonly id: number,
|
|
177
|
-
readonly
|
|
178
|
-
readonly
|
|
179
|
-
readonly
|
|
166
|
+
readonly name: string,
|
|
167
|
+
readonly category: CategoryDto,
|
|
168
|
+
readonly photoUrls: Collection<string>,
|
|
169
|
+
readonly tags: Collection<TagDto>,
|
|
180
170
|
readonly status: string,
|
|
181
|
-
readonly complete: boolean,
|
|
182
171
|
) {}
|
|
183
172
|
|
|
184
173
|
|
|
185
|
-
static fromJson(json:
|
|
186
|
-
return new
|
|
174
|
+
static fromJson(json: Pet): PetDto {
|
|
175
|
+
return new PetDto(
|
|
187
176
|
json.id,
|
|
188
|
-
json.
|
|
189
|
-
json.
|
|
190
|
-
json.
|
|
177
|
+
json.name,
|
|
178
|
+
CategoryDto.fromJson(json.category),
|
|
179
|
+
Collection.from(option(json.photoUrls).getOrElseValue([]))
|
|
180
|
+
,
|
|
181
|
+
Collection.from(option(json.tags).getOrElseValue([]))
|
|
182
|
+
.map(i => TagDto.fromJson(i)),
|
|
191
183
|
json.status,
|
|
192
|
-
json.complete,
|
|
193
184
|
);
|
|
194
185
|
}
|
|
195
186
|
|
|
196
|
-
copy(fields: Partial<
|
|
197
|
-
return new
|
|
187
|
+
copy(fields: Partial<PetDto>): PetDto {
|
|
188
|
+
return new PetDto(
|
|
198
189
|
option(fields.id).getOrElseValue(this.id),
|
|
199
|
-
option(fields.
|
|
200
|
-
option(fields.
|
|
201
|
-
option(fields.
|
|
190
|
+
option(fields.name).getOrElseValue(this.name),
|
|
191
|
+
option(fields.category).getOrElseValue(this.category),
|
|
192
|
+
option(fields.photoUrls).getOrElseValue(this.photoUrls),
|
|
193
|
+
option(fields.tags).getOrElseValue(this.tags),
|
|
202
194
|
option(fields.status).getOrElseValue(this.status),
|
|
203
|
-
option(fields.complete).getOrElseValue(this.complete),
|
|
204
195
|
);
|
|
205
196
|
}
|
|
206
197
|
|
|
207
|
-
get toJson():
|
|
198
|
+
get toJson(): Pet {
|
|
208
199
|
return {
|
|
209
200
|
id: this.id,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
name: this.name,
|
|
202
|
+
category: this.category.toJson,
|
|
203
|
+
photoUrls: this.photoUrls
|
|
204
|
+
.toArray,
|
|
205
|
+
tags: this.tags
|
|
206
|
+
.map(_ => _.toJson) .toArray,
|
|
213
207
|
status: this.status,
|
|
214
|
-
complete: this.complete,
|
|
215
208
|
};
|
|
216
209
|
}
|
|
217
210
|
}
|
|
@@ -222,14 +215,15 @@ export class ApiClient {
|
|
|
222
215
|
constructor(private readonly requestOptions: RequestOptions = defaultRequestOptions()) {
|
|
223
216
|
}
|
|
224
217
|
|
|
218
|
+
// ... some methods skipped
|
|
225
219
|
|
|
226
220
|
async updatePet(
|
|
227
|
-
body:
|
|
221
|
+
body: PetDto,
|
|
228
222
|
requestOptions: RequestOptions = this.requestOptions
|
|
229
223
|
): Promise<TryLike<PetDto>> {
|
|
230
224
|
return (await Try.promise(() =>
|
|
231
225
|
updatePet(
|
|
232
|
-
body,
|
|
226
|
+
body.toJson,
|
|
233
227
|
requestOptions
|
|
234
228
|
)
|
|
235
229
|
))
|
|
@@ -237,17 +231,18 @@ export class ApiClient {
|
|
|
237
231
|
;
|
|
238
232
|
}
|
|
239
233
|
|
|
240
|
-
async
|
|
241
|
-
|
|
234
|
+
async findPetsByStatus(
|
|
235
|
+
status: 'available' | 'pending' | 'sold',
|
|
242
236
|
requestOptions: RequestOptions = this.requestOptions
|
|
243
|
-
): Promise<TryLike<PetDto
|
|
237
|
+
): Promise<TryLike<Collection<PetDto>>> {
|
|
244
238
|
return (await Try.promise(() =>
|
|
245
|
-
|
|
246
|
-
|
|
239
|
+
findPetsByStatus(
|
|
240
|
+
status,
|
|
247
241
|
requestOptions
|
|
248
242
|
)
|
|
249
243
|
))
|
|
250
|
-
.map(res =>
|
|
244
|
+
.map(res => Collection.from(option(res).getOrElseValue([])))
|
|
245
|
+
.map(items => items.map(i => PetDto.fromJson(i)))
|
|
251
246
|
;
|
|
252
247
|
}
|
|
253
248
|
|
package/dist/templates/index.ejs
CHANGED
|
@@ -23,7 +23,7 @@ export interface RequestOptions {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
export const
|
|
26
|
+
export const defaultRequestOptions: RequestOptions = {
|
|
27
27
|
apiPrefix: '',
|
|
28
28
|
headers: {
|
|
29
29
|
'Accept': 'application/json',
|
|
@@ -31,7 +31,7 @@ export const defaultReqOpts: RequestOptions = {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const defReqOpts = () => defaultRequestOptions;
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
async function requestImpl<T>(request: Request, requestOptions: RequestOptions): Promise<T> {
|
|
@@ -33,7 +33,7 @@ export async function <%= method.endpointName %>(
|
|
|
33
33
|
<%_ if (method.body.nonEmpty) { -%>
|
|
34
34
|
body: <%- method.body.get.jsType %>,
|
|
35
35
|
<%_ } -%>
|
|
36
|
-
requestOptions: RequestOptions =
|
|
36
|
+
requestOptions: RequestOptions = defReqOpts()
|
|
37
37
|
): Promise<<%- method.response.responseType %>> {
|
|
38
38
|
let query = '';
|
|
39
39
|
<%_ if (method.parameters.filter(x => x.in === 'query').nonEmpty) { -%>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export class ApiClient {
|
|
2
2
|
|
|
3
|
-
constructor(private readonly requestOptions: RequestOptions =
|
|
3
|
+
constructor(private readonly requestOptions: RequestOptions = defReqOpts()) {
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ export class ApiClient {
|
|
|
18
18
|
},
|
|
19
19
|
<%_ } -%>
|
|
20
20
|
<%_ method.body.foreach(body => { -%>
|
|
21
|
-
body: <%- body.
|
|
21
|
+
body: <%- body.scatsWrapperType %>,
|
|
22
22
|
<%_ }); -%>
|
|
23
23
|
requestOptions: RequestOptions = this.requestOptions
|
|
24
24
|
): Promise<TryLike<<%- method.response.asProperty.scatsWrapperType %>>> {
|
|
@@ -31,9 +31,23 @@ export class ApiClient {
|
|
|
31
31
|
<%_ } else { -%>
|
|
32
32
|
params,
|
|
33
33
|
<%_ } -%>
|
|
34
|
-
<%_
|
|
34
|
+
<%_ method.body.foreach(body => { -%>
|
|
35
|
+
<%_ if (body.schemaType === 'object') { _%>
|
|
36
|
+
body.toJson,
|
|
37
|
+
<%_ } else if (body.schemaType === 'property') { _%>
|
|
38
|
+
<%_ if (body.isArray && body.itemReferencesObject) { _%>
|
|
39
|
+
body.map(_ => _.toJson).toArray,
|
|
40
|
+
<%_ } else if (body.isArray && !body.itemReferencesObject) { -%>
|
|
41
|
+
body.toArray,
|
|
42
|
+
<%_ } else if (body.referencesObject) { -%>
|
|
43
|
+
body.toJson,
|
|
44
|
+
<%_ } else { -%>
|
|
45
|
+
body,
|
|
46
|
+
<%_ } -%>
|
|
47
|
+
<%_ } else { -%>
|
|
35
48
|
body,
|
|
36
49
|
<%_ } -%>
|
|
50
|
+
<%_ }); -%>
|
|
37
51
|
requestOptions
|
|
38
52
|
)
|
|
39
53
|
))
|