tsoa-next 7.2.1 → 7.3.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 +78 -10
- package/package.json +10 -7
- package/tsoa-next-logo-590.png +0 -0
package/README.MD
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
<!-- This file is generated from README.template.MD by `npm run sync:readmes`. Do not edit directly. -->
|
|
2
|
+
|
|
1
3
|
<div align="center">
|
|
2
|
-
<a href="https://
|
|
3
|
-
<h1>
|
|
4
|
+
<a href="https://tsoa-next.dev/" target="_blank" rel="noreferrer">
|
|
5
|
+
<h1>
|
|
6
|
+
<span style="display: inline-flex; align-items: center; gap: 0.35em; white-space: nowrap;">
|
|
7
|
+
<img src="./tsoa-next-logo-590.png" alt="tsoa-next logo" height="40" style="height: 1em; width: auto;" />
|
|
8
|
+
<span>tsoa-next</span>
|
|
9
|
+
</span>
|
|
10
|
+
</h1>
|
|
4
11
|
</a>
|
|
5
12
|
Pronounced so·uh
|
|
6
13
|
|
|
7
14
|
OpenAPI-compliant REST APIs using TypeScript and Node
|
|
8
15
|
|
|
9
|
-
](https://github.com/tsoa-next/tsoa-next/actions/workflows/runTestsOnPush.yml)
|
|
10
17
|
[](https://www.npmjs.com/package/tsoa-next)
|
|
18
|
+
[](https://sonarcloud.io/summary/new_code?id=tsoa-next_tsoa-next)
|
|
11
19
|
|
|
12
20
|
</div>
|
|
13
21
|
|
|
@@ -39,26 +47,86 @@ Where historical release notes or migration references still point upstream, the
|
|
|
39
47
|
- Runtime validation of tsoa-next should behave as closely as possible to the specifications that the generated OpenAPI 2/3 schema describes. Any differences in validation logic are clarified by logging warnings during the generation of the OpenAPI Specification (OAS) and/or the routes.
|
|
40
48
|
- Please note that by enabling OpenAPI 3 you minimize the chances of divergent validation logic since OpenAPI 3 has a more expressive schema syntax.
|
|
41
49
|
|
|
50
|
+
## External Validators
|
|
51
|
+
|
|
52
|
+
`@Validate(...)` adds opt-in runtime authority for external schemas on supported controller method parameters.
|
|
53
|
+
|
|
54
|
+
- Supported forms: `@Validate(schema)`, `@Validate('zod', schema)`, `@Validate({ kind: 'zod', schema })`
|
|
55
|
+
- Supported libraries: `zod`, `joi`, `yup`, `superstruct`, `io-ts`
|
|
56
|
+
- `io-ts` installs: add `fp-ts`, and add `io-ts-types` as well if you rely on helpers like `withMessage`
|
|
57
|
+
- Supported parameter decorators: `@Body`, `@BodyProp`, `@Query`, `@Queries`, `@Path`, `@Header`, and `@FormField` / uploaded file params
|
|
58
|
+
- Behavior: TypeScript metadata still drives OpenAPI generation, while the external schema replaces built-in runtime validation for the decorated parameter subtree
|
|
59
|
+
- Compatibility: routes without `@Validate(...)` keep their current behavior
|
|
60
|
+
|
|
61
|
+
Generated `RegisterRoutes(...)` functions also accept an optional validation context so applications can provide translation or failure-formatting hooks:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
RegisterRoutes(app, {
|
|
65
|
+
validation: {
|
|
66
|
+
translate: (key, params) => translateMessage(key, params),
|
|
67
|
+
errorFormatter: failure => failure,
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import * as t from 'io-ts'
|
|
74
|
+
import { withMessage } from 'io-ts-types'
|
|
75
|
+
import { Body, Controller, Post, Route, Validate } from '@tsoa-next/runtime'
|
|
76
|
+
|
|
77
|
+
interface PositiveFloatBrand {
|
|
78
|
+
readonly PositiveFloat: unique symbol
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const PositiveFloat = withMessage(
|
|
82
|
+
t.brand(t.number, (n): n is t.Branded<number, PositiveFloatBrand> => Number.isFinite(n) && n > 0, 'PositiveFloat'),
|
|
83
|
+
() => 'validation.wager.amount.mustBePositiveFloat',
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
const WagerCodec = t.type({
|
|
87
|
+
amount: PositiveFloat,
|
|
88
|
+
outcome: t.Int,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
type Wager = t.TypeOf<typeof WagerCodec>
|
|
92
|
+
|
|
93
|
+
@Route('wagers')
|
|
94
|
+
export class WagersController extends Controller {
|
|
95
|
+
@Post()
|
|
96
|
+
public createWager(
|
|
97
|
+
@Body()
|
|
98
|
+
@Validate('io-ts', WagerCodec)
|
|
99
|
+
wager: Wager,
|
|
100
|
+
): Wager {
|
|
101
|
+
return wager
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Migration Note
|
|
107
|
+
|
|
108
|
+
This feature is fully opt-in. If you do not use `@Validate(...)`, existing interface/class models, generated routes, validation behavior, and error responses are unchanged.
|
|
109
|
+
|
|
42
110
|
## Getting Started
|
|
43
111
|
|
|
44
112
|
- Requirements:
|
|
45
113
|
- Node.js 22 or newer
|
|
46
114
|
- npm 10 or newer
|
|
47
115
|
- We verify support across the previous LTS, current LTS, and Node vNext in CI
|
|
48
|
-
- [Documentation](https://
|
|
49
|
-
- [API Reference](https://
|
|
50
|
-
- [Getting started guide](https://
|
|
116
|
+
- [Documentation](https://tsoa-next.dev/)
|
|
117
|
+
- [API Reference](https://tsoa-next.dev/reference/)
|
|
118
|
+
- [Getting started guide](https://tsoa-next.dev/getting-started)
|
|
51
119
|
|
|
52
120
|
## Examples
|
|
53
121
|
|
|
54
|
-
Check out the [guides](https://
|
|
122
|
+
Check out the [guides](https://tsoa-next.dev/)
|
|
55
123
|
|
|
56
|
-
See example controllers in [the tests](https://github.com/
|
|
124
|
+
See example controllers in [the tests](https://github.com/tsoa-next/tsoa-next/tree/main/tests/fixtures/controllers)
|
|
57
125
|
|
|
58
|
-
See example models in [the tests](https://github.com/
|
|
126
|
+
See example models in [the tests](https://github.com/tsoa-next/tsoa-next/blob/main/tests/fixtures/testModel.ts)
|
|
59
127
|
|
|
60
128
|
## Help wanted
|
|
61
129
|
|
|
62
130
|
### Contributing code
|
|
63
131
|
|
|
64
|
-
To contribute (via a PR), please first see the [Contributing Guide](https://github.com/
|
|
132
|
+
To contribute (via a PR), please first see the [Contributing Guide](https://github.com/tsoa-next/tsoa-next/blob/main/docs/CONTRIBUTING.md)
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsoa-next",
|
|
3
|
-
"version": "7.2
|
|
3
|
+
"version": "7.3.2",
|
|
4
4
|
"description": "Build swagger-compliant REST APIs using TypeScript and Node",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"tsoa-next-logo-590.png"
|
|
9
10
|
],
|
|
10
11
|
"bin": {
|
|
11
12
|
"tsoa": "dist/cli.js"
|
|
@@ -28,11 +29,11 @@
|
|
|
28
29
|
"swagger",
|
|
29
30
|
"typescript"
|
|
30
31
|
],
|
|
31
|
-
"author": "
|
|
32
|
+
"author": "Vanna DiCatania <vanna@dicatania.me> (http://www.dicatania.me)",
|
|
32
33
|
"license": "MIT",
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@tsoa-next/cli": "7.2
|
|
35
|
-
"@tsoa-next/runtime": "7.2
|
|
35
|
+
"@tsoa-next/cli": "7.3.2",
|
|
36
|
+
"@tsoa-next/runtime": "7.3.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/node": "24.12.0",
|
|
@@ -40,7 +41,8 @@
|
|
|
40
41
|
},
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|
|
43
|
-
"url": "https://github.com/
|
|
44
|
+
"url": "https://github.com/tsoa-next/tsoa-next.git",
|
|
45
|
+
"directory": "packages/tsoa"
|
|
44
46
|
},
|
|
45
47
|
"engines": {
|
|
46
48
|
"node": ">=22.0.0",
|
|
@@ -49,5 +51,6 @@
|
|
|
49
51
|
"engineStrict": true,
|
|
50
52
|
"publishConfig": {
|
|
51
53
|
"access": "public"
|
|
52
|
-
}
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://tsoa-next.dev"
|
|
53
56
|
}
|
|
Binary file
|