@penkov/swagger-code-gen 1.7.5 → 1.7.7
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/dist/property.js +1 -0
- package/dist/templates/index.ejs +6 -3
- package/dist/templates/method.ejs +20 -12
- package/package.json +1 -1
package/dist/property.js
CHANGED
package/dist/templates/index.ejs
CHANGED
|
@@ -49,7 +49,7 @@ function valueToString(value: any): string {
|
|
|
49
49
|
/**
|
|
50
50
|
* Helper to serialize data for 'multipart/form-data'
|
|
51
51
|
*/
|
|
52
|
-
function objectToForm(o:
|
|
52
|
+
function objectToForm(o: Record<string, any>): FormData {
|
|
53
53
|
const res = new FormData();
|
|
54
54
|
Object.keys(o)
|
|
55
55
|
.filter(k => o[k] !== undefined && o[k] !== null)
|
|
@@ -58,6 +58,8 @@ function objectToForm(o: object): FormData {
|
|
|
58
58
|
o[k].forEach(e => {
|
|
59
59
|
res.append(k, valueToString(e));
|
|
60
60
|
})
|
|
61
|
+
} else if (o[k] instanceof File) {
|
|
62
|
+
res.append(k, o[k]);
|
|
61
63
|
} else {
|
|
62
64
|
res.append(k, valueToString(o[k]));
|
|
63
65
|
}
|
|
@@ -68,7 +70,7 @@ function objectToForm(o: object): FormData {
|
|
|
68
70
|
/**
|
|
69
71
|
* Helper to serialize data for 'application/x-www-form-urlencoded'
|
|
70
72
|
*/
|
|
71
|
-
function objectToFormWwwEncoded(o:
|
|
73
|
+
function objectToFormWwwEncoded(o: Record<string, any>): string {
|
|
72
74
|
return Object.keys(o)
|
|
73
75
|
.filter(k => o[k] !== undefined && o[k] !== null)
|
|
74
76
|
.map(k => `${k}=${encodeURIComponent(valueToString(o[k]))}`)
|
|
@@ -82,7 +84,8 @@ async function requestImpl<T>(request: Request, requestOptions: RequestOptions):
|
|
|
82
84
|
if (postProcessed.ok) {
|
|
83
85
|
let json: any = null;
|
|
84
86
|
if (postProcessed.headers.has('content-length')) {
|
|
85
|
-
const
|
|
87
|
+
const ctLent = postProcessed.headers.get('content-length');
|
|
88
|
+
const ct = ctLent != null ? parseInt(ctLent): 0;
|
|
86
89
|
if (ct > 0) {
|
|
87
90
|
json = await postProcessed.json()
|
|
88
91
|
}
|
|
@@ -62,6 +62,7 @@ export async function <%= method.endpointName %><%= body.map(b => b.suffix).getO
|
|
|
62
62
|
query = '?' + queryParams.join('&');
|
|
63
63
|
}
|
|
64
64
|
<%_ } -%>
|
|
65
|
+
|
|
65
66
|
let bodySerialised: BodyInit | null = null;
|
|
66
67
|
<%_ if (body.nonEmpty && body.get.mimeType === 'application/json') {%>
|
|
67
68
|
bodySerialised = JSON.stringify(body);
|
|
@@ -72,22 +73,29 @@ export async function <%= method.endpointName %><%= body.map(b => b.suffix).getO
|
|
|
72
73
|
<%_ } else if (body.nonEmpty && body.get.mimeType === 'application/octet-stream') { -%>
|
|
73
74
|
bodySerialised = body;
|
|
74
75
|
<%_ } -%>
|
|
76
|
+
|
|
77
|
+
const headers: HeadersInit = {
|
|
78
|
+
...requestOptions.headers || {},
|
|
79
|
+
'Accept': 'application/json',
|
|
80
|
+
<%_ if (body.nonEmpty && body.get.mimeType !== 'multipart/form-data') {%>
|
|
81
|
+
'Content-Type': '<%= body.get.mimeType %>',
|
|
82
|
+
<%_ } -%>
|
|
83
|
+
<%_ if (method.parameters.filter(x => x.in === 'header').nonEmpty) { -%>
|
|
84
|
+
<%_ method.parameters.filter(x => x.in === 'header').foreach(p => { -%>
|
|
85
|
+
<%= p.name %>: <%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>,
|
|
86
|
+
<%_ }) -%>
|
|
87
|
+
<%_ } -%>
|
|
88
|
+
};
|
|
89
|
+
<%_ if (body.nonEmpty && body.get.mimeType === 'multipart/form-data') {%>
|
|
90
|
+
delete headers['Content-Type'];
|
|
91
|
+
<%_ } -%>
|
|
92
|
+
|
|
93
|
+
|
|
75
94
|
const request = new Request(`${requestOptions.apiPrefix}<%- method.pathWithSubstitutions %>${query}`, {
|
|
76
95
|
method: '<%= method.method %>',
|
|
77
96
|
body: bodySerialised,
|
|
78
97
|
signal: requestOptions.signal,
|
|
79
|
-
headers:
|
|
80
|
-
...requestOptions.headers || {},
|
|
81
|
-
'Accept': 'application/json',
|
|
82
|
-
<%_ if (body.nonEmpty && body.get.mimeType !== 'multipart/form-data') {%>
|
|
83
|
-
'Content-Type': '<%= body.get.mimeType %>',
|
|
84
|
-
<%_ } -%>
|
|
85
|
-
<%_ if (method.parameters.filter(x => x.in === 'header').nonEmpty) { -%>
|
|
86
|
-
<%_ method.parameters.filter(x => x.in === 'header').foreach(p => { -%>
|
|
87
|
-
<%= p.name %>: <%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>,
|
|
88
|
-
<%_ }) -%>
|
|
89
|
-
<%_ } -%>
|
|
90
|
-
}
|
|
98
|
+
headers: headers
|
|
91
99
|
});
|
|
92
100
|
return requestImpl<<%- method.response.responseType %>>(request, requestOptions);
|
|
93
101
|
}
|