@nxgt/typespec 0.13.1 → 0.13.2

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.
package/README.md CHANGED
@@ -339,7 +339,8 @@ model Place {
339
339
  Each is an OpenAPI component named as in GraphQL (`Latitude`, `URL`), with a
340
340
  `format`, a pattern or bounds approximating the rule, and `x-nxgt-scalar`
341
341
  naming it. The exact rules (checksums, ISO and IANA lists) are outside the
342
- pattern. TypeSpec's own `url` takes any scheme; `httpUrl` takes `http:` and
342
+ pattern; [`@nxgt/openapi-codegen`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars)'s
343
+ `scalars: 'exact'` checks them with the schemas of `@nxgt/zod`. TypeSpec's own `url` takes any scheme; `httpUrl` takes `http:` and
343
344
  `https:`. Every scalar by category, in
344
345
  [Scalars](docs/guide/scalars.md); the ids, the addresses and the columns, in
345
346
  [Scalars and columns](docs/guide/columns.md).
@@ -67,9 +67,12 @@ components:
67
67
  | `description` | The rule in words, and what the pattern leaves out. |
68
68
 
69
69
  A generator that knows nothing of `x-nxgt-scalar` still validates the pattern
70
- and the bounds. A later `@nxgt/openapi-codegen` release will map it to the exact
71
- Zod schema from `@nxgt/zod` ([roadmap](../roadmap.md)); until then, what a
72
- scalar leaves out is not checked.
70
+ and the bounds. `@nxgt/openapi-codegen` with
71
+ [`scalars: 'exact'`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars) maps it to the exact Zod
72
+ schema from `@nxgt/zod`, the checksum, the list or the `Intl` rule included;
73
+ with the default `'pattern'`, what a scalar leaves out is not checked. The
74
+ codecs (`dateTime`, `timestamp`, `bigInt`, `long`) keep their pattern under
75
+ `'exact'` too.
73
76
 
74
77
  ## Names
75
78
 
package/docs/roadmap.md CHANGED
@@ -10,9 +10,7 @@ Nothing in progress.
10
10
 
11
11
  ## Next
12
12
 
13
- - **Exact scalar rules in the generated code.** `@nxgt/openapi-codegen` maps
14
- `x-nxgt-scalar` to the exact Zod schema from `@nxgt/zod`: the checksums,
15
- the ISO and IANA lists and the `Intl` rules the patterns leave out.
13
+ Nothing planned beyond what is under Later.
16
14
 
17
15
  ## Later
18
16
 
@@ -27,6 +25,15 @@ Nothing in progress.
27
25
 
28
26
  ## Shipped
29
27
 
28
+ ### 0.13.2
29
+
30
+ - **Exact scalar rules in the generated code.** `@nxgt/openapi-codegen`
31
+ with `scalars: 'exact'` maps `x-nxgt-scalar` to the exact Zod schema from
32
+ `@nxgt/zod`: the checksums, the ISO and IANA lists, the `Intl` rules and the
33
+ refusal of `-0` the patterns leave out. The codecs keep their pattern until
34
+ `@nxgt/zod` offers their wire schemas. The guides and the troubleshooting
35
+ entries say so.
36
+
30
37
  ### 0.13.0
31
38
 
32
39
  - **The emitter `@nxgt/typespec`.** `emit: ["@nxgt/typespec"]` runs
@@ -628,12 +628,17 @@ one.
628
628
 
629
629
  **Why:** the scalar's pattern checks the shape. A list (`countryCode`,
630
630
  `currency`, `timeZone`, `locale`) or a checksum (`iban`, ISBN) does not fit in
631
- a pattern. `x-nxgt-scalar` names the exact rule, but `@nxgt/openapi-codegen`
632
- does not map it to the `@nxgt/zod` schema yet ([roadmap](roadmap.md)).
633
-
634
- **Fix:** until it does, check the value in the handler against the exact
635
- rule, the list or the checksum, from `@nxgt/zod` or your own table, and answer
636
- `400` as the generated validator does:
631
+ a pattern. `x-nxgt-scalar` names the exact rule, and `@nxgt/openapi-codegen`
632
+ maps it to the `@nxgt/zod` schema only with `scalars: 'exact'`; the default is
633
+ `'pattern'`.
634
+
635
+ **Fix:** generate with
636
+ [`scalars: 'exact'`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars)
637
+ (`bun add @nxgt/zod`, then `generate({ …, scalars: 'exact' })`): `iban` is
638
+ checked by `ibanSchema`, `countryCode` by its list of assigned codes. If you
639
+ cannot, check the value in the handler against the exact rule, the list or the
640
+ checksum, from `@nxgt/zod` or your own table, and answer `400` as the generated
641
+ validator does:
637
642
 
638
643
  ```ts
639
644
  if (!knownCountries.has(body.country)) {
@@ -651,7 +656,8 @@ where `@nxgt/graphql-scalars` refuses it.
651
656
  tell from `0`. For `nonNegativeInt`, `nonPositiveInt`, `port`, the bound holds,
652
657
  so the value passes (`positiveInt` and `negativeInt` refuse it by their bound).
653
658
 
654
- **Fix:** normalise in the handler when the sign matters:
659
+ **Fix:** generate with [`scalars: 'exact'`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars), whose schemas refuse `-0` for
660
+ an integer scalar. Otherwise normalise in the handler when the sign matters:
655
661
 
656
662
  ```ts
657
663
  const quantity = Object.is(body.quantity, -0) ? 0 : body.quantity;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/typespec",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -61,8 +61,9 @@
61
61
  }
62
62
  },
63
63
  "devDependencies": {
64
- "@nxgt/openapi-codegen": "^0.9.2",
64
+ "@nxgt/openapi-codegen": "^0.10.0",
65
65
  "@nxgt/openapi-hono": "^0.3.3",
66
+ "@nxgt/zod": "^0.1.3",
66
67
  "@types/bun": "^1.4.0",
67
68
  "@typespec/compiler": "1.17.0",
68
69
  "@typespec/http": "1.17.0",