@vercube/schema 0.0.48 → 1.0.0-beta.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
@@ -12,7 +12,7 @@
12
12
  ![GitHub License](<https://img.shields.io/github/license/vercube/vercube?style=for-the-badge&logo=gitbook&logoColor=rgba(255%2C%20255%2C%20255%2C%200.6)&labelColor=%23000&color=%232f2f2f>)
13
13
  ![Codecov](<https://img.shields.io/codecov/c/github/vercube/vercube?style=for-the-badge&logo=vitest&logoColor=rgba(255%2C%20255%2C%20255%2C%200.6)&labelColor=%23000&color=%232f2f2f>)
14
14
 
15
- **Auto-generate OpenAPI specs from your Zod schemas. Add `@Schema` to your routes, get Swagger docs at `/_schema`.**
15
+ **Auto-generate OpenAPI specs from your Zod schemas. Add `@Schema` to your routes, get OpenAPI at `/_schema` and Scalar docs at `/_schema/docs`.**
16
16
 
17
17
  [Website](https://vercube.dev) • [Documentation](https://vercube.dev/docs/getting-started)
18
18
 
@@ -24,6 +24,7 @@
24
24
  - **Decorator API** - `@Schema` on routes to add OpenAPI metadata
25
25
  - **Auto-resolution** - picks up `@Body`, `@Param`, `@QueryParams` automatically
26
26
  - **Runtime endpoint** - OpenAPI JSON available at `/_schema`
27
+ - **Scalar UI** - Interactive API docs at `/_schema/docs` ([Scalar](https://github.com/scalar/scalar))
27
28
 
28
29
  ## 📦 Installation
29
30
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RouteConfig } from "@asteasolutions/zod-to-openapi";
2
2
  import { z } from "zod";
3
3
  import { App, BasePlugin } from "@vercube/core";
4
+ import { HtmlRenderingConfiguration } from "@scalar/client-side-rendering";
4
5
 
5
6
  //#region src/Decorators/Schema.d.ts
6
7
  interface SchemaDecoratorOptions extends Omit<RouteConfig, 'method' | 'path'> {}
@@ -15,6 +16,35 @@ interface SchemaDecoratorOptions extends Omit<RouteConfig, 'method' | 'path'> {}
15
16
  */
16
17
  declare function Schema(params: SchemaDecoratorOptions): Function;
17
18
  //#endregion
19
+ //#region src/Types/SchemaPluginOptions.d.ts
20
+ /**
21
+ * Scalar API Reference options (see https://github.com/scalar/scalar).
22
+ */
23
+ interface SchemaScalarOptions {
24
+ /**
25
+ * OpenAPI document URL passed to Scalar.
26
+ * @default '/_schema/'
27
+ */
28
+ openApiUrl?: string;
29
+ /** HTML page title. @default 'API Reference' */
30
+ pageTitle?: string;
31
+ /** CDN URL for the Scalar bundle. Uses Scalar default when omitted. */
32
+ cdn?: string;
33
+ /** Additional Scalar configuration (theme, layout, etc.). */
34
+ config?: Partial<HtmlRenderingConfiguration>;
35
+ }
36
+ /**
37
+ * Options for {@link SchemaPlugin}.
38
+ */
39
+ interface SchemaPluginOptions {
40
+ /**
41
+ * Scalar API Reference UI served at `/_schema/docs`.
42
+ * Pass `false` to disable.
43
+ * @default enabled with OpenAPI at `/_schema/`
44
+ */
45
+ scalar?: false | SchemaScalarOptions;
46
+ }
47
+ //#endregion
18
48
  //#region src/Plugins/SchemaPlugin.d.ts
19
49
  /**
20
50
  * Schema Plugin for Vercube framework
@@ -23,6 +53,7 @@ declare function Schema(params: SchemaDecoratorOptions): Function;
23
53
  * - Automatic OpenAPI schema generation from Zod schemas
24
54
  * - Route-level schema validation via @Schema decorator
25
55
  * - Runtime schema access via /_schema endpoint
56
+ * - Scalar API Reference UI at /_schema/docs (https://github.com/scalar/scalar)
26
57
  * - Seamless integration with request validation (@Body, @Query, etc)
27
58
  *
28
59
  * @example
@@ -39,7 +70,7 @@ declare function Schema(params: SchemaDecoratorOptions): Function;
39
70
  *
40
71
  * @see {@link https://vercube.dev} for full documentation
41
72
  */
42
- declare class SchemaPlugin<T = unknown> extends BasePlugin<T> {
73
+ declare class SchemaPlugin extends BasePlugin<SchemaPluginOptions> {
43
74
  /**
44
75
  * The name of the plugin.
45
76
  * @override
@@ -51,7 +82,7 @@ declare class SchemaPlugin<T = unknown> extends BasePlugin<T> {
51
82
  * @returns {void | Promise<void>}
52
83
  * @override
53
84
  */
54
- use(app: App, options: T): void | Promise<void>;
85
+ use(app: App, options?: SchemaPluginOptions): void | Promise<void>;
55
86
  }
56
87
  //#endregion
57
- export { Schema, SchemaPlugin, z };
88
+ export { Schema, SchemaPlugin, type SchemaPluginOptions, type SchemaScalarOptions, z };
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import { OpenAPIRegistry, OpenApiGeneratorV3, extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
2
2
  import { z } from "zod";
3
- import { BaseDecorator, Inject, createDecorator } from "@vercube/di";
4
- import defu from "defu";
3
+ import { BaseDecorator, Identity, Inject, createDecorator } from "@vercube/di";
4
+ import defu$1, { defu } from "defu";
5
5
  import { BasePlugin, Controller, Get } from "@vercube/core";
6
+ import { renderApiReference } from "@scalar/client-side-rendering";
6
7
  //#region src/Resolvers/SchemaBodyResolver.ts
7
8
  /**
8
9
  * Resolves the body schema for a given method.
@@ -13,7 +14,7 @@ import { BasePlugin, Controller, Get } from "@vercube/core";
13
14
  function SchemaBodyResolver(metadata, schema) {
14
15
  const body = metadata.args.find((arg) => arg.type === "body");
15
16
  if (!body || !body.validationSchema) return;
16
- schema.request = defu(schema?.request ?? {}, { body: { content: { "application/json": { schema: body.validationSchema } } } });
17
+ schema.request = defu$1(schema?.request ?? {}, { body: { content: { "application/json": { schema: body.validationSchema } } } });
17
18
  }
18
19
  //#endregion
19
20
  //#region src/Resolvers/SchemaQueryParamsResolver.ts
@@ -26,7 +27,7 @@ function SchemaBodyResolver(metadata, schema) {
26
27
  function SchemaQueryParamsResolver(metadata, schema) {
27
28
  const query = metadata.args.find((arg) => arg.type === "query-params");
28
29
  if (!query || !query.validationSchema) return;
29
- schema.request = defu(schema?.request ?? {}, { query: query.validationSchema });
30
+ schema.request = defu$1(schema?.request ?? {}, { query: query.validationSchema });
30
31
  }
31
32
  //#endregion
32
33
  //#region src/Services/SchemaRegistry.ts
@@ -67,7 +68,7 @@ var SchemaRegistry = class {
67
68
  }
68
69
  };
69
70
  //#endregion
70
- //#region \0@oxc-project+runtime@0.130.0/helpers/decorate.js
71
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorate.js
71
72
  function __decorate(decorators, target, key, desc) {
72
73
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
73
74
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -114,9 +115,19 @@ function Schema(params) {
114
115
  return createDecorator(SchemaDecorator, params);
115
116
  }
116
117
  //#endregion
118
+ //#region src/Constants/SchemaDefaults.ts
119
+ const DEFAULT_SCHEMA_PLUGIN_OPTIONS = { scalar: {
120
+ openApiUrl: "/_schema/",
121
+ pageTitle: "API Reference"
122
+ } };
123
+ //#endregion
124
+ //#region src/Symbols/SchemaSymbols.ts
125
+ const $SchemaPluginOptions = Identity("SchemaPluginOptions");
126
+ //#endregion
117
127
  //#region src/Controllers/SchameController.ts
118
128
  let SchemaController = class SchemaController {
119
129
  gSchemaRegistry;
130
+ gSchemaPluginOptions;
120
131
  /**
121
132
  * Handles GET requests to retrieve the generated OpenAPI schema.
122
133
  *
@@ -125,9 +136,35 @@ let SchemaController = class SchemaController {
125
136
  async get() {
126
137
  return this.gSchemaRegistry.generateSchema();
127
138
  }
139
+ /**
140
+ * Serves the Scalar API Reference UI for the generated OpenAPI schema.
141
+ *
142
+ * @see https://github.com/scalar/scalar
143
+ */
144
+ getDocs() {
145
+ if (this.gSchemaPluginOptions.scalar === false) return new Response(null, { status: 404 });
146
+ const scalar = {
147
+ ...DEFAULT_SCHEMA_PLUGIN_OPTIONS.scalar,
148
+ ...typeof this.gSchemaPluginOptions.scalar === "object" ? this.gSchemaPluginOptions.scalar : {}
149
+ };
150
+ const html = renderApiReference({
151
+ config: {
152
+ url: scalar.openApiUrl ?? "/_schema/",
153
+ ...scalar.config
154
+ },
155
+ pageTitle: scalar.pageTitle,
156
+ cdn: scalar.cdn
157
+ });
158
+ return new Response(html, {
159
+ status: 200,
160
+ headers: { "Content-Type": "text/html; charset=utf-8" }
161
+ });
162
+ }
128
163
  };
129
164
  __decorate([Inject(SchemaRegistry)], SchemaController.prototype, "gSchemaRegistry", void 0);
165
+ __decorate([Inject($SchemaPluginOptions)], SchemaController.prototype, "gSchemaPluginOptions", void 0);
130
166
  __decorate([Get("/")], SchemaController.prototype, "get", null);
167
+ __decorate([Get("/docs")], SchemaController.prototype, "getDocs", null);
131
168
  SchemaController = __decorate([Controller("/_schema")], SchemaController);
132
169
  //#endregion
133
170
  //#region src/Plugins/SchemaPlugin.ts
@@ -138,6 +175,7 @@ SchemaController = __decorate([Controller("/_schema")], SchemaController);
138
175
  * - Automatic OpenAPI schema generation from Zod schemas
139
176
  * - Route-level schema validation via @Schema decorator
140
177
  * - Runtime schema access via /_schema endpoint
178
+ * - Scalar API Reference UI at /_schema/docs (https://github.com/scalar/scalar)
141
179
  * - Seamless integration with request validation (@Body, @Query, etc)
142
180
  *
143
181
  * @example
@@ -167,6 +205,8 @@ var SchemaPlugin = class extends BasePlugin {
167
205
  * @override
168
206
  */
169
207
  use(app, options) {
208
+ const mergedOptions = defu(options ?? {}, DEFAULT_SCHEMA_PLUGIN_OPTIONS);
209
+ app.container.bindInstance($SchemaPluginOptions, mergedOptions);
170
210
  app.container.bind(SchemaRegistry);
171
211
  app.container.bind(SchemaController);
172
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercube/schema",
3
- "version": "0.0.48",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Schema (swagger) module for Vercube framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,11 +28,12 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@asteasolutions/zod-to-openapi": "8.5.0",
31
+ "@scalar/client-side-rendering": "0.2.3",
31
32
  "@standard-schema/spec": "1.1.0",
32
33
  "defu": "6.1.7",
33
34
  "zod": "4.4.3",
34
- "@vercube/di": "0.0.48",
35
- "@vercube/core": "0.0.48"
35
+ "@vercube/core": "1.0.0-beta.2",
36
+ "@vercube/di": "1.0.0-beta.2"
36
37
  },
37
38
  "publishConfig": {
38
39
  "access": "public"