@veloxts/router 0.7.6 → 0.7.7
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/CHANGELOG.md +9 -0
- package/GUIDE.md +2 -27
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/openapi/index.d.ts +3 -4
- package/dist/openapi/index.js +3 -4
- package/dist/openapi/plugin.d.ts +3 -47
- package/dist/openapi/plugin.js +3 -51
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @veloxts/router
|
|
2
2
|
|
|
3
|
+
## 0.7.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- refactor(router): rename swaggerUIPlugin → swaggerPlugin, remove redundant exports
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @veloxts/core@0.7.7
|
|
10
|
+
- @veloxts/validation@0.7.7
|
|
11
|
+
|
|
3
12
|
## 0.7.6
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/GUIDE.md
CHANGED
|
@@ -198,9 +198,9 @@ fs.writeFileSync('openapi.json', JSON.stringify(spec, null, 2));
|
|
|
198
198
|
Serve interactive API documentation with Swagger UI:
|
|
199
199
|
|
|
200
200
|
```typescript
|
|
201
|
-
import {
|
|
201
|
+
import { swaggerPlugin } from '@veloxts/router';
|
|
202
202
|
|
|
203
|
-
app.server.register(
|
|
203
|
+
app.server.register(swaggerPlugin, {
|
|
204
204
|
routePrefix: '/docs',
|
|
205
205
|
collections: [userProcedures, postProcedures],
|
|
206
206
|
openapi: {
|
|
@@ -215,31 +215,6 @@ app.server.register(swaggerUIPlugin, {
|
|
|
215
215
|
// - /docs/openapi.json - Raw OpenAPI spec
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
### Factory Functions
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
import { createSwaggerUI, getOpenApiSpec, registerDocs } from '@veloxts/router';
|
|
222
|
-
|
|
223
|
-
// Create pre-configured plugin
|
|
224
|
-
const docs = createSwaggerUI({
|
|
225
|
-
collections: [userProcedures],
|
|
226
|
-
openapi: { info: { title: 'My API', version: '1.0.0' } },
|
|
227
|
-
});
|
|
228
|
-
app.server.register(docs);
|
|
229
|
-
|
|
230
|
-
// Get spec without registering routes
|
|
231
|
-
const spec = getOpenApiSpec({
|
|
232
|
-
collections: [userProcedures],
|
|
233
|
-
openapi: { info: { title: 'My API', version: '1.0.0' } },
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// Register docs with one call
|
|
237
|
-
await registerDocs(app.server, {
|
|
238
|
-
collections: [userProcedures],
|
|
239
|
-
openapi: { info: { title: 'My API', version: '1.0.0' } },
|
|
240
|
-
});
|
|
241
|
-
```
|
|
242
|
-
|
|
243
218
|
### CLI Commands
|
|
244
219
|
|
|
245
220
|
Generate and serve OpenAPI specs from the command line:
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export { serve } from './expose.js';
|
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
68
|
* ```typescript
|
|
69
|
-
* import { generateOpenApiSpec,
|
|
69
|
+
* import { generateOpenApiSpec, swaggerPlugin } from '@veloxts/router';
|
|
70
70
|
*
|
|
71
71
|
* // Generate spec programmatically
|
|
72
72
|
* const spec = generateOpenApiSpec([userProcedures], {
|
|
@@ -74,7 +74,7 @@ export { serve } from './expose.js';
|
|
|
74
74
|
* });
|
|
75
75
|
*
|
|
76
76
|
* // Or serve Swagger UI
|
|
77
|
-
* app.register(
|
|
77
|
+
* app.register(swaggerPlugin, {
|
|
78
78
|
* routePrefix: '/docs',
|
|
79
79
|
* collections: [userProcedures],
|
|
80
80
|
* openapi: { info: { title: 'My API', version: '1.0.0' } },
|
|
@@ -82,7 +82,7 @@ export { serve } from './expose.js';
|
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
export type { BuildParametersOptions, BuildParametersResult, GuardMappingOptions, JSONSchema, OpenAPIComponents, OpenAPIContact, OpenAPIEncoding, OpenAPIExample, OpenAPIExternalDocs, OpenAPIGeneratorOptions, OpenAPIHeader, OpenAPIHttpMethod, OpenAPIInfo, OpenAPILicense, OpenAPILink, OpenAPIMediaType, OpenAPIOAuthFlow, OpenAPIOAuthFlows, OpenAPIOperation, OpenAPIParameter, OpenAPIPathItem, OpenAPIRequestBody, OpenAPIResponse, OpenAPISecurityRequirement, OpenAPISecurityScheme, OpenAPIServer, OpenAPISpec, OpenAPITag, ParameterIn, QueryParamExtractionOptions, RouteInfo, SchemaConversionOptions, SecuritySchemeType, SwaggerUIConfig, SwaggerUIHtmlOptions, SwaggerUIPluginOptions, } from './openapi/index.js';
|
|
85
|
-
export { buildParameters, convertFromOpenAPIPath, convertToOpenAPIPath, createSecurityRequirement, createStringSchema,
|
|
85
|
+
export { buildParameters, convertFromOpenAPIPath, convertToOpenAPIPath, createSecurityRequirement, createStringSchema, DEFAULT_GUARD_MAPPINGS, DEFAULT_SECURITY_SCHEMES, DEFAULT_UI_CONFIG, escapeHtml, extractGuardScopes, extractPathParamNames, extractQueryParameters, extractResourceFromPath, extractSchemaProperties, extractUsedSecuritySchemes, filterUsedSecuritySchemes, generateOpenApiSpec, generateSwaggerUIHtml, getOpenApiRouteSummary, getOpenApiSpec, guardsRequireAuth, guardsToSecurity, hasPathParameters, joinPaths, mapGuardToSecurity, mergeSchemas, mergeSecuritySchemes, normalizePath, parsePathParameters, removeSchemaProperties, SWAGGER_UI_CDN, schemaHasProperties, swaggerPlugin, validateOpenApiSpec, zodSchemaToJsonSchema, } from './openapi/index.js';
|
|
86
86
|
export type { AccessLevel, AccessLevelConfig, ADMIN, AdminOutput, AdminTaggedContext, ANONYMOUS, AnonymousOutput, AnonymousTaggedContext, AnyResourceOutput, AUTHENTICATED, AuthenticatedOutput, AuthenticatedTaggedContext, BuilderField, ContextTag, CustomResourceSchemaWithViews, CustomSchemaBuilder, ExtractTag, FilterFieldsByLevel, HasTag, IfAdmin, IfAuthenticated, InferResourceData, InferResourceOutput, IsVisibleToTag, LevelToTag, OutputForLevel, OutputForTag, PUBLIC, PublicOutput, PublicTaggedContext, RelationField, ResourceField, ResourceSchema, ResourceSchemaWithViews, RuntimeField, TaggedContext, TagToLevel, VisibilityLevel, WithTag, } from './resource/index.js';
|
|
87
87
|
/**
|
|
88
88
|
* Resource API for context-dependent output types using phantom types.
|
package/dist/index.js
CHANGED
|
@@ -71,13 +71,13 @@ buildParameters, convertFromOpenAPIPath, convertToOpenAPIPath,
|
|
|
71
71
|
// Security mapper
|
|
72
72
|
createSecurityRequirement,
|
|
73
73
|
// Schema converter
|
|
74
|
-
createStringSchema,
|
|
75
|
-
// Plugin
|
|
76
|
-
createSwaggerUI, DEFAULT_GUARD_MAPPINGS, DEFAULT_SECURITY_SCHEMES, DEFAULT_UI_CONFIG, escapeHtml, extractGuardScopes, extractPathParamNames, extractQueryParameters, extractResourceFromPath, extractSchemaProperties, extractUsedSecuritySchemes, filterUsedSecuritySchemes,
|
|
74
|
+
createStringSchema, DEFAULT_GUARD_MAPPINGS, DEFAULT_SECURITY_SCHEMES, DEFAULT_UI_CONFIG, escapeHtml, extractGuardScopes, extractPathParamNames, extractQueryParameters, extractResourceFromPath, extractSchemaProperties, extractUsedSecuritySchemes, filterUsedSecuritySchemes,
|
|
77
75
|
// Generator
|
|
78
76
|
generateOpenApiSpec,
|
|
79
77
|
// HTML Generator
|
|
80
|
-
generateSwaggerUIHtml, getOpenApiRouteSummary, getOpenApiSpec, guardsRequireAuth, guardsToSecurity, hasPathParameters, joinPaths, mapGuardToSecurity, mergeSchemas, mergeSecuritySchemes, normalizePath, parsePathParameters,
|
|
78
|
+
generateSwaggerUIHtml, getOpenApiRouteSummary, getOpenApiSpec, guardsRequireAuth, guardsToSecurity, hasPathParameters, joinPaths, mapGuardToSecurity, mergeSchemas, mergeSecuritySchemes, normalizePath, parsePathParameters, removeSchemaProperties, SWAGGER_UI_CDN, schemaHasProperties,
|
|
79
|
+
// Plugin
|
|
80
|
+
swaggerPlugin, validateOpenApiSpec, zodSchemaToJsonSchema, } from './openapi/index.js';
|
|
81
81
|
/**
|
|
82
82
|
* Resource API for context-dependent output types using phantom types.
|
|
83
83
|
*
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* ```typescript
|
|
10
10
|
* import {
|
|
11
11
|
* generateOpenApiSpec,
|
|
12
|
-
*
|
|
13
|
-
* createSwaggerUI,
|
|
12
|
+
* swaggerPlugin,
|
|
14
13
|
* } from '@veloxts/router';
|
|
15
14
|
*
|
|
16
15
|
* // Generate spec programmatically
|
|
@@ -20,7 +19,7 @@
|
|
|
20
19
|
* });
|
|
21
20
|
*
|
|
22
21
|
* // Or register Swagger UI plugin
|
|
23
|
-
* app.register(
|
|
22
|
+
* app.register(swaggerPlugin, {
|
|
24
23
|
* routePrefix: '/docs',
|
|
25
24
|
* collections: [userProcedures],
|
|
26
25
|
* openapi: {
|
|
@@ -30,7 +29,7 @@
|
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
31
|
export { generateOpenApiSpec, getOpenApiRouteSummary, validateOpenApiSpec, } from './generator.js';
|
|
33
|
-
export {
|
|
32
|
+
export { getOpenApiSpec, swaggerPlugin, } from './plugin.js';
|
|
34
33
|
export { DEFAULT_UI_CONFIG, escapeHtml, generateSwaggerUIHtml, SWAGGER_UI_CDN, type SwaggerUIHtmlOptions, } from './html-generator.js';
|
|
35
34
|
export { createStringSchema, extractSchemaProperties, mergeSchemas, removeSchemaProperties, type SchemaConversionOptions, schemaHasProperties, zodSchemaToJsonSchema, } from './schema-converter.js';
|
|
36
35
|
export { type BuildParametersOptions, type BuildParametersResult, buildParameters, convertFromOpenAPIPath, convertToOpenAPIPath, extractPathParamNames, extractQueryParameters, extractResourceFromPath, hasPathParameters, joinPaths, normalizePath, parsePathParameters, type QueryParamExtractionOptions, } from './path-extractor.js';
|
package/dist/openapi/index.js
CHANGED
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* ```typescript
|
|
10
10
|
* import {
|
|
11
11
|
* generateOpenApiSpec,
|
|
12
|
-
*
|
|
13
|
-
* createSwaggerUI,
|
|
12
|
+
* swaggerPlugin,
|
|
14
13
|
* } from '@veloxts/router';
|
|
15
14
|
*
|
|
16
15
|
* // Generate spec programmatically
|
|
@@ -20,7 +19,7 @@
|
|
|
20
19
|
* });
|
|
21
20
|
*
|
|
22
21
|
* // Or register Swagger UI plugin
|
|
23
|
-
* app.register(
|
|
22
|
+
* app.register(swaggerPlugin, {
|
|
24
23
|
* routePrefix: '/docs',
|
|
25
24
|
* collections: [userProcedures],
|
|
26
25
|
* openapi: {
|
|
@@ -36,7 +35,7 @@ export { generateOpenApiSpec, getOpenApiRouteSummary, validateOpenApiSpec, } fro
|
|
|
36
35
|
// ============================================================================
|
|
37
36
|
// Plugin
|
|
38
37
|
// ============================================================================
|
|
39
|
-
export {
|
|
38
|
+
export { getOpenApiSpec, swaggerPlugin, } from './plugin.js';
|
|
40
39
|
// ============================================================================
|
|
41
40
|
// HTML Generator
|
|
42
41
|
// ============================================================================
|
package/dist/openapi/plugin.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ import type { OpenAPISpec, SwaggerUIPluginOptions } from './types.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* import {
|
|
17
|
+
* import { swaggerPlugin } from '@veloxts/router';
|
|
18
18
|
*
|
|
19
|
-
* app.register(
|
|
19
|
+
* app.register(swaggerPlugin, {
|
|
20
20
|
* routePrefix: '/docs',
|
|
21
21
|
* collections: [userProcedures, postProcedures],
|
|
22
22
|
* openapi: {
|
|
@@ -30,51 +30,7 @@ import type { OpenAPISpec, SwaggerUIPluginOptions } from './types.js';
|
|
|
30
30
|
* });
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
export declare const
|
|
34
|
-
/**
|
|
35
|
-
* Creates a Swagger UI plugin with pre-configured options
|
|
36
|
-
*
|
|
37
|
-
* @param options - Plugin options
|
|
38
|
-
* @returns Configured plugin
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* import { createSwaggerUI } from '@veloxts/router';
|
|
43
|
-
*
|
|
44
|
-
* const docs = createSwaggerUI({
|
|
45
|
-
* collections: [userProcedures],
|
|
46
|
-
* openapi: {
|
|
47
|
-
* info: { title: 'My API', version: '1.0.0' },
|
|
48
|
-
* },
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* app.register(docs);
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export declare function createSwaggerUI(options: SwaggerUIPluginOptions): FastifyPluginAsync<SwaggerUIPluginOptions>;
|
|
55
|
-
/**
|
|
56
|
-
* Registers multiple procedure collections with Swagger UI
|
|
57
|
-
*
|
|
58
|
-
* Convenience function that sets up both REST routes and documentation.
|
|
59
|
-
*
|
|
60
|
-
* @param fastify - Fastify instance
|
|
61
|
-
* @param options - Documentation options
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* import { registerDocs } from '@veloxts/router';
|
|
66
|
-
*
|
|
67
|
-
* await registerDocs(app, {
|
|
68
|
-
* collections: [userProcedures, postProcedures],
|
|
69
|
-
* openapi: {
|
|
70
|
-
* info: { title: 'My API', version: '1.0.0' },
|
|
71
|
-
* },
|
|
72
|
-
* });
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare function registerDocs(fastify: {
|
|
76
|
-
register: (plugin: FastifyPluginAsync<SwaggerUIPluginOptions>, options: SwaggerUIPluginOptions) => Promise<void>;
|
|
77
|
-
}, options: SwaggerUIPluginOptions): Promise<void>;
|
|
33
|
+
export declare const swaggerPlugin: FastifyPluginAsync<SwaggerUIPluginOptions>;
|
|
78
34
|
/**
|
|
79
35
|
* Gets the generated OpenAPI specification without registering routes
|
|
80
36
|
*
|
package/dist/openapi/plugin.js
CHANGED
|
@@ -17,9 +17,9 @@ import { generateSwaggerUIHtml } from './html-generator.js';
|
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
|
20
|
-
* import {
|
|
20
|
+
* import { swaggerPlugin } from '@veloxts/router';
|
|
21
21
|
*
|
|
22
|
-
* app.register(
|
|
22
|
+
* app.register(swaggerPlugin, {
|
|
23
23
|
* routePrefix: '/docs',
|
|
24
24
|
* collections: [userProcedures, postProcedures],
|
|
25
25
|
* openapi: {
|
|
@@ -33,7 +33,7 @@ import { generateSwaggerUIHtml } from './html-generator.js';
|
|
|
33
33
|
* });
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export const
|
|
36
|
+
export const swaggerPlugin = async (fastify, options) => {
|
|
37
37
|
const { routePrefix = '/docs', specRoute = `${routePrefix}/openapi.json`, uiConfig = {}, openapi, collections, title = 'API Documentation', favicon, } = options;
|
|
38
38
|
// Generate the OpenAPI specification
|
|
39
39
|
let spec;
|
|
@@ -69,54 +69,6 @@ export const swaggerUIPlugin = async (fastify, options) => {
|
|
|
69
69
|
// ============================================================================
|
|
70
70
|
// Utility Functions
|
|
71
71
|
// ============================================================================
|
|
72
|
-
/**
|
|
73
|
-
* Creates a Swagger UI plugin with pre-configured options
|
|
74
|
-
*
|
|
75
|
-
* @param options - Plugin options
|
|
76
|
-
* @returns Configured plugin
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* import { createSwaggerUI } from '@veloxts/router';
|
|
81
|
-
*
|
|
82
|
-
* const docs = createSwaggerUI({
|
|
83
|
-
* collections: [userProcedures],
|
|
84
|
-
* openapi: {
|
|
85
|
-
* info: { title: 'My API', version: '1.0.0' },
|
|
86
|
-
* },
|
|
87
|
-
* });
|
|
88
|
-
*
|
|
89
|
-
* app.register(docs);
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export function createSwaggerUI(options) {
|
|
93
|
-
return async (fastify) => {
|
|
94
|
-
await swaggerUIPlugin(fastify, options);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Registers multiple procedure collections with Swagger UI
|
|
99
|
-
*
|
|
100
|
-
* Convenience function that sets up both REST routes and documentation.
|
|
101
|
-
*
|
|
102
|
-
* @param fastify - Fastify instance
|
|
103
|
-
* @param options - Documentation options
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* import { registerDocs } from '@veloxts/router';
|
|
108
|
-
*
|
|
109
|
-
* await registerDocs(app, {
|
|
110
|
-
* collections: [userProcedures, postProcedures],
|
|
111
|
-
* openapi: {
|
|
112
|
-
* info: { title: 'My API', version: '1.0.0' },
|
|
113
|
-
* },
|
|
114
|
-
* });
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
export async function registerDocs(fastify, options) {
|
|
118
|
-
await fastify.register(swaggerUIPlugin, options);
|
|
119
|
-
}
|
|
120
72
|
/**
|
|
121
73
|
* Gets the generated OpenAPI specification without registering routes
|
|
122
74
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/router",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Procedure definitions with tRPC and REST routing for VeloxTS framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@trpc/server": "11.10.0",
|
|
41
41
|
"fastify": "5.7.4",
|
|
42
|
-
"@veloxts/
|
|
43
|
-
"@veloxts/
|
|
42
|
+
"@veloxts/core": "0.7.7",
|
|
43
|
+
"@veloxts/validation": "0.7.7"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@vitest/coverage-v8": "4.0.18",
|