|
| 1 | +import transformResponseObject, { TransformResponseObjectOptions } from "../src/transform/response-object.js"; |
| 2 | +import type { ResponseObject } from "../src/types.js"; |
| 3 | + |
| 4 | +const options: TransformResponseObjectOptions = { |
| 5 | + path: "#/test/response-object", |
| 6 | + ctx: { |
| 7 | + additionalProperties: false, |
| 8 | + alphabetize: false, |
| 9 | + emptyObjectsUnknown: false, |
| 10 | + defaultNonNullable: false, |
| 11 | + discriminators: {}, |
| 12 | + immutableTypes: false, |
| 13 | + indentLv: 0, |
| 14 | + operations: {}, |
| 15 | + parameters: {}, |
| 16 | + pathParamsAsTypes: false, |
| 17 | + postTransform: undefined, |
| 18 | + silent: true, |
| 19 | + supportArrayLength: false, |
| 20 | + transform: undefined, |
| 21 | + excludeDeprecated: false, |
| 22 | + }, |
| 23 | +}; |
| 24 | + |
| 25 | +describe("Response Object", () => { |
| 26 | + test("basic", () => { |
| 27 | + const schema: ResponseObject = { |
| 28 | + description: "basic", |
| 29 | + headers: { |
| 30 | + foo: { |
| 31 | + schema: { type: "string" } |
| 32 | + } |
| 33 | + }, |
| 34 | + content: { |
| 35 | + "application/json": { |
| 36 | + schema: { |
| 37 | + type: "object", |
| 38 | + properties: { |
| 39 | + url: { type: "string" }, |
| 40 | + "content-type": { type: "string" }, |
| 41 | + }, |
| 42 | + required: ["url"], |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }; |
| 47 | + const generated = transformResponseObject(schema, options); |
| 48 | + expect(generated).toBe(`{ |
| 49 | + headers: { |
| 50 | + foo?: string; |
| 51 | + }; |
| 52 | + content: { |
| 53 | + "application/json": { |
| 54 | + url: string; |
| 55 | + "content-type"?: string; |
| 56 | + }; |
| 57 | + }; |
| 58 | +}`); |
| 59 | + }); |
| 60 | + |
| 61 | + test("empty", () => { |
| 62 | + const schema: ResponseObject = { |
| 63 | + description: "empty", |
| 64 | + headers: { |
| 65 | + "some-header": { |
| 66 | + schema: { type: "string" } |
| 67 | + } |
| 68 | + } |
| 69 | + }; |
| 70 | + const generated = transformResponseObject(schema, options); |
| 71 | + expect(generated).toBe(`{ |
| 72 | + headers: { |
| 73 | + "some-header"?: string; |
| 74 | + }; |
| 75 | + content: never; |
| 76 | +}`) |
| 77 | + }); |
| 78 | +}); |
0 commit comments