Skip to content

Commit 10f19cf

Browse files
author
Jochen Diekenbrock
committed
fix: handling for consumes plain/text and consumes with parameter charset
1 parent 3bb7441 commit 10f19cf

File tree

7 files changed

+38
-1
lines changed

7 files changed

+38
-1
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: 8 additions & 1 deletion
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 {
@@ -207,7 +208,7 @@ class SchemaRoutes {
207208

208209
getContentKind = (contentTypes) => {
209210
if (
210-
_.includes(contentTypes, "application/json") ||
211+
_.some(contentTypes, (contentType) => _.startsWith(contentType, "application/json")) ||
211212
_.some(contentTypes, (contentType) => _.endsWith(contentType, "+json"))
212213
) {
213214
return CONTENT_KIND.JSON;
@@ -225,6 +226,12 @@ class SchemaRoutes {
225226
return CONTENT_KIND.IMAGE;
226227
}
227228

229+
if (
230+
_.some(contentTypes, (contentType) => _.startsWith(contentType, "text/"))
231+
) {
232+
return CONTENT_KIND.TEXT;
233+
}
234+
228235
return CONTENT_KIND.OTHER;
229236
};
230237

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

Lines changed: 1 addition & 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> {

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

Lines changed: 1 addition & 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> {

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/schemas/v2.0/api-with-examples.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,30 @@ paths:
165165
]
166166
}
167167
}
168+
/with-charset/:
169+
post:
170+
operationId: with-charset
171+
summary: consumes contains charset
172+
description: consumes contains charset
173+
consumes:
174+
- application/json;charset=UTF-8
175+
produces:
176+
- application/json;charset=UTF-8
177+
parameters:
178+
- in: body
179+
name: someParm
180+
type: string
181+
/consumes-plain-text/:
182+
post:
183+
operationId: consumes-plain-text
184+
summary: consumes plain text
185+
description: consumes plain text
186+
consumes:
187+
- text/plain
188+
parameters:
189+
- in: body
190+
name: someParm
191+
type: string
192+
168193
consumes:
169194
- application/json

0 commit comments

Comments
 (0)