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
}

0 commit comments

Comments
 (0)