Skip to content

Commit bc66cde

Browse files
committed
fix: generate correct response for text/plain content type
1 parent b463bbf commit bc66cde

File tree

16 files changed

+150
-5
lines changed

16 files changed

+150
-5
lines changed

.changeset/green-dancers-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: generate correct response for text/plain content type

packages/openapi-ts/src/ir/__tests__/mediaType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('isMediaTypeFileLike', () => {
5252
mediaType: 'text/javascript; charset=ISO-8859-1',
5353
},
5454
{
55-
fileLike: true,
55+
fileLike: false,
5656
mediaType: 'text/plain; charset=utf-8',
5757
},
5858
{

packages/openapi-ts/src/ir/mediaType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fileLikeRegExp =
2-
/^(application\/(pdf|rtf|msword|vnd\.(ms-|openxmlformats-officedocument\.)|zip|x-(7z|tar|rar|zip|iso)|octet-stream|gzip|x-msdownload|json\+download|xml|x-yaml|x-7z-compressed|x-tar)|text\/(plain|yaml|css|javascript)|audio\/(mpeg|wav)|video\/(mp4|x-matroska)|image\/(vnd\.adobe\.photoshop|svg\+xml))(; ?charset=[^;]+)?$/i;
2+
/^(application\/(pdf|rtf|msword|vnd\.(ms-|openxmlformats-officedocument\.)|zip|x-(7z|tar|rar|zip|iso)|octet-stream|gzip|x-msdownload|json\+download|xml|x-yaml|x-7z-compressed|x-tar)|text\/(yaml|css|javascript)|audio\/(mpeg|wav)|video\/(mp4|x-matroska)|image\/(vnd\.adobe\.photoshop|svg\+xml))(; ?charset=[^;]+)?$/i;
33
const jsonMimeRegExp = /^application\/(.*\+)?json(;.*)?$/i;
44
const multipartFormDataMimeRegExp = /^multipart\/form-data(;.*)?$/i;
55
const xWwwFormUrlEncodedMimeRegExp =

packages/openapi-ts/test/2.0.x.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ describe(`OpenAPI ${version}`, () => {
3434
});
3535

3636
const scenarios = [
37+
{
38+
config: createConfig({
39+
input: 'body-response-text-plain.yaml',
40+
output: 'body-response-text-plain',
41+
}),
42+
description: 'handle text/plain content type',
43+
},
3744
{
3845
config: createConfig({
3946
input: 'enum-names-values.json',

packages/openapi-ts/test/3.0.x.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ describe(`OpenAPI ${version}`, () => {
6363
description:
6464
'generates correct array when items are oneOf array with single item',
6565
},
66+
{
67+
config: createConfig({
68+
input: 'body-response-text-plain.yaml',
69+
output: 'body-response-text-plain',
70+
}),
71+
description: 'handle text/plain content type',
72+
},
6673
{
6774
config: createConfig({
6875
input: 'case.json',

packages/openapi-ts/test/3.1.x.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ describe(`OpenAPI ${version}`, () => {
6363
description:
6464
'generates correct array when items are oneOf array with single item',
6565
},
66+
{
67+
config: createConfig({
68+
input: 'body-response-text-plain.yaml',
69+
output: 'body-response-text-plain',
70+
}),
71+
description: 'handle text/plain content type',
72+
},
6673
{
6774
config: createConfig({
6875
input: 'case.json',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type PostFooData = {
4+
body: string;
5+
path?: never;
6+
query?: never;
7+
url: '/foo';
8+
};
9+
10+
export type PostFooResponses = {
11+
/**
12+
* OK
13+
*/
14+
200: string;
15+
};
16+
17+
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type PostFooData = {
4+
body: string;
5+
path?: never;
6+
query?: never;
7+
url: '/foo';
8+
};
9+
10+
export type PostFooResponses = {
11+
/**
12+
* OK
13+
*/
14+
200: string;
15+
};
16+
17+
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];

0 commit comments

Comments
 (0)