@contractkit/openapi-to-ck 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.turbo/turbo-build$colon$ci.log +7 -7
  2. package/.turbo/turbo-test$colon$ci.log +30 -26
  3. package/CHANGELOG.md +117 -0
  4. package/LICENSE +21 -0
  5. package/README.md +30 -8
  6. package/dist/ast-to-ck.d.ts +32 -16
  7. package/dist/ast-to-ck.d.ts.map +1 -1
  8. package/dist/{chunk-JPI3AQ7V.js → chunk-Z53MK4FM.js} +196 -390
  9. package/dist/chunk-Z53MK4FM.js.map +1 -0
  10. package/dist/convert.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/normalize.d.ts +6 -2
  13. package/dist/normalize.d.ts.map +1 -1
  14. package/dist/paths-to-ast.d.ts +2 -0
  15. package/dist/paths-to-ast.d.ts.map +1 -1
  16. package/dist/plugin.d.ts.map +1 -1
  17. package/dist/plugin.js +18 -3
  18. package/dist/plugin.js.map +1 -1
  19. package/dist/schema-to-ast.d.ts +13 -1
  20. package/dist/schema-to-ast.d.ts.map +1 -1
  21. package/dist/tag-splitter.d.ts.map +1 -1
  22. package/dist/types.d.ts +28 -0
  23. package/dist/types.d.ts.map +1 -1
  24. package/package.json +5 -5
  25. package/src/ast-to-ck.ts +29 -453
  26. package/src/convert.ts +57 -3
  27. package/src/normalize.ts +87 -11
  28. package/src/paths-to-ast.ts +92 -11
  29. package/src/plugin.ts +17 -2
  30. package/src/schema-to-ast.ts +51 -7
  31. package/src/tag-splitter.ts +21 -16
  32. package/src/types.ts +28 -0
  33. package/tests/__snapshots__/kitchen-sink.ck +102 -0
  34. package/tests/ast-to-ck.test.ts +34 -17
  35. package/tests/component-refs.test.ts +114 -0
  36. package/tests/coverage.test.ts +246 -0
  37. package/tests/error-responses.test.ts +94 -0
  38. package/tests/fixtures/kitchen-sink-3.1.json +100 -0
  39. package/tests/helpers.ts +40 -0
  40. package/tests/kitchen-sink.test.ts +116 -0
  41. package/tests/schema-to-ast.test.ts +11 -2
  42. package/dist/chunk-JPI3AQ7V.js.map +0 -1
@@ -6,13 +6,13 @@ $ tsup src/index.ts src/plugin.ts --format esm --sourcemap --dts && tsc --emitDe
6
6
  CLI Target: esnext
7
7
  ESM Build start
8
8
  ESM dist/index.js 498.00 B
9
- ESM dist/plugin.js 2.51 KB
10
- ESM dist/chunk-JPI3AQ7V.js 51.50 KB
9
+ ESM dist/plugin.js 3.28 KB
10
+ ESM dist/chunk-Z53MK4FM.js 44.82 KB
11
11
  ESM dist/index.js.map 71.00 B
12
- ESM dist/plugin.js.map 4.95 KB
13
- ESM dist/chunk-JPI3AQ7V.js.map 120.62 KB
14
- ESM ⚡️ Build success in 243ms
12
+ ESM dist/plugin.js.map 6.11 KB
13
+ ESM dist/chunk-Z53MK4FM.js.map 111.74 KB
14
+ ESM ⚡️ Build success in 185ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 8914ms
17
- DTS dist/index.d.ts 9.00 KB
16
+ DTS ⚡️ Build success in 5204ms
17
+ DTS dist/index.d.ts 12.51 KB
18
18
  DTS dist/plugin.d.ts 128.00 B
@@ -3,32 +3,36 @@ $ vitest run --coverage
3
3
   RUN  v4.1.5 /home/runner/work/ContractKit/ContractKit/packages/openapi-to-ck
4
4
  Coverage enabled with v8
5
5
 
