| 1 | import * as JsonSchemaGenerator from "@effect/openapi-generator/JsonSchemaGenerator" |
| 2 | import { assert, describe, it } from "@effect/vitest" |
| 3 | |
| 4 | describe("JsonSchemaGenerator representation", () => { |
| 5 | it("preserves patterns in Unicode mode from code generation inputs", () => { |
| 6 | const generator = JsonSchemaGenerator.make() |
| 7 | generator.addSchema("Root", { type: "string", pattern: "^a+$" }) |
| 8 | |
| 9 | const output = generator.generate("openapi-3.1", {}, false) |
| 10 | |
| 11 | assert.include(output, `Schema.isPattern(new RegExp("^a+$", "u"))`) |
| 12 | }) |
| 13 | |
| 14 | it("emits only reachable definitions", () => { |
| 15 | const generator = JsonSchemaGenerator.make() |
| 16 | generator.addSchema("Root", { $ref: "#/components/schemas/Shared" }) |
| 17 | |
| 18 | const output = generator.generate("openapi-3.1", { |
| 19 | Shared: { type: "string" }, |
| 20 | Unused: { type: "boolean" } |
| 21 | }, false) |
| 22 | |
| 23 | assert.strictEqual( |
| 24 | output, |
| 25 | `// non-recursive definitions |
| 26 | export type Shared = string |
| 27 | export const Shared = Schema.String.annotate({ "identifier": "Shared" }) |
| 28 | // schemas |
| 29 | export type Root = Shared |
| 30 | export const Root = Shared |
| 31 | ` |
| 32 | ) |
| 33 | }) |
| 34 | }) |