@questpie/openapi 3.0.19 → 3.0.21

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
@@ -14,8 +14,8 @@ Register `openApiModule` in your `modules.ts` file to add `/openapi.json` and `/
14
14
 
15
15
  ```ts
16
16
  // src/questpie/server/modules.ts
17
- import { adminModule } from "@questpie/admin/server";
18
- import { openApiModule } from "@questpie/openapi";
17
+ import { adminModule } from "@questpie/admin/modules/admin";
18
+ import { openApiModule } from "@questpie/openapi/modules/openapi";
19
19
 
20
20
  export default [adminModule, openApiModule] as const;
21
21
  ```
@@ -24,7 +24,7 @@ Configure the OpenAPI module via `config/openapi.ts`:
24
24
 
25
25
  ```ts
26
26
  // src/questpie/server/config/openapi.ts
27
- import { openApiConfig } from "@questpie/openapi";
27
+ import { openApiConfig } from "@questpie/openapi/server";
28
28
 
29
29
  export default openApiConfig({
30
30
  info: { title: "My API", version: "1.0.0" },
@@ -36,7 +36,7 @@ Your route handler stays clean — no wrapper needed:
36
36
 
37
37
  ```ts
38
38
  // routes/api/$.ts
39
- import { createFetchHandler } from "questpie";
39
+ import { createFetchHandler } from "questpie/http";
40
40
  import { app } from "#questpie";
41
41
 
42
42
  const handler = createFetchHandler(app, { basePath: "/api" });
@@ -66,7 +66,7 @@ Routes with an explicit `outputSchema` get full request/response documentation.
66
66
  Generate the spec without mounting routes:
67
67
 
68
68
  ```ts
69
- import { generateOpenApiSpec } from "@questpie/openapi";
69
+ import { generateOpenApiSpec } from "@questpie/openapi/server";
70
70
 
71
71
  const spec = generateOpenApiSpec(app, {
72
72
  basePath: "/api",
@@ -0,0 +1,2 @@
1
+ import { i as openApiModule } from "../server-C8504hNI.mjs";
2
+ export { openApiModule };
@@ -0,0 +1,3 @@
1
+ import { i as openApiModule } from "../server-DsUIkt4E.mjs";
2
+
3
+ export { openApiModule };
@@ -0,0 +1,30 @@
1
+ //#region src/plugin.ts
2
+ function openApiPlugin() {
3
+ return {
4
+ name: "questpie-openapi",
5
+ targets: { server: {
6
+ root: ".",
7
+ outputFile: "index.ts",
8
+ discover: { openapi: {
9
+ pattern: "config/openapi.ts",
10
+ configKey: "openapi"
11
+ } },
12
+ registries: { singletonFactories: { openapi: {
13
+ configType: "OpenApiModuleConfig",
14
+ imports: [{
15
+ name: "OpenApiModuleConfig",
16
+ from: "@questpie/openapi"
17
+ }]
18
+ } } },
19
+ transform: (ctx) => {
20
+ const routes = ctx.categories.get("routes");
21
+ if (!routes?.size) return;
22
+ const union = [...routes.keys()].map((k) => `"${k}"`).join(" | ");
23
+ ctx.addTypeDeclaration(`export type AppRouteKeys = ${union};`);
24
+ }
25
+ } }
26
+ };
27
+ }
28
+
29
+ //#endregion
30
+ export { openApiPlugin as t };
package/dist/plugin.mjs CHANGED
@@ -1,30 +1,3 @@
1
- //#region src/plugin.ts
2
- function openApiPlugin() {
3
- return {
4
- name: "questpie-openapi",
5
- targets: { server: {
6
- root: ".",
7
- outputFile: "index.ts",
8
- discover: { openapi: {
9
- pattern: "config/openapi.ts",
10
- configKey: "openapi"
11
- } },
12
- registries: { singletonFactories: { openapi: {
13
- configType: "OpenApiModuleConfig",
14
- imports: [{
15
- name: "OpenApiModuleConfig",
16
- from: "@questpie/openapi"
17
- }]
18
- } } },
19
- transform: (ctx) => {
20
- const routes = ctx.categories.get("routes");
21
- if (!routes?.size) return;
22
- const union = [...routes.keys()].map((k) => `"${k}"`).join(" | ");
23
- ctx.addTypeDeclaration(`export type AppRouteKeys = ${union};`);
24
- }
25
- } }
26
- };
27
- }
1
+ import { t as openApiPlugin } from "./plugin-CbmRC5nO.mjs";
28
2
 
29
- //#endregion
30
3
  export { openApiPlugin };
@@ -0,0 +1,186 @@
1
+ import * as questpie0 from "questpie";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * Configuration for OpenAPI spec generation.
6
+ */
7
+ interface OpenApiConfig {
8
+ /** OpenAPI info object */
9
+ info?: {
10
+ title?: string;
11
+ version?: string;
12
+ description?: string;
13
+ };
14
+ /** Server definitions */
15
+ servers?: Array<{
16
+ url: string;
17
+ description?: string;
18
+ }>;
19
+ /** Base path for routes (must match your adapter basePath) */
20
+ basePath?: string;
21
+ /** Exclude specific collections or globals from the spec */
22
+ exclude?: {
23
+ collections?: string[];
24
+ globals?: string[];
25
+ };
26
+ /** Include auth endpoints in the spec */
27
+ auth?: boolean;
28
+ /** Include search endpoints in the spec */
29
+ search?: boolean;
30
+ }
31
+ /**
32
+ * Scalar UI configuration options.
33
+ */
34
+ interface ScalarConfig {
35
+ /** Theme for Scalar UI */
36
+ theme?: string;
37
+ /** Page title override */
38
+ title?: string;
39
+ /** Custom CSS */
40
+ customCss?: string;
41
+ /** Hide the "Download OpenAPI Spec" button */
42
+ hideDownloadButton?: boolean;
43
+ /** Default HTTP client for code samples */
44
+ defaultHttpClient?: {
45
+ targetKey: string;
46
+ clientKey: string;
47
+ };
48
+ }
49
+ /**
50
+ * Configuration for the OpenAPI module.
51
+ * Export from `config/openapi.ts` via `openApiConfig()`.
52
+ */
53
+ interface OpenApiModuleConfig extends OpenApiConfig {
54
+ /** Scalar UI options */
55
+ scalar?: ScalarConfig;
56
+ /** Path for the JSON spec route (default: "openapi.json") */
57
+ specPath?: string;
58
+ /** Path for the Scalar UI docs route (default: "docs") */
59
+ docsPath?: string;
60
+ }
61
+ /**
62
+ * OpenAPI 3.1 spec (simplified type — full spec is a plain object).
63
+ */
64
+ type OpenApiSpec = {
65
+ openapi: "3.1.0";
66
+ info: {
67
+ title: string;
68
+ version: string;
69
+ description?: string;
70
+ };
71
+ servers?: Array<{
72
+ url: string;
73
+ description?: string;
74
+ }>;
75
+ paths: Record<string, Record<string, PathOperation>>;
76
+ components: {
77
+ schemas: Record<string, unknown>;
78
+ securitySchemes?: Record<string, unknown>;
79
+ };
80
+ tags?: Array<{
81
+ name: string;
82
+ description?: string;
83
+ }>;
84
+ security?: Array<Record<string, string[]>>;
85
+ };
86
+ interface PathOperation {
87
+ operationId?: string;
88
+ summary?: string;
89
+ description?: string;
90
+ tags?: string[];
91
+ parameters?: unknown[];
92
+ requestBody?: unknown;
93
+ responses: Record<string, unknown>;
94
+ security?: Array<Record<string, string[]>>;
95
+ }
96
+ //#endregion
97
+ //#region src/server.d.ts
98
+
99
+ /**
100
+ * Identity factory for `config/openapi.ts` — provides type inference.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * // config/openapi.ts
105
+ * import { openApiConfig } from "@questpie/openapi/server";
106
+ *
107
+ * export default openApiConfig({
108
+ * info: { title: "My API", version: "1.0.0" },
109
+ * scalar: { theme: "purple" },
110
+ * });
111
+ * ```
112
+ */
113
+ declare function openApiConfig(config: OpenApiModuleConfig): OpenApiModuleConfig;
114
+ /**
115
+ * Generate a complete OpenAPI 3.1 spec from a QUESTPIE app instance.
116
+ * Routes are read from `app.config.routes` automatically.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import { generateOpenApiSpec } from "@questpie/openapi/server";
121
+ *
122
+ * const spec = generateOpenApiSpec(app, {
123
+ * info: { title: "My API", version: "1.0.0" },
124
+ * });
125
+ * ```
126
+ */
127
+ declare function generateOpenApiSpec(app: unknown, config?: OpenApiConfig): OpenApiSpec;
128
+ /**
129
+ * Create a route that serves the OpenAPI 3.1 JSON spec.
130
+ * Place in your `routes/` directory for automatic discovery.
131
+ *
132
+ * Spec is lazy-generated on first request and cached with ETag.
133
+ * Config is read from `config/openapi.ts` at request time, or from
134
+ * explicit parameter if provided.
135
+ *
136
+ * @example
137
+ * ```ts title="routes/openapi-spec.ts"
138
+ * import { openApiRoute } from "@questpie/openapi/server";
139
+ *
140
+ * export default openApiRoute();
141
+ * ```
142
+ */
143
+ declare function openApiRoute(config?: OpenApiConfig): questpie0.RawRouteDefinition<questpie0.JsonRouteParams>;
144
+ /**
145
+ * Create a route that serves the Scalar interactive API docs.
146
+ * Place in your `routes/` directory for automatic discovery.
147
+ *
148
+ * @example
149
+ * ```ts title="routes/docs.ts"
150
+ * import { docsRoute } from "@questpie/openapi/server";
151
+ *
152
+ * export default docsRoute();
153
+ * ```
154
+ */
155
+ declare function docsRoute(config?: OpenApiConfig & {
156
+ scalar?: ScalarConfig;
157
+ }): questpie0.RawRouteDefinition<questpie0.JsonRouteParams>;
158
+ /**
159
+ * OpenAPI module — registers spec + docs routes.
160
+ *
161
+ * Routes are served as:
162
+ * - `GET /api/openapi.json` — OpenAPI 3.1 JSON spec
163
+ * - `GET /api/docs` — Scalar interactive API reference
164
+ *
165
+ * Configure via `config/openapi.ts`:
166
+ * ```ts
167
+ * import { openApiConfig } from "@questpie/openapi/server";
168
+ * export default openApiConfig({ info: { title: "My API", version: "1.0.0" } });
169
+ * ```
170
+ *
171
+ * @example Static (reads config from config/openapi.ts):
172
+ * ```ts title="questpie/server/modules.ts"
173
+ * import { openApiModule } from "@questpie/openapi/server";
174
+ * export default [openApiModule] as const;
175
+ * ```
176
+ */
177
+ declare const openApiModule: {
178
+ name: "questpie-openapi";
179
+ plugin: questpie0.CodegenPlugin;
180
+ routes: {
181
+ "openapi.json": questpie0.RawRouteDefinition<questpie0.JsonRouteParams>;
182
+ docs: questpie0.RawRouteDefinition<questpie0.JsonRouteParams>;
183
+ };
184
+ };
185
+ //#endregion
186
+ export { openApiRoute as a, OpenApiSpec as c, openApiModule as i, ScalarConfig as l, generateOpenApiSpec as n, OpenApiConfig as o, openApiConfig as r, OpenApiModuleConfig as s, docsRoute as t };