6
- ✓ tests/schema-to-ast.test.ts (36 tests) 123ms
7
- ✓ tests/normalize.test.ts (6 tests) 41ms
8
- ✓ tests/tag-splitter.test.ts (5 tests) 71ms
9
- ✓ tests/ast-to-ck.test.ts (45 tests) 243ms
10
- ✓ tests/convert.test.ts (17 tests) 346ms
11
- ✓ tests/circular-refs.test.ts (8 tests) 32ms
6
+ ✓ tests/schema-to-ast.test.ts (37 tests) 86ms
7
+ ✓ tests/ast-to-ck.test.ts (45 tests) 119ms
8
+ ✓ tests/convert.test.ts (17 tests) 1283ms
9
+ ✓ tests/coverage.test.ts (17 tests) 418ms
10
+ ✓ tests/normalize.test.ts (6 tests) 39ms
11
+ ✓ tests/component-refs.test.ts (4 tests) 67ms
12
+ ✓ tests/kitchen-sink.test.ts (7 tests) 996ms
13
+ ✓ tests/error-responses.test.ts (5 tests) 130ms
14
+ ✓ tests/circular-refs.test.ts (8 tests) 17ms
15
+ ✓ tests/tag-splitter.test.ts (5 tests) 17ms
12
16
 
13
-  Test Files  6 passed (6)
14
-  Tests  117 passed (117)
15
-  Start at  17:32:00
16
-  Duration  7.22s (transform 2.75s, setup 0ms, import 9.95s, tests 857ms, environment 1ms)
17
+  Test Files  10 passed (10)
18
+  Tests  151 passed (151)
19
+  Start at  16:35:30
20
+  Duration  8.18s (transform 2.04s, setup 0ms, import 14.38s, tests 3.17s, environment 1ms)
17
21
 
18
22
   % Coverage report from v8
19
- -------------------|---------|----------|---------|---------|-------------------------------------------------------------
20
- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
21
- -------------------|---------|----------|---------|---------|-------------------------------------------------------------
22
- All files | 81.5 | 71.07 | 94.82 | 84.21 |
23
- src | 81.27 | 71.27 | 93.68 | 83.86 |
24
- ast-to-ck.ts | 91.73 | 83.93 | 100 | 92.89 | 117-127,204,305,360,393-394,404,465
25
- circular-refs.ts | 100 | 90 | 100 | 100 | 20-23
26
- convert.ts | 77.19 | 87.5 | 80 | 77.77 | 83-98,112-117
27
- normalize.ts | 62.96 | 56.6 | 80 | 63.33 | 79,121-163,237-255,270-271,280-309,346,350,358
28
- paths-to-ast.ts | 85.07 | 66.99 | 100 | 91.45 | 101,126,131,141-142,150,193,207,248,323
29
- schema-to-ast.ts | 84.69 | 75 | 95.65 | 87.65 | 128-129,151,159,173,196-197,205-206,311-314,353-360,396-404
30
- tag-splitter.ts | 70 | 55.88 | 81.81 | 76.47 | 63-71,137-138,141-146,162-163,171-178
31
- warnings.ts | 100 | 100 | 100 | 100 |
32
- tests | 86.84 | 65.38 | 100 | 93.54 |
33
- helpers.ts | 86.84 | 65.38 | 100 | 93.54 | 139-140
34
- -------------------|---------|----------|---------|---------|-------------------------------------------------------------
23
+ -------------------|---------|----------|---------|---------|----------------------------------------------------------
24
+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
25
+ -------------------|---------|----------|---------|---------|----------------------------------------------------------
26
+ All files | 83.11 | 73.51 | 94.78 | 85.87 |
27
+ src | 83.18 | 74.02 | 95.45 | 85.52 |
28
+ ast-to-ck.ts | 100 | 100 | 100 | 100 |
29
+ circular-refs.ts | 100 | 90 | 100 | 100 | 20-23
30
+ convert.ts | 79.01 | 78.78 | 88.88 | 81.08 | 123-124,137-152,166-171
31
+ normalize.ts | 67.52 | 61.2 | 85.71 | 67.59 | 67-68,80,155,197-239,313-331,346-347,356-385,422,426,434
32
+ paths-to-ast.ts | 90.68 | 77.23 | 100 | 96.45 | 130,158,168,246,260
33
+ schema-to-ast.ts | 89.41 | 80.81 | 100 | 92.21 | 150-151,173,181,195,218-219,227-228,375-382
34
+ tag-splitter.ts | 85.71 | 78.94 | 90.9 | 89.02 | 71,153-154,167-168,179-183
35
+ warnings.ts | 100 | 100 | 100 | 100 |
36
+ tests | 82.14 | 64.7 | 92.59 | 91.11 |
37
+ helpers.ts | 82.14 | 64.7 | 92.59 | 91.11 | 142-143,179,184
38
+ -------------------|---------|----------|---------|---------|----------------------------------------------------------
package/CHANGELOG.md CHANGED
@@ -1,5 +1,122 @@
1
1
  # @contractkit/openapi-to-ck
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7b3b270: Import 4xx/5xx responses that declare a body as `(documented)`
8
+
9
+ **This changes the output of re-running the importer.** OpenAPI cannot say whether a handler
10
+ _returns_ a status or merely documents it, but `.ck` distinguishes the two and every generator
11
+ depends on the answer. Every declared status used to be imported as service-produced: a spec
12
+ declaring `404: {application/json: Error}` became `404: { … }`, which made the generated Koa
13
+ handler responsible for returning the 404 and made the TypeScript and Python SDKs hand it back
14
+ as a value rather than throwing.
15
+
16
+ A bodied 4xx or 5xx now imports as `404(documented): { … }` — the body is the error contract, the
17
+ SDK throws it as an `SdkError`, and the service is not responsible for producing it. 2xx and 3xx
18
+ are unchanged, as is a bare bodyless error status (marking those would be redundant, and core
19
+ warns about it).
20
+
21
+ Pass `errorResponses: 'emitted'`, or `--error-responses emitted` on the command line, to restore
22
+ the previous behaviour.
23
+
24
+ Also in this release:
25
+ - `$ref`s to `#/components/parameters`, `requestBodies`, `responses` and `headers` are now
26
+ resolved. A `$ref`'d parameter previously reached the printer with no name and emitted
27
+ `undefined: string` — which parses, so nothing reported it. Anything still unresolvable is
28
+ warned about and skipped instead of emitted.
29
+ - Every generated file is re-parsed before it is returned, and a file that does not parse is
30
+ reported as a warning rather than written out silently.
31
+ - The command line gained `--no-comments`, which was documented but never implemented.
32
+
33
+ Coverage, in the same release:
34
+ - `name:` is imported from an operation's `summary`, which used to be dropped entirely.
35
+ - Request bodies keep any RFC 6838 `type/subtype` content type. The importer previously allowed
36
+ only JSON, form-urlencoded and multipart, silently discarding everything else, even though the
37
+ grammar has accepted any mime since vendor MIME support landed.
38
+ - `format: duration` maps to the `duration` scalar, and the `idn-email`, `uri-reference`, `iri`
39
+ and `iri-reference` formats map alongside their existing counterparts.
40
+ - `additionalProperties: true` imports as `mode(loose)`.
41
+ - A spec-level `security` requirement now applies to operations that do not override it; it was
42
+ collected and never read, so a globally unsecured spec imported as secured.
43
+ - Constructs with no `.ck` equivalent are warned about rather than dropped in silence: `head`,
44
+ `options` and `trace` operations, non-numeric response keys (`default`, `4XX`), cookie
45
+ parameters, unparameterised mime types, and the `exclusiveMinimum`, `exclusiveMaximum`,
46
+ `multipleOf` and `uniqueItems` constraints. A `4XX` response key previously became status `4`,
47
+ because `parseInt` stops at the first non-digit.
48
+
49
+ ### Patch Changes
50
+
51
+ - fd62377: Fix tag splitting, schema-name sanitization, and stale docs
52
+ - A model reached only from a `params`, `query` or `headers` block was filed under `shared.ck`
53
+ instead of its own tag's file. `collectParamSourceRefs` was written against the shape
54
+ `ParamSource` had before it became a tagged union, so only the `ref` case still worked — and
55
+ only by coincidence, since it happens to look like a model reference.
56
+ - A schema whose name starts with a digit (`3DModel`) produced an identifier the parser rejects.
57
+ It is now prefixed with `_`.
58
+ - `@scalar/openapi-parser` has been removed from the dependencies. It was never imported; the
59
+ normalization is hand-written, despite a comment claiming otherwise.
60
+ - The README documented an `openapi-to-ck --input …` command that does not exist. The command is
61
+ `import-openapi <spec-path>`, and the docs now cover `--no-comments`, `--error-responses`, and
62
+ what the converter warns about rather than dropping silently.
63
+
64
+ - 841af6e: Only wrap a circular reference in `lazy()` where it breaks a real cycle
65
+
66
+ `lazy()` exists so that a reference between two contracts that depend on each other can be
67
+ deferred: `topoSortModels` emits dependencies before dependents and can only fall back to source
68
+ order for a cycle. A reference from an operation — a response body, request body, parameter, or
69
+ response header — names a model the generated module has already imported and fully evaluated,
70
+ so there is no cycle to break.
71
+
72
+ Every reference to a self-referential schema used to be wrapped, so importing a spec with a tree-
73
+ shaped model produced `application/json: lazy(Widget)` on every body mentioning it. References
74
+ inside a contract, including one extracted from an inline body schema, still wrap as before.
75
+
76
+ Also fixed: a model extracted from an inline request or response body schema was referenced by
77
+ the generated operation and never emitted, because the extracted-model list was read before path
78
+ conversion filled it. Any spec with an inline (non-`$ref`) body schema produced a contract
79
+ pointing at something that did not exist. The post-conversion self-check now runs reference
80
+ validation as well as parsing, which is what caught it — a reference to an undefined contract is
81
+ perfectly good syntax, so parsing alone could not.
82
+
83
+ - aea5e21: Move the `.ck` printer into core, so the language has exactly one
84
+
85
+ `.ck` had two printers: the prettier plugin's `printCk` and a hand-rolled one inside
86
+ `openapi-to-ck`. Only the prettier copy was covered by the round-trip tests that the grammar
87
+ checklist points at, so the other silently fell behind the grammar — it ignored `hasBlock` and
88
+ the `(documented)` response modifier, could not emit `mcp:`, `plugins:`, `name:`, `override`,
89
+ `format(output=)` or options-level header globals, and emitted source that does not parse for a
90
+ regex containing `/` or an enum value carrying both quote styles.
91
+
92
+ `printCk` now lives in `@contractkit/core` next to `parseCk` and is exported from it. The
93
+ prettier plugin re-exports it unchanged, and `openapi-to-ck`'s `astToCk` is a thin adapter over
94
+ it, so all of the above now print correctly.
95
+
96
+ Three printing fixes come with the move, all of which affect `pnpm format` on existing files:
97
+ - A regex containing `/` prints as `regex="…"` instead of an unterminated regex literal.
98
+ - A string containing `"` prints single-quoted; one carrying both quote styles is degraded
99
+ rather than emitted unparseable (use the new `isUnquotable` to warn before printing).
100
+ - A description containing newlines is flattened when it prints as a trailing `# …` comment,
101
+ instead of leaking the remainder as raw source.
102
+
103
+ Files containing any of these currently cannot round-trip at all, so this is a fix rather than a
104
+ break. `openapi-to-ck` output changes shape in two ways: model descriptions now print as a
105
+ doc-comment block above the `contract` rather than as a trailing comment, and scalar constraints
106
+ use the canonical `len=` / positional `format` spellings.
107
+
108
+ - Updated dependencies [aea5e21]
109
+ - Updated dependencies [5dc2693]
110
+ - @contractkit/core@0.27.0
111
+
112
+ ## 0.10.2
113
+
114
+ ### Patch Changes
115
+
116
+ - ca1c139: Declare the MIT license explicitly: every package now ships a `LICENSE` file in its published tarball and sets `"license": "MIT"` in its manifest, so license scanners and registries report the terms correctly.
117
+ - Updated dependencies [ca1c139]
118
+ - @contractkit/core@0.26.1
119
+
3
120
  ## 0.10.1
4
121
 
5
122
  ### Patch Changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marooned Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,18 +10,19 @@ pnpm add -D @contractkit/openapi-to-ck
10
10
 
11
11
  ## Use as a CLI subcommand
12
12
 
13
- When the package is installed, the `@contractkit/cli` binary picks up an `openapi-to-ck` subcommand:
13
+ When the package is installed, the `@contractkit/cli` binary picks up an `import-openapi` subcommand. The spec path is a positional argument:
14
14
 
15
15
  ```bash
16
- contractkit openapi-to-ck --input openapi.yaml --output contracts/
16
+ contractkit import-openapi openapi.yaml --output contracts/
17
17
  ```
18
18
 
19
19
  | Flag | Description |
20
20
  | --- | --- |
21
- | `--input <path>` | Path to an OpenAPI YAML or JSON file. |
22
- | `--output <dir>` | Directory to write `.ck` files into. |
21
+ | `<spec-path>` | Positional. Path to an OpenAPI YAML or JSON file. |
22
+ | `-o, --output <dir>` | Directory to write `.ck` files into. Defaults to the current directory. |
23
23
  | `--split <single \| by-tag>` | Output mode. `by-tag` (default) writes one file per OpenAPI tag; `single` writes one combined file. |
24
24
  | `--no-comments` | Don't emit OpenAPI descriptions as `#` comments. |
25
+ | `--error-responses <documented \| emitted>` | How to import a 4xx/5xx that declares a body. See [Error responses](#error-responses). |
25
26
 
26
27
  ## Programmatic use
27
28
 
@@ -32,6 +33,7 @@ const { files, warnings } = await convertOpenApiToCk({
32
33
  input: 'openapi.yaml', // file path, JSON/YAML string, or pre-parsed object
33
34
  split: 'by-tag', // 'single' | 'by-tag' (default: 'by-tag')
34
35
  includeComments: true, // emit OpenAPI descriptions as # comments (default: true)
36
+ errorResponses: 'documented', // 'documented' | 'emitted' (default: 'documented')
35
37
  onWarning: w => console.warn(w),
36
38
  });
37
39
 
@@ -41,7 +43,17 @@ for (const [filename, source] of files) {
41
43
  }
42
44
  ```
43
45
 
44
- `Warning` entries carry a JSON-pointer-style `path` into the OpenAPI spec, a human-readable `message`, and a `severity` of `'info' | 'warn'`.
46
+ `Warning` entries carry a JSON-pointer-style `path` into the OpenAPI spec, a human-readable `message`, and a `severity` of `'info' | 'warn'`. Anything the spec declares that `.ck` cannot express is reported this way rather than dropped in silence — `head`/`options`/`trace` operations, non-numeric response keys such as `default` or `4XX`, cookie parameters, content types that are not a plain `type/subtype`, and the `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf` and `uniqueItems` constraints. Every generated file is also re-parsed before it is returned, so output that would not compile arrives as a warning instead of as a broken file on disk.
47
+
48
+ ## Error responses
49
+
50
+ OpenAPI cannot say whether a service *produces* a status or merely documents it. `.ck` draws that distinction, and it decides what the generated router writes and whether the SDKs return a status or throw it.
51
+
52
+ By default a 4xx or 5xx that declares a body is imported as `404(documented): { ... }`: the body is the error contract, the SDKs throw it as an `SdkError`, and the service is not responsible for returning it. 2xx and 3xx are imported as service-produced, as is a bare bodyless error status — marking those would be redundant.
53
+
54
+ Pass `errorResponses: 'emitted'` to import every declared status as service-produced instead.
55
+
56
+ A spec generated by `@contractkit/plugin-openapi` carries `x-contractkit-emit` on responses that were marked `(documented)`, and that is honoured ahead of the status-code default — so a `.ck` → OpenAPI → `.ck` round trip preserves the distinction exactly, including on a 2xx.
45
57
 
46
58
  ## What's converted
47
59
 
@@ -53,7 +65,13 @@ for (const [filename, source] of files) {
53
65
  | `requestBody.content[mime].schema` | `request: { mime: Type }` |
54
66
  | `responses[code].content[mime].schema` | `response: { code: { mime: Type } }` |
55
67
  | `responses[code].headers` | per-status `headers: { name: type }` |
56
- | `allOf` | `&` intersection on `contract` declarations |
68
+ | `responses[code]` for a bodied 4xx/5xx | `code(documented): { ... }` (see [Error responses](#error-responses)) |
69
+ | `summary` | `name:` |
70
+ | `operationId` | `sdk:` |
71
+ | `deprecated` | `get(deprecated)` |
72
+ | `security: []`, at spec or operation level | `security: none` |
73
+ | `additionalProperties: true` | `mode(loose)` |
74
+ | `allOf` | `&` inheritance on `contract` declarations |
57
75
  | `oneOf` + `discriminator` | `discriminated(by=field, A \| B)` |
58
76
  | `oneOf` / `anyOf` (no discriminator) | `\|` union |
59
77
  | `enum`, `pattern`, `minimum/maximum`, `minLength/maxLength` | type constraint args |
@@ -71,8 +89,12 @@ import {
71
89
  detectCircularRefs, // find $ref cycles
72
90
  extractRefName, // "#/components/schemas/Foo" → "Foo"
73
91
  sanitizeName, // turn an arbitrary string into a valid CK identifier
74
- normalize, // upgrade 2.0/3.0 → 3.1 + dereference
75
- astToCk, // ContractKit AST → `.ck` source string
92
+ normalize, // upgrade 2.0/3.0 → 3.1 + inline non-schema component $refs
93
+ astToCk, // ContractKit AST → `.ck` source string (delegates to core's printCk)
76
94
  serializeType, // ContractTypeNode → `.ck` type expression
77
95
  } from '@contractkit/openapi-to-ck';
78
96
  ```
97
+
98
+ `astToCk` and `serializeType` are thin adapters over `printCk` and `printType` from
99
+ `@contractkit/core`. `.ck` has one printer, shared with the prettier plugin, so a grammar change
100
+ lands in one place; call the core functions directly if you have no reason to go through here.
@@ -1,22 +1,38 @@
1
- import type { CkRootNode, ContractTypeNode } from '@contractkit/core';
2
- /** Options controlling how a {@link CkRootNode} is rendered to `.ck` source. */
1
+ import type { CkRootNode } from '@contractkit/core';
2
+ import { printType } from '@contractkit/core';
3
+ /**
4
+ * `.ck` serialization for the OpenAPI importer.
5
+ *
6
+ * This module used to carry its own printer. `.ck` had two of them — this one and the prettier
7
+ * plugin's — and only the prettier copy was covered by the round-trip tests that the
8
+ * `ck-grammar-change` checklist points at, so this one silently fell behind the grammar: it
9
+ * ignored `hasBlock` and the `(documented)` response modifier, could not emit `mcp:`,
10
+ * `plugins:`, `name:`, `override`, `format(output=)` or options-level header globals, and
11
+ * emitted unparseable source for a regex containing `/` or an enum value containing both quote
12
+ * styles.
13
+ *
14
+ * The printer now lives in `@contractkit/core` next to `parseCk`, and this module is a thin
15
+ * adapter over it. A grammar change has one printer to update.
16
+ */
17
+ /**
18
+ * Options controlling how a {@link CkRootNode} is rendered to `.ck` source.
19
+ *
20
+ * @deprecated `includeComments` is a no-op and is kept only so existing callers still compile.
21
+ * Comments are controlled upstream: `ConvertOptions.includeComments` gates every `description`
22
+ * assignment in `schema-to-ast.ts` and `paths-to-ast.ts`, so when it is off the descriptions are
23
+ * absent from the AST and there is nothing left for the printer to suppress.
24
+ */
3
25
  export interface SerializeOptions {
4
- /** Emit descriptions as inline # comments. Default: true. */
26
+ /** No-op. See the deprecation note on {@link SerializeOptions}. */
5
27
  includeComments?: boolean;
6
28
  }
7
29
  /**
8
- * Serialize a `.ck` AST back to formatted `.ck` source text. Emits the options
9
- * block first, then every model, then every route, separated by blank lines and
10
- * terminated with a trailing newline. Descriptions become trailing `# ...`
11
- * comments unless `options.includeComments` is `false`. The output is designed
12
- * to re-parse cleanly via `parseCk` (see round-trip tests).
13
- */
14
- export declare function astToCk(root: CkRootNode, options?: SerializeOptions): string;
15
- /**
16
- * Serialize a single {@link ContractTypeNode} to its inline `.ck` type
17
- * expression (e.g. `array(User, min=1)`, `string | int`, `enum(asc, desc)`).
18
- * Recurses through composite types; enum values are quoted as needed via
19
- * {@link quoteEnumValue}.
30
+ * Serialize a `.ck` AST back to formatted `.ck` source text.
31
+ *
32
+ * Delegates to `printCk`, which prints from a `CkRootNode` alone no Ohm CST and no original
33
+ * source so programmatically built nodes print correctly.
20
34
  */
21
- export declare function serializeType(type: ContractTypeNode): string;
35
+ export declare function astToCk(root: CkRootNode, _options?: SerializeOptions): string;
36
+ /** Render a `ContractTypeNode` to its `.ck` source string. Re-exported from core. */
37
+ export declare const serializeType: typeof printType;
22
38
  //# sourceMappingURL=ast-to-ck.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast-to-ck.d.ts","sourceRoot":"","sources":["../src/ast-to-ck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EAGV,gBAAgB,EAUnB,MAAM,mBAAmB,CAAC;AAiC3B,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAC7B,6DAA6D;IAC7D,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAoBhF;AAkID;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CA2B5D"}
1
+ {"version":3,"file":"ast-to-ck.d.ts","sourceRoot":"","sources":["../src/ast-to-ck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAW,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC7B,mEAAmE;IACnE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,GAAE,gBAAqB,GAAG,MAAM,CAEjF;AAED,qFAAqF;AACrF,eAAO,MAAM,aAAa,kBAAY,CAAC"}