@vercube/schema 0.0.22 → 0.0.23
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 +20 -21
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +35 -35
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
<br>
|
|
4
4
|
<br>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
# Vercube
|
|
7
|
+
|
|
8
|
+
Next generation HTTP framework
|
|
9
|
+
|
|
10
10
|
<a href="https://www.npmjs.com/package/@vercube/schema">
|
|
11
11
|
<img src="https://img.shields.io/npm/v/%40vercube%2Fschema?style=for-the-badge&logo=npm&color=%23767eff" alt="npm"/>
|
|
12
12
|
</a>
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
<a href="https://github.com/vercube/vercube/blob/main/LICENSE" target="_blank">
|
|
17
17
|
<img src="https://img.shields.io/npm/l/%40vercube%2Fschema?style=for-the-badge&color=%23767eff" alt="License"/>
|
|
18
18
|
</a>
|
|
19
|
+
<a href="https://codecov.io/gh/vercube/vercube" target="_blank">
|
|
20
|
+
<img src="https://img.shields.io/codecov/c/github/vercube/vercube?style=for-the-badge&color=%23767eff" alt="Coverage"/>
|
|
21
|
+
</a>
|
|
19
22
|
<br/>
|
|
20
23
|
<br/>
|
|
21
24
|
</div>
|
|
@@ -43,7 +46,7 @@ It abstracts schema definitions into a consistent API that works across tools an
|
|
|
43
46
|
|
|
44
47
|
```bash
|
|
45
48
|
pnpm install @vercube/schema
|
|
46
|
-
|
|
49
|
+
```
|
|
47
50
|
|
|
48
51
|
---
|
|
49
52
|
|
|
@@ -58,7 +61,7 @@ import { SchemaPlugin } from '@vercube/schema';
|
|
|
58
61
|
const app = createApp({
|
|
59
62
|
setup: async (app) => {
|
|
60
63
|
app.addPlugin(SchemaPlugin);
|
|
61
|
-
}
|
|
64
|
+
},
|
|
62
65
|
});
|
|
63
66
|
```
|
|
64
67
|
|
|
@@ -70,12 +73,11 @@ The `@Schema` decorator lets you define OpenAPI-compatible schema definitions di
|
|
|
70
73
|
It leverages [`@asteasolutions/zod-to-openapi`](https://github.com/asteasolutions/zod-to-openapi) for automatic schema translation and also supports `.openapi` properties on Zod schemas.
|
|
71
74
|
|
|
72
75
|
```ts
|
|
73
|
-
import { Controller, Post
|
|
76
|
+
import { Body, Controller, Post } from '@vercube/core';
|
|
74
77
|
import { Schema } from '@vercube/schema';
|
|
75
78
|
|
|
76
79
|
@Controller('/users')
|
|
77
80
|
export class UsersController {
|
|
78
|
-
|
|
79
81
|
@Post('/')
|
|
80
82
|
@Schema({
|
|
81
83
|
request: {
|
|
@@ -92,9 +94,7 @@ export class UsersController {
|
|
|
92
94
|
},
|
|
93
95
|
},
|
|
94
96
|
})
|
|
95
|
-
public async insertUser(
|
|
96
|
-
@Body({ validationSchema: UserSchema }) user: User,
|
|
97
|
-
): Promise<void> {
|
|
97
|
+
public async insertUser(@Body({ validationSchema: UserSchema }) user: User): Promise<void> {
|
|
98
98
|
console.log(user);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -106,6 +106,7 @@ When the SchemaPlugin is added to your application, a special controller is auto
|
|
|
106
106
|
This controller exposes the full OpenAPI schema at runtime and is available without any additional configuration.
|
|
107
107
|
|
|
108
108
|
You can access it at:
|
|
109
|
+
|
|
109
110
|
```
|
|
110
111
|
http://localhost:3000/_schema
|
|
111
112
|
```
|
|
@@ -114,12 +115,11 @@ This makes it easy to integrate with tools like Swagger UI, Postman, or for debu
|
|
|
114
115
|
|
|
115
116
|
### ✨ Automatic Resolution
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* Path parameters (`@Params`)
|
|
118
|
+
- The `@Schema` decorator automatically resolves:
|
|
119
|
+
- HTTP method and route path
|
|
120
|
+
- Request body schema (`@Body`)
|
|
121
|
+
- Query parameters (`@QueryParams`)
|
|
122
|
+
- Path parameters (`@Params`)
|
|
123
123
|
|
|
124
124
|
---
|
|
125
125
|
|
|
@@ -134,13 +134,12 @@ Explore guides, API references, and best practices to master Vercube.
|
|
|
134
134
|
|
|
135
135
|
This module is inspired by:
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
- [@asteasolutions/zod-to-openapi](https://github.com/asteasolutions/zod-to-openapi)
|
|
138
|
+
- [Hono Zod OpenAPI Example](https://hono.dev/examples/zod-openapi)
|
|
139
|
+
- [Nitro OpenAPI](https://nitro.build/config#openapi)
|
|
140
140
|
|
|
141
141
|
---
|
|
142
142
|
|
|
143
143
|
## 🪪 License
|
|
144
144
|
|
|
145
145
|
[MIT License](https://github.com/vercube/vercube/blob/main/LICENSE)
|
|
146
|
-
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
import { OpenAPIRegistry, OpenApiGeneratorV3, extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
3
|
+
import { z } from "zod";
|
|
4
4
|
import { BaseDecorator, Inject, createDecorator } from "@vercube/di";
|
|
5
5
|
import defu from "defu";
|
|
6
6
|
import { BasePlugin, Controller, Get } from "@vercube/core";
|
|
@@ -30,6 +30,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
enumerable: true
|
|
31
31
|
}) : target, mod));
|
|
32
32
|
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/Resolvers/SchemaBodyResolver.ts
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the body schema for a given method.
|
|
37
|
+
* @param metadata - The metadata of the method.
|
|
38
|
+
* @param schema - The schema to resolve the body for.
|
|
39
|
+
* @returns void
|
|
40
|
+
*/
|
|
41
|
+
function SchemaBodyResolver(metadata, schema) {
|
|
42
|
+
const body = metadata.args.find((arg) => arg.type === "body");
|
|
43
|
+
if (!body || !body.validationSchema) return;
|
|
44
|
+
schema.request = defu(schema?.request ?? {}, { body: { content: { "application/json": { schema: body.validationSchema } } } });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/Resolvers/SchemaQueryParamsResolver.ts
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the query params schema for a given method.
|
|
51
|
+
* @param metadata - The metadata of the method.
|
|
52
|
+
* @param schema - The schema to resolve the query params for.
|
|
53
|
+
* @returns void
|
|
54
|
+
*/
|
|
55
|
+
function SchemaQueryParamsResolver(metadata, schema) {
|
|
56
|
+
const query = metadata.args.find((arg) => arg.type === "query-params");
|
|
57
|
+
if (!query || !query.validationSchema) return;
|
|
58
|
+
schema.request = defu(schema?.request ?? {}, { query: query.validationSchema });
|
|
59
|
+
}
|
|
60
|
+
|
|
33
61
|
//#endregion
|
|
34
62
|
//#region src/Services/SchemaRegistry.ts
|
|
35
63
|
/**
|
|
@@ -70,36 +98,8 @@ var SchemaRegistry = class {
|
|
|
70
98
|
};
|
|
71
99
|
|
|
72
100
|
//#endregion
|
|
73
|
-
//#region src/
|
|
74
|
-
|
|
75
|
-
* Resolves the body schema for a given method.
|
|
76
|
-
* @param metadata - The metadata of the method.
|
|
77
|
-
* @param schema - The schema to resolve the body for.
|
|
78
|
-
* @returns void
|
|
79
|
-
*/
|
|
80
|
-
function SchemaBodyResolver(metadata, schema) {
|
|
81
|
-
const body = metadata.args.find((arg) => arg.type === "body");
|
|
82
|
-
if (!body || !body.validationSchema) return;
|
|
83
|
-
schema.request = defu(schema?.request ?? {}, { body: { content: { "application/json": { schema: body.validationSchema } } } });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/Resolvers/SchemaQueryParamsResolver.ts
|
|
88
|
-
/**
|
|
89
|
-
* Resolves the query params schema for a given method.
|
|
90
|
-
* @param metadata - The metadata of the method.
|
|
91
|
-
* @param schema - The schema to resolve the query params for.
|
|
92
|
-
* @returns void
|
|
93
|
-
*/
|
|
94
|
-
function SchemaQueryParamsResolver(metadata, schema) {
|
|
95
|
-
const query = metadata.args.find((arg) => arg.type === "query-params");
|
|
96
|
-
if (!query || !query.validationSchema) return;
|
|
97
|
-
schema.request = defu(schema?.request ?? {}, { query: query.validationSchema });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
102
|
-
var require_decorate = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js": ((exports, module) => {
|
|
101
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.82.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
102
|
+
var require_decorate = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.82.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js": ((exports, module) => {
|
|
103
103
|
function __decorate(decorators, target, key, desc) {
|
|
104
104
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
105
105
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -172,25 +172,25 @@ SchemaController = (0, import_decorate.default)([Controller("/_schema")], Schema
|
|
|
172
172
|
//#region src/Plugins/SchemaPlugin.ts
|
|
173
173
|
/**
|
|
174
174
|
* Schema Plugin for Vercube framework
|
|
175
|
-
*
|
|
175
|
+
*
|
|
176
176
|
* Provides OpenAPI/Swagger schema generation and validation capabilities:
|
|
177
177
|
* - Automatic OpenAPI schema generation from Zod schemas
|
|
178
178
|
* - Route-level schema validation via @Schema decorator
|
|
179
179
|
* - Runtime schema access via /_schema endpoint
|
|
180
180
|
* - Seamless integration with request validation (@Body, @Query, etc)
|
|
181
|
-
*
|
|
181
|
+
*
|
|
182
182
|
* @example
|
|
183
183
|
* ```ts
|
|
184
184
|
* import { createApp } from '@vercube/core';
|
|
185
185
|
* import { SchemaPlugin } from '@vercube/schema';
|
|
186
|
-
*
|
|
186
|
+
*
|
|
187
187
|
* const app = createApp({
|
|
188
188
|
* setup: async (app) => {
|
|
189
189
|
* app.addPlugin(SchemaPlugin);
|
|
190
190
|
* }
|
|
191
191
|
* });
|
|
192
192
|
* ```
|
|
193
|
-
*
|
|
193
|
+
*
|
|
194
194
|
* @see {@link https://vercube.dev} for full documentation
|
|
195
195
|
*/
|
|
196
196
|
var SchemaPlugin = class extends BasePlugin {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Schema (swagger) module for Vercube framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"@asteasolutions/zod-to-openapi": "8.1.0",
|
|
31
31
|
"@standard-schema/spec": "1.0.0",
|
|
32
32
|
"defu": "6.1.4",
|
|
33
|
-
"zod": "4.
|
|
34
|
-
"@vercube/core": "0.0.
|
|
35
|
-
"@vercube/di": "0.0.
|
|
33
|
+
"zod": "4.1.3",
|
|
34
|
+
"@vercube/core": "0.0.23",
|
|
35
|
+
"@vercube/di": "0.0.23"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|