@vercube/schema 0.0.22 → 0.0.24
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 +41 -73
- 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,34 +1,35 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { z } from "zod";
|
|
3
1
|
import { OpenAPIRegistry, OpenApiGeneratorV3, extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
2
|
+
import { z } from "zod";
|
|
4
3
|
import { BaseDecorator, Inject, createDecorator } from "@vercube/di";
|
|
5
4
|
import defu from "defu";
|
|
6
5
|
import { BasePlugin, Controller, Get } from "@vercube/core";
|
|
7
6
|
|
|
8
|
-
//#region
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
//#region src/Resolvers/SchemaBodyResolver.ts
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the body schema for a given method.
|
|
10
|
+
* @param metadata - The metadata of the method.
|
|
11
|
+
* @param schema - The schema to resolve the body for.
|
|
12
|
+
* @returns void
|
|
13
|
+
*/
|
|
14
|
+
function SchemaBodyResolver(metadata, schema) {
|
|
15
|
+
const body = metadata.args.find((arg) => arg.type === "body");
|
|
16
|
+
if (!body || !body.validationSchema) return;
|
|
17
|
+
schema.request = defu(schema?.request ?? {}, { body: { content: { "application/json": { schema: body.validationSchema } } } });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/Resolvers/SchemaQueryParamsResolver.ts
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the query params schema for a given method.
|
|
24
|
+
* @param metadata - The metadata of the method.
|
|
25
|
+
* @param schema - The schema to resolve the query params for.
|
|
26
|
+
* @returns void
|
|
27
|
+
*/
|
|
28
|
+
function SchemaQueryParamsResolver(metadata, schema) {
|
|
29
|
+
const query = metadata.args.find((arg) => arg.type === "query-params");
|
|
30
|
+
if (!query || !query.validationSchema) return;
|
|
31
|
+
schema.request = defu(schema?.request ?? {}, { query: query.validationSchema });
|
|
32
|
+
}
|
|
32
33
|
|
|
33
34
|
//#endregion
|
|
34
35
|
//#region src/Services/SchemaRegistry.ts
|
|
@@ -70,48 +71,16 @@ var SchemaRegistry = class {
|
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
//#endregion
|
|
73
|
-
//#region
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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 });
|
|
74
|
+
//#region \0@oxc-project+runtime@0.90.0/helpers/decorate.js
|
|
75
|
+
function __decorate(decorators, target, key, desc) {
|
|
76
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
77
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
78
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
79
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
98
80
|
}
|
|
99
81
|
|
|
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) => {
|
|
103
|
-
function __decorate(decorators, target, key, desc) {
|
|
104
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
105
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
106
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
107
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
108
|
-
}
|
|
109
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
110
|
-
}) });
|
|
111
|
-
|
|
112
82
|
//#endregion
|
|
113
83
|
//#region src/Decorators/Schema.ts
|
|
114
|
-
var import_decorate$1 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
115
84
|
/**
|
|
116
85
|
* A decorator class for handling OpenAPI schema registration for routes.
|
|
117
86
|
*
|
|
@@ -136,7 +105,7 @@ var SchemaDecorator = class extends BaseDecorator {
|
|
|
136
105
|
this.gSchemaRegistry.register(_schema);
|
|
137
106
|
}
|
|
138
107
|
};
|
|
139
|
-
(
|
|
108
|
+
__decorate([Inject(SchemaRegistry)], SchemaDecorator.prototype, "gSchemaRegistry", void 0);
|
|
140
109
|
/**
|
|
141
110
|
* A decorator function for registering OpenAPI schema metadata for a route.
|
|
142
111
|
*
|
|
@@ -152,7 +121,6 @@ function Schema(params) {
|
|
|
152
121
|
|
|
153
122
|
//#endregion
|
|
154
123
|
//#region src/Controllers/SchameController.ts
|
|
155
|
-
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
156
124
|
let SchemaController = class SchemaController$1 {
|
|
157
125
|
gSchemaRegistry;
|
|
158
126
|
/**
|
|
@@ -164,33 +132,33 @@ let SchemaController = class SchemaController$1 {
|
|
|
164
132
|
return this.gSchemaRegistry.generateSchema();
|
|
165
133
|
}
|
|
166
134
|
};
|
|
167
|
-
(
|
|
168
|
-
(
|
|
169
|
-
SchemaController = (
|
|
135
|
+
__decorate([Inject(SchemaRegistry)], SchemaController.prototype, "gSchemaRegistry", void 0);
|
|
136
|
+
__decorate([Get("/")], SchemaController.prototype, "get", null);
|
|
137
|
+
SchemaController = __decorate([Controller("/_schema")], SchemaController);
|
|
170
138
|
|
|
171
139
|
//#endregion
|
|
172
140
|
//#region src/Plugins/SchemaPlugin.ts
|
|
173
141
|
/**
|
|
174
142
|
* Schema Plugin for Vercube framework
|
|
175
|
-
*
|
|
143
|
+
*
|
|
176
144
|
* Provides OpenAPI/Swagger schema generation and validation capabilities:
|
|
177
145
|
* - Automatic OpenAPI schema generation from Zod schemas
|
|
178
146
|
* - Route-level schema validation via @Schema decorator
|
|
179
147
|
* - Runtime schema access via /_schema endpoint
|
|
180
148
|
* - Seamless integration with request validation (@Body, @Query, etc)
|
|
181
|
-
*
|
|
149
|
+
*
|
|
182
150
|
* @example
|
|
183
151
|
* ```ts
|
|
184
152
|
* import { createApp } from '@vercube/core';
|
|
185
153
|
* import { SchemaPlugin } from '@vercube/schema';
|
|
186
|
-
*
|
|
154
|
+
*
|
|
187
155
|
* const app = createApp({
|
|
188
156
|
* setup: async (app) => {
|
|
189
157
|
* app.addPlugin(SchemaPlugin);
|
|
190
158
|
* }
|
|
191
159
|
* });
|
|
192
160
|
* ```
|
|
193
|
-
*
|
|
161
|
+
*
|
|
194
162
|
* @see {@link https://vercube.dev} for full documentation
|
|
195
163
|
*/
|
|
196
164
|
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.24",
|
|
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.11",
|
|
34
|
+
"@vercube/core": "0.0.24",
|
|
35
|
+
"@vercube/di": "0.0.24"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|