fork of hey-api/openapi-ts because I need some additional things

Merge pull request #1594 from hey-api/fix/text-plain-serializer

fix: generate correct response for text/plain content type

authored by

Lubos and committed by
GitHub
548e5d8a c26e7924

+150 -5
+5
.changeset/green-dancers-pull.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: generate correct response for text/plain content type
+1 -1
packages/openapi-ts/src/ir/__tests__/mediaType.test.ts
··· 52 52 mediaType: 'text/javascript; charset=ISO-8859-1', 53 53 }, 54 54 { 55 - fileLike: true, 55 + fileLike: false, 56 56 mediaType: 'text/plain; charset=utf-8', 57 57 }, 58 58 {
+1 -1
packages/openapi-ts/src/ir/mediaType.ts
··· 1 1 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; 3 3 const jsonMimeRegExp = /^application\/(.*\+)?json(;.*)?$/i; 4 4 const multipartFormDataMimeRegExp = /^multipart\/form-data(;.*)?$/i; 5 5 const xWwwFormUrlEncodedMimeRegExp =
+7
packages/openapi-ts/test/2.0.x.test.ts
··· 36 36 const scenarios = [ 37 37 { 38 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 + }, 44 + { 45 + config: createConfig({ 39 46 input: 'enum-names-values.json', 40 47 output: 'enum-names-values', 41 48 }),
+7
packages/openapi-ts/test/3.0.x.test.ts
··· 65 65 }, 66 66 { 67 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 + }, 73 + { 74 + config: createConfig({ 68 75 input: 'case.json', 69 76 output: 'case', 70 77 plugins: [
+7
packages/openapi-ts/test/3.1.x.test.ts
··· 65 65 }, 66 66 { 67 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 + }, 73 + { 74 + config: createConfig({ 68 75 input: 'case.json', 69 76 output: 'case', 70 77 plugins: [
+2
packages/openapi-ts/test/__snapshots__/2.0.x/body-response-text-plain/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen';
+17
packages/openapi-ts/test/__snapshots__/2.0.x/body-response-text-plain/types.gen.ts
··· 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];
+2
packages/openapi-ts/test/__snapshots__/3.0.x/body-response-text-plain/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen';
+17
packages/openapi-ts/test/__snapshots__/3.0.x/body-response-text-plain/types.gen.ts
··· 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];
+2
packages/openapi-ts/test/__snapshots__/3.1.x/body-response-text-plain/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen';
+17
packages/openapi-ts/test/__snapshots__/3.1.x/body-response-text-plain/types.gen.ts
··· 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];
+3 -3
packages/openapi-ts/test/openapi-ts.config.ts
··· 3 3 export default defineConfig({ 4 4 client: { 5 5 // bundle: true, 6 - name: '@hey-api/client-nuxt', 6 + name: '@hey-api/client-fetch', 7 7 // name: 'legacy/xhr', 8 8 }, 9 9 // experimentalParser: false, ··· 11 11 // exclude: '^#/components/schemas/ModelWithCircularReference$', 12 12 // include: 13 13 // '^(#/components/schemas/import|#/paths/api/v{api-version}/simple/options)$', 14 - path: './packages/openapi-ts/test/spec/3.1.x/full.json', 14 + path: './packages/openapi-ts/test/spec/2.0.x/body-response-text-plain.yaml', 15 15 // path: './test/spec/v3-transforms.json', 16 16 // path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', 17 17 // path: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', ··· 74 74 }, 75 75 // @ts-ignore 76 76 { 77 - name: 'zod', 77 + // name: 'zod', 78 78 }, 79 79 ], 80 80 // useOptions: false,
+22
packages/openapi-ts/test/spec/2.0.x/body-response-text-plain.yaml
··· 1 + swagger: '2.0' 2 + info: 3 + title: OpenAPI 2.0 body response text plain example 4 + version: '1' 5 + paths: 6 + /foo: 7 + post: 8 + consumes: 9 + - text/plain 10 + produces: 11 + - text/plain 12 + parameters: 13 + - name: body 14 + in: body 15 + required: true 16 + schema: 17 + type: string 18 + responses: 19 + '200': 20 + description: OK 21 + schema: 22 + type: string
+20
packages/openapi-ts/test/spec/3.0.x/body-response-text-plain.yaml
··· 1 + openapi: 3.0.4 2 + info: 3 + title: OpenAPI 3.0.4 body response text plain example 4 + version: 1 5 + paths: 6 + /foo: 7 + post: 8 + requestBody: 9 + content: 10 + 'text/plain': 11 + schema: 12 + type: string 13 + required: true 14 + responses: 15 + '200': 16 + description: OK 17 + content: 18 + text/plain: 19 + schema: 20 + type: string
+20
packages/openapi-ts/test/spec/3.1.x/body-response-text-plain.yaml
··· 1 + openapi: 3.1.1 2 + info: 3 + title: OpenAPI 3.1.1 body response text plain example 4 + version: 1 5 + paths: 6 + /foo: 7 + post: 8 + requestBody: 9 + content: 10 + 'text/plain': 11 + schema: 12 + type: string 13 + required: true 14 + responses: 15 + '200': 16 + description: OK 17 + content: 18 + text/plain: 19 + schema: 20 + type: string