|
| 1 | +import type { GlobalContext, OperationObject } from "../src/types.js"; |
| 2 | +import transformOperationObject from "../src/transform/operation-object.js"; |
| 3 | + |
| 4 | +const ctx: GlobalContext = { |
| 5 | + additionalProperties: false, |
| 6 | + alphabetize: false, |
| 7 | + defaultNonNullable: false, |
| 8 | + discriminators: {}, |
| 9 | + emptyObjectsUnknown: false, |
| 10 | + immutableTypes: false, |
| 11 | + indentLv: 0, |
| 12 | + operations: {}, |
| 13 | + parameters: {}, |
| 14 | + pathParamsAsTypes: false, |
| 15 | + postTransform: undefined, |
| 16 | + silent: true, |
| 17 | + supportArrayLength: false, |
| 18 | + transform: undefined, |
| 19 | + excludeDeprecated: false, |
| 20 | +}; |
| 21 | + |
| 22 | +describe("Operation Object", () => { |
| 23 | + it("allows 2XX codes", () => { |
| 24 | + const schema: OperationObject = { |
| 25 | + responses: { |
| 26 | + "2XX": { |
| 27 | + description: "OK", |
| 28 | + content: { |
| 29 | + "application/json": { |
| 30 | + schema: { type: "string" }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + "4XX": { |
| 35 | + description: "OK", |
| 36 | + content: { |
| 37 | + "application/json": { schema: { $ref: 'components["schemas"]["Error"]' } }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + "5XX": { |
| 41 | + description: "OK", |
| 42 | + content: { |
| 43 | + "application/json": { schema: { $ref: 'components["schemas"]["Error"]' } }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }; |
| 48 | + const generated = transformOperationObject(schema, { ctx, path: "#/paths/~get-item" }); |
| 49 | + expect(generated).toBe(`{ |
| 50 | + responses: { |
| 51 | + /** @description OK */ |
| 52 | + "2XX": { |
| 53 | + content: { |
| 54 | + "application/json": string; |
| 55 | + }; |
| 56 | + }; |
| 57 | + /** @description OK */ |
| 58 | + "4XX": { |
| 59 | + content: { |
| 60 | + "application/json": components["schemas"]["Error"]; |
| 61 | + }; |
| 62 | + }; |
| 63 | + /** @description OK */ |
| 64 | + "5XX": { |
| 65 | + content: { |
| 66 | + "application/json": components["schemas"]["Error"]; |
| 67 | + }; |
| 68 | + }; |
| 69 | + }; |
| 70 | +}`); |
| 71 | + }); |
| 72 | +}); |
0 commit comments