Skip to content

Commit 30e008c

Browse files
authored
Merge pull request #443 from JochenDiekenbrock/fix-consumes-test/plain
Fix consumes test/plain
2 parents 4365b63 + 2080e95 commit 30e008c

File tree

106 files changed

+266
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+266
-0
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ export enum RequestContentKind {
315315
FORM_DATA = "FORM_DATA",
316316
IMAGE = "IMAGE",
317317
OTHER = "OTHER",
318+
TEXT = "TEXT",
318319
}
319320

320321
export interface RequestResponseInfo {

src/schema-parser/schema-routes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const CONTENT_KIND = {
1616
FORM_DATA: "FORM_DATA",
1717
IMAGE: "IMAGE",
1818
OTHER: "OTHER",
19+
TEXT: "TEXT",
1920
};
2021

2122
class SchemaRoutes {
@@ -265,6 +266,12 @@ class SchemaRoutes {
265266
return CONTENT_KIND.IMAGE;
266267
}
267268

269+
if (
270+
_.some(contentTypes, (contentType) => _.startsWith(contentType, "text/"))
271+
) {
272+
return CONTENT_KIND.TEXT;
273+
}
274+
268275
return CONTENT_KIND.OTHER;
269276
};
270277

templates/base/http-clients/axios-http-client.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export enum ContentType {
3333
Json = "application/json",
3434
FormData = "multipart/form-data",
3535
UrlEncoded = "application/x-www-form-urlencoded",
36+
Text = "text/plain",
3637
}
3738

3839
export class HttpClient<SecurityDataType = unknown> {
@@ -114,6 +115,10 @@ export class HttpClient<SecurityDataType = unknown> {
114115
body = this.createFormData(body as Record<string, unknown>);
115116
}
116117

118+
if (type === ContentType.Text && body && body !== null && typeof body !== "string") {
119+
body = JSON.stringify(body);
120+
}
121+
117122
return this.instance.request({
118123
...requestParams,
119124
headers: {

templates/base/http-clients/fetch-http-client.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export enum ContentType {
4545
Json = "application/json",
4646
FormData = "multipart/form-data",
4747
UrlEncoded = "application/x-www-form-urlencoded",
48+
Text = "text/plain",
4849
}
4950

5051
export class HttpClient<SecurityDataType = unknown> {
@@ -102,6 +103,7 @@ export class HttpClient<SecurityDataType = unknown> {
102103

103104
private contentFormatters: Record<ContentType, (input: any) => any> = {
104105
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
106+
[ContentType.Text]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input,
105107
[ContentType.FormData]: (input: any) =>
106108
Object.keys(input || {}).reduce((formData, key) => {
107109
const property = input[key];

templates/default/procedure-call.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const requestContentKind = {
5050
"JSON": "ContentType.Json",
5151
"URL_ENCODED": "ContentType.UrlEncoded",
5252
"FORM_DATA": "ContentType.FormData",
53+
"TEXT": "ContentType.Text",
5354
}
5455
// RequestParams["format"]
5556
const responseContentKind = {

templates/modular/procedure-call.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const requestContentKind = {
5050
"JSON": "ContentType.Json",
5151
"URL_ENCODED": "ContentType.UrlEncoded",
5252
"FORM_DATA": "ContentType.FormData",
53+
"TEXT": "ContentType.Text",
5354
}
5455
// RequestParams["format"]
5556
const responseContentKind = {

tests/generated/v2.0/adafruit.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export enum ContentType {
208208
Json = "application/json",
209209
FormData = "multipart/form-data",
210210
UrlEncoded = "application/x-www-form-urlencoded",
211+
Text = "text/plain",
211212
}
212213

213214
export class HttpClient<SecurityDataType = unknown> {
@@ -262,6 +263,7 @@ export class HttpClient<SecurityDataType = unknown> {
262263
private contentFormatters: Record<ContentType, (input: any) => any> = {
263264
[ContentType.Json]: (input: any) =>
264265
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
266+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
265267
[ContentType.FormData]: (input: any) =>
266268
Object.keys(input || {}).reduce((formData, key) => {
267269
const property = input[key];

tests/generated/v2.0/another-example.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export enum ContentType {
174174
Json = "application/json",
175175
FormData = "multipart/form-data",
176176
UrlEncoded = "application/x-www-form-urlencoded",
177+
Text = "text/plain",
177178
}
178179

179180
export class HttpClient<SecurityDataType = unknown> {
@@ -228,6 +229,7 @@ export class HttpClient<SecurityDataType = unknown> {
228229
private contentFormatters: Record<ContentType, (input: any) => any> = {
229230
[ContentType.Json]: (input: any) =>
230231
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
232+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
231233
[ContentType.FormData]: (input: any) =>
232234
Object.keys(input || {}).reduce((formData, key) => {
233235
const property = input[key];

tests/generated/v2.0/another-schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export enum ContentType {
7272
Json = "application/json",
7373
FormData = "multipart/form-data",
7474
UrlEncoded = "application/x-www-form-urlencoded",
75+
Text = "text/plain",
7576
}
7677

7778
export class HttpClient<SecurityDataType = unknown> {
@@ -126,6 +127,7 @@ export class HttpClient<SecurityDataType = unknown> {
126127
private contentFormatters: Record<ContentType, (input: any) => any> = {
127128
[ContentType.Json]: (input: any) =>
128129
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
130+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
129131
[ContentType.FormData]: (input: any) =>
130132
Object.keys(input || {}).reduce((formData, key) => {
131133
const property = input[key];

tests/generated/v2.0/api-with-examples.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum ContentType {
5151
Json = "application/json",
5252
FormData = "multipart/form-data",
5353
UrlEncoded = "application/x-www-form-urlencoded",
54+
Text = "text/plain",
5455
}
5556

5657
export class HttpClient<SecurityDataType = unknown> {
@@ -105,6 +106,7 @@ export class HttpClient<SecurityDataType = unknown> {
105106
private contentFormatters: Record<ContentType, (input: any) => any> = {
106107
[ContentType.Json]: (input: any) =>
107108
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
109+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
108110
[ContentType.FormData]: (input: any) =>
109111
Object.keys(input || {}).reduce((formData, key) => {
110112
const property = input[key];
@@ -270,4 +272,21 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
270272
...params,
271273
}),
272274
};
275+
consumesPlainText = {
276+
/**
277+
* @description consumes plain text
278+
*
279+
* @name ConsumesPlainText
280+
* @summary consumes plain text
281+
* @request POST:/consumes-plain-text/
282+
*/
283+
consumesPlainText: (someParm: string, params: RequestParams = {}) =>
284+
this.request<any, void>({
285+
path: `/consumes-plain-text/`,
286+
method: "POST",
287+
body: someParm,
288+
type: ContentType.Text,
289+
...params,
290+
}),
291+
};
273292
}

tests/generated/v2.0/authentiq.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export enum ContentType {
9191
Json = "application/json",
9292
FormData = "multipart/form-data",
9393
UrlEncoded = "application/x-www-form-urlencoded",
94+
Text = "text/plain",
9495
}
9596

9697
export class HttpClient<SecurityDataType = unknown> {
@@ -145,6 +146,7 @@ export class HttpClient<SecurityDataType = unknown> {
145146
private contentFormatters: Record<ContentType, (input: any) => any> = {
146147
[ContentType.Json]: (input: any) =>
147148
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
149+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
148150
[ContentType.FormData]: (input: any) =>
149151
Object.keys(input || {}).reduce((formData, key) => {
150152
const property = input[key];

tests/generated/v2.0/enums.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export enum ContentType {
110110
Json = "application/json",
111111
FormData = "multipart/form-data",
112112
UrlEncoded = "application/x-www-form-urlencoded",
113+
Text = "text/plain",
113114
}
114115

115116
export class HttpClient<SecurityDataType = unknown> {
@@ -164,6 +165,7 @@ export class HttpClient<SecurityDataType = unknown> {
164165
private contentFormatters: Record<ContentType, (input: any) => any> = {
165166
[ContentType.Json]: (input: any) =>
166167
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
168+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
167169
[ContentType.FormData]: (input: any) =>
168170
Object.keys(input || {}).reduce((formData, key) => {
169171
const property = input[key];

tests/generated/v2.0/example1.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export enum ContentType {
8888
Json = "application/json",
8989
FormData = "multipart/form-data",
9090
UrlEncoded = "application/x-www-form-urlencoded",
91+
Text = "text/plain",
9192
}
9293

9394
export class HttpClient<SecurityDataType = unknown> {
@@ -142,6 +143,7 @@ export class HttpClient<SecurityDataType = unknown> {
142143
private contentFormatters: Record<ContentType, (input: any) => any> = {
143144
[ContentType.Json]: (input: any) =>
144145
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
146+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
145147
[ContentType.FormData]: (input: any) =>
146148
Object.keys(input || {}).reduce((formData, key) => {
147149
const property = input[key];

tests/generated/v2.0/file-formdata-example.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum ContentType {
5151
Json = "application/json",
5252
FormData = "multipart/form-data",
5353
UrlEncoded = "application/x-www-form-urlencoded",
54+
Text = "text/plain",
5455
}
5556

5657
export class HttpClient<SecurityDataType = unknown> {
@@ -105,6 +106,7 @@ export class HttpClient<SecurityDataType = unknown> {
105106
private contentFormatters: Record<ContentType, (input: any) => any> = {
106107
[ContentType.Json]: (input: any) =>
107108
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
109+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
108110
[ContentType.FormData]: (input: any) =>
109111
Object.keys(input || {}).reduce((formData, key) => {
110112
const property = input[key];

tests/generated/v2.0/furkot-example.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export enum ContentType {
124124
Json = "application/json",
125125
FormData = "multipart/form-data",
126126
UrlEncoded = "application/x-www-form-urlencoded",
127+
Text = "text/plain",
127128
}
128129

129130
export class HttpClient<SecurityDataType = unknown> {
@@ -178,6 +179,7 @@ export class HttpClient<SecurityDataType = unknown> {
178179
private contentFormatters: Record<ContentType, (input: any) => any> = {
179180
[ContentType.Json]: (input: any) =>
180181
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
182+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
181183
[ContentType.FormData]: (input: any) =>
182184
Object.keys(input || {}).reduce((formData, key) => {
183185
const property = input[key];

tests/generated/v2.0/giphy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export enum ContentType {
308308
Json = "application/json",
309309
FormData = "multipart/form-data",
310310
UrlEncoded = "application/x-www-form-urlencoded",
311+
Text = "text/plain",
311312
}
312313

313314
export class HttpClient<SecurityDataType = unknown> {
@@ -362,6 +363,7 @@ export class HttpClient<SecurityDataType = unknown> {
362363
private contentFormatters: Record<ContentType, (input: any) => any> = {
363364
[ContentType.Json]: (input: any) =>
364365
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
366+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
365367
[ContentType.FormData]: (input: any) =>
366368
Object.keys(input || {}).reduce((formData, key) => {
367369
const property = input[key];

tests/generated/v2.0/github-swagger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,7 @@ export enum ContentType {
19491949
Json = "application/json",
19501950
FormData = "multipart/form-data",
19511951
UrlEncoded = "application/x-www-form-urlencoded",
1952+
Text = "text/plain",
19521953
}
19531954

19541955
export class HttpClient<SecurityDataType = unknown> {
@@ -2003,6 +2004,7 @@ export class HttpClient<SecurityDataType = unknown> {
20032004
private contentFormatters: Record<ContentType, (input: any) => any> = {
20042005
[ContentType.Json]: (input: any) =>
20052006
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
2007+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
20062008
[ContentType.FormData]: (input: any) =>
20072009
Object.keys(input || {}).reduce((formData, key) => {
20082010
const property = input[key];
@@ -2684,6 +2686,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
26842686
this.request<void, void>({
26852687
path: `/markdown/raw`,
26862688
method: "POST",
2689+
type: ContentType.Text,
26872690
...params,
26882691
}),
26892692
};

tests/generated/v2.0/path-args.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum ContentType {
5151
Json = "application/json",
5252
FormData = "multipart/form-data",
5353
UrlEncoded = "application/x-www-form-urlencoded",
54+
Text = "text/plain",
5455
}
5556

5657
export class HttpClient<SecurityDataType = unknown> {
@@ -105,6 +106,7 @@ export class HttpClient<SecurityDataType = unknown> {
105106
private contentFormatters: Record<ContentType, (input: any) => any> = {
106107
[ContentType.Json]: (input: any) =>
107108
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
109+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
108110
[ContentType.FormData]: (input: any) =>
109111
Object.keys(input || {}).reduce((formData, key) => {
110112
const property = input[key];

tests/generated/v2.0/petstore-expanded.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export enum ContentType {
8787
Json = "application/json",
8888
FormData = "multipart/form-data",
8989
UrlEncoded = "application/x-www-form-urlencoded",
90+
Text = "text/plain",
9091
}
9192

9293
export class HttpClient<SecurityDataType = unknown> {
@@ -141,6 +142,7 @@ export class HttpClient<SecurityDataType = unknown> {
141142
private contentFormatters: Record<ContentType, (input: any) => any> = {
142143
[ContentType.Json]: (input: any) =>
143144
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
145+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
144146
[ContentType.FormData]: (input: any) =>
145147
Object.keys(input || {}).reduce((formData, key) => {
146148
const property = input[key];

tests/generated/v2.0/petstore-minimal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export enum ContentType {
5959
Json = "application/json",
6060
FormData = "multipart/form-data",
6161
UrlEncoded = "application/x-www-form-urlencoded",
62+
Text = "text/plain",
6263
}
6364

6465
export class HttpClient<SecurityDataType = unknown> {
@@ -113,6 +114,7 @@ export class HttpClient<SecurityDataType = unknown> {
113114
private contentFormatters: Record<ContentType, (input: any) => any> = {
114115
[ContentType.Json]: (input: any) =>
115116
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
117+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
116118
[ContentType.FormData]: (input: any) =>
117119
Object.keys(input || {}).reduce((formData, key) => {
118120
const property = input[key];

tests/generated/v2.0/petstore-simple.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export enum ContentType {
7575
Json = "application/json",
7676
FormData = "multipart/form-data",
7777
UrlEncoded = "application/x-www-form-urlencoded",
78+
Text = "text/plain",
7879
}
7980

8081
export class HttpClient<SecurityDataType = unknown> {
@@ -129,6 +130,7 @@ export class HttpClient<SecurityDataType = unknown> {
129130
private contentFormatters: Record<ContentType, (input: any) => any> = {
130131
[ContentType.Json]: (input: any) =>
131132
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
133+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
132134
[ContentType.FormData]: (input: any) =>
133135
Object.keys(input || {}).reduce((formData, key) => {
134136
const property = input[key];

tests/generated/v2.0/petstore-swagger-io.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export enum ContentType {
112112
Json = "application/json",
113113
FormData = "multipart/form-data",
114114
UrlEncoded = "application/x-www-form-urlencoded",
115+
Text = "text/plain",
115116
}
116117

117118
export class HttpClient<SecurityDataType = unknown> {
@@ -166,6 +167,7 @@ export class HttpClient<SecurityDataType = unknown> {
166167
private contentFormatters: Record<ContentType, (input: any) => any> = {
167168
[ContentType.Json]: (input: any) =>
168169
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
170+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
169171
[ContentType.FormData]: (input: any) =>
170172
Object.keys(input || {}).reduce((formData, key) => {
171173
const property = input[key];

tests/generated/v2.0/petstore-with-external-docs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export enum ContentType {
6767
Json = "application/json",
6868
FormData = "multipart/form-data",
6969
UrlEncoded = "application/x-www-form-urlencoded",
70+
Text = "text/plain",
7071
}
7172

7273
export class HttpClient<SecurityDataType = unknown> {
@@ -121,6 +122,7 @@ export class HttpClient<SecurityDataType = unknown> {
121122
private contentFormatters: Record<ContentType, (input: any) => any> = {
122123
[ContentType.Json]: (input: any) =>
123124
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
125+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
124126
[ContentType.FormData]: (input: any) =>
125127
Object.keys(input || {}).reduce((formData, key) => {
126128
const property = input[key];

tests/generated/v2.0/petstore.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export enum ContentType {
6666
Json = "application/json",
6767
FormData = "multipart/form-data",
6868
UrlEncoded = "application/x-www-form-urlencoded",
69+
Text = "text/plain",
6970
}
7071

7172
export class HttpClient<SecurityDataType = unknown> {
@@ -120,6 +121,7 @@ export class HttpClient<SecurityDataType = unknown> {
120121
private contentFormatters: Record<ContentType, (input: any) => any> = {
121122
[ContentType.Json]: (input: any) =>
122123
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
124+
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
123125
[ContentType.FormData]: (input: any) =>
124126
Object.keys(input || {}).reduce((formData, key) => {
125127
const property = input[key];

0 commit comments

Comments
 (0)