@questpie/openapi 3.0.24 → 3.0.26
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/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/modules/openapi.d.mts +1 -1
- package/dist/modules/openapi.mjs +1 -1
- package/dist/{server-BBseHEQj.d.mts → server-3xWD7ZeS.d.mts} +5 -4
- package/dist/{server-DD4ci13b.mjs → server-IiX4cD55.mjs} +92 -43
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as openApiRoute, c as OpenApiSpec, i as openApiModule, l as ScalarConfig, n as generateOpenApiSpec, o as OpenApiConfig, r as openApiConfig, s as OpenApiModuleConfig, t as docsRoute } from "./server-
|
|
1
|
+
import { a as openApiRoute, c as OpenApiSpec, i as openApiModule, l as ScalarConfig, n as generateOpenApiSpec, o as OpenApiConfig, r as openApiConfig, s as OpenApiModuleConfig, t as docsRoute } from "./server-3xWD7ZeS.mjs";
|
|
2
2
|
export { OpenApiConfig, OpenApiModuleConfig, OpenApiSpec, ScalarConfig, openApiModule as default, openApiModule, docsRoute, generateOpenApiSpec, openApiConfig, openApiRoute };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as openApiRoute, i as openApiModule, n as generateOpenApiSpec, o as server_default, r as openApiConfig, t as docsRoute } from "./server-
|
|
1
|
+
import { a as openApiRoute, i as openApiModule, n as generateOpenApiSpec, o as server_default, r as openApiConfig, t as docsRoute } from "./server-IiX4cD55.mjs";
|
|
2
2
|
|
|
3
3
|
export { server_default as default, docsRoute, generateOpenApiSpec, openApiConfig, openApiModule, openApiRoute };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as openApiModule } from "../server-
|
|
1
|
+
import { i as openApiModule } from "../server-3xWD7ZeS.mjs";
|
|
2
2
|
export { openApiModule };
|
package/dist/modules/openapi.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as questpie0 from "questpie";
|
|
2
|
+
import { RawRouteDefinition } from "questpie";
|
|
2
3
|
|
|
3
4
|
//#region src/types.d.ts
|
|
4
5
|
/**
|
|
@@ -140,7 +141,7 @@ declare function generateOpenApiSpec(app: unknown, config?: OpenApiConfig): Open
|
|
|
140
141
|
* export default openApiRoute();
|
|
141
142
|
* ```
|
|
142
143
|
*/
|
|
143
|
-
declare function openApiRoute(config?: OpenApiConfig):
|
|
144
|
+
declare function openApiRoute(config?: OpenApiConfig): RawRouteDefinition;
|
|
144
145
|
/**
|
|
145
146
|
* Create a route that serves the Scalar interactive API docs.
|
|
146
147
|
* Place in your `routes/` directory for automatic discovery.
|
|
@@ -154,7 +155,7 @@ declare function openApiRoute(config?: OpenApiConfig): questpie0.RawRouteDefinit
|
|
|
154
155
|
*/
|
|
155
156
|
declare function docsRoute(config?: OpenApiConfig & {
|
|
156
157
|
scalar?: ScalarConfig;
|
|
157
|
-
}):
|
|
158
|
+
}): RawRouteDefinition;
|
|
158
159
|
/**
|
|
159
160
|
* OpenAPI module — registers spec + docs routes.
|
|
160
161
|
*
|
|
@@ -178,8 +179,8 @@ declare const openApiModule: {
|
|
|
178
179
|
name: "questpie-openapi";
|
|
179
180
|
plugin: questpie0.CodegenPlugin;
|
|
180
181
|
routes: {
|
|
181
|
-
"openapi.json":
|
|
182
|
-
docs:
|
|
182
|
+
"openapi.json": RawRouteDefinition;
|
|
183
|
+
docs: RawRouteDefinition;
|
|
183
184
|
};
|
|
184
185
|
};
|
|
185
186
|
//#endregion
|
|
@@ -296,6 +296,82 @@ function generateAuthPaths(config) {
|
|
|
296
296
|
};
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/generator/field-schema-flags.ts
|
|
301
|
+
function buildFieldDefinitionSchemas(fieldDefinitions) {
|
|
302
|
+
if (!fieldDefinitions || typeof fieldDefinitions !== "object") return null;
|
|
303
|
+
const inputShape = {};
|
|
304
|
+
const responseShape = {};
|
|
305
|
+
for (const [fieldName, fieldDefinition] of Object.entries(fieldDefinitions)) {
|
|
306
|
+
const fd = fieldDefinition;
|
|
307
|
+
if (typeof fd.toZodSchema !== "function") continue;
|
|
308
|
+
try {
|
|
309
|
+
const schema = fd.toZodSchema();
|
|
310
|
+
if (!schema || typeof schema !== "object" || !("_def" in schema)) continue;
|
|
311
|
+
if (fd._state?.input !== false) inputShape[fieldName] = schema;
|
|
312
|
+
if (fd._state?.output !== false) responseShape[fieldName] = schema;
|
|
313
|
+
} catch {}
|
|
314
|
+
}
|
|
315
|
+
if (Object.keys(inputShape).length === 0 && Object.keys(responseShape).length === 0) return null;
|
|
316
|
+
const insertJsonSchema = z.toJSONSchema(z.object(inputShape), { unrepresentable: "any" });
|
|
317
|
+
const updateJsonSchema = z.toJSONSchema(z.object(inputShape).partial(), { unrepresentable: "any" });
|
|
318
|
+
const responseJsonSchema = z.toJSONSchema(z.object(responseShape), { unrepresentable: "any" });
|
|
319
|
+
applyRequestFieldFlags(insertJsonSchema, fieldDefinitions);
|
|
320
|
+
applyRequestFieldFlags(updateJsonSchema, fieldDefinitions);
|
|
321
|
+
applyResponseFieldFlags(responseJsonSchema, fieldDefinitions);
|
|
322
|
+
return {
|
|
323
|
+
insert: insertJsonSchema,
|
|
324
|
+
update: updateJsonSchema,
|
|
325
|
+
response: responseJsonSchema
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function applyRequestFieldFlags(schema, fieldDefinitions) {
|
|
329
|
+
applyFieldFlags(schema, fieldDefinitions, "request");
|
|
330
|
+
}
|
|
331
|
+
function applyResponseFieldFlags(schema, fieldDefinitions) {
|
|
332
|
+
applyFieldFlags(schema, fieldDefinitions, "response");
|
|
333
|
+
}
|
|
334
|
+
function applyFieldFlags(schema, fieldDefinitions, mode) {
|
|
335
|
+
if (!schema || typeof schema !== "object") return;
|
|
336
|
+
if (!fieldDefinitions || typeof fieldDefinitions !== "object") return;
|
|
337
|
+
for (const [fieldName, fieldDefinition] of Object.entries(fieldDefinitions)) {
|
|
338
|
+
const state = fieldDefinition._state;
|
|
339
|
+
if (!state) continue;
|
|
340
|
+
if (mode === "request" && state.input === false) {
|
|
341
|
+
removeProperty(schema, fieldName);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (mode === "response" && state.output === false) {
|
|
345
|
+
removeProperty(schema, fieldName);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (mode === "request" && state.output === false) markProperty(schema, fieldName, "writeOnly");
|
|
349
|
+
if (mode === "response" && state.input === false) markProperty(schema, fieldName, "readOnly");
|
|
350
|
+
const propertySchema = getProperty(schema, fieldName);
|
|
351
|
+
if (propertySchema && state.nestedFields) applyFieldFlags(propertySchema, state.nestedFields, mode);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function getProperty(schema, fieldName) {
|
|
355
|
+
if (!schema || typeof schema !== "object") return void 0;
|
|
356
|
+
return schema.properties?.[fieldName];
|
|
357
|
+
}
|
|
358
|
+
function removeProperty(schema, fieldName) {
|
|
359
|
+
if (!schema || typeof schema !== "object") return;
|
|
360
|
+
const schemaObject = schema;
|
|
361
|
+
if (!schemaObject.properties?.[fieldName]) return;
|
|
362
|
+
delete schemaObject.properties[fieldName];
|
|
363
|
+
if (Array.isArray(schemaObject.required)) schemaObject.required = schemaObject.required.filter((field) => field !== fieldName);
|
|
364
|
+
}
|
|
365
|
+
function markProperty(schema, fieldName, flag) {
|
|
366
|
+
if (!schema || typeof schema !== "object") return;
|
|
367
|
+
const properties = schema.properties;
|
|
368
|
+
if (!properties?.[fieldName] || typeof properties[fieldName] !== "object") return;
|
|
369
|
+
properties[fieldName] = {
|
|
370
|
+
...properties[fieldName],
|
|
371
|
+
[flag]: true
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
299
375
|
//#endregion
|
|
300
376
|
//#region src/generator/collections.ts
|
|
301
377
|
/**
|
|
@@ -321,9 +397,11 @@ function generateCollectionPaths(app, config) {
|
|
|
321
397
|
const documentSchemaName = `${pascalName}Document`;
|
|
322
398
|
const insertSchemaName = `${pascalName}Insert`;
|
|
323
399
|
const updateSchemaName = `${pascalName}Update`;
|
|
324
|
-
const fieldDefinitionSchema =
|
|
400
|
+
const fieldDefinitionSchema = buildFieldDefinitionSchemas(state.fieldDefinitions);
|
|
325
401
|
if (state.validation?.insertSchema) try {
|
|
326
|
-
|
|
402
|
+
const insertSchema = z.toJSONSchema(state.validation.insertSchema, { unrepresentable: "any" });
|
|
403
|
+
applyRequestFieldFlags(insertSchema, state.fieldDefinitions);
|
|
404
|
+
schemas[insertSchemaName] = insertSchema;
|
|
327
405
|
} catch {
|
|
328
406
|
schemas[insertSchemaName] = {
|
|
329
407
|
type: "object",
|
|
@@ -336,7 +414,9 @@ function generateCollectionPaths(app, config) {
|
|
|
336
414
|
description: `Insert schema for ${name}`
|
|
337
415
|
};
|
|
338
416
|
if (state.validation?.updateSchema) try {
|
|
339
|
-
|
|
417
|
+
const updateSchema = z.toJSONSchema(state.validation.updateSchema, { unrepresentable: "any" });
|
|
418
|
+
applyRequestFieldFlags(updateSchema, state.fieldDefinitions);
|
|
419
|
+
schemas[updateSchemaName] = updateSchema;
|
|
340
420
|
} catch {
|
|
341
421
|
schemas[updateSchemaName] = {
|
|
342
422
|
type: "object",
|
|
@@ -348,7 +428,7 @@ function generateCollectionPaths(app, config) {
|
|
|
348
428
|
type: "object",
|
|
349
429
|
description: `Update schema for ${name}`
|
|
350
430
|
};
|
|
351
|
-
schemas[documentSchemaName] = buildDocumentSchema(name, state, insertSchemaName);
|
|
431
|
+
schemas[documentSchemaName] = buildDocumentSchema(name, state, insertSchemaName, fieldDefinitionSchema?.response);
|
|
352
432
|
const prefix = `${basePath}/${name}`;
|
|
353
433
|
paths[prefix] = {
|
|
354
434
|
get: {
|
|
@@ -543,7 +623,7 @@ function generateCollectionPaths(app, config) {
|
|
|
543
623
|
* Build a document response schema that extends the insert schema with
|
|
544
624
|
* standard fields (id, timestamps).
|
|
545
625
|
*/
|
|
546
|
-
function buildDocumentSchema(name, state, insertSchemaName) {
|
|
626
|
+
function buildDocumentSchema(name, state, insertSchemaName, documentFieldsSchema) {
|
|
547
627
|
const properties = { id: { type: "string" } };
|
|
548
628
|
if (state.options?.timestamps !== false) {
|
|
549
629
|
properties.createdAt = {
|
|
@@ -564,32 +644,13 @@ function buildDocumentSchema(name, state, insertSchemaName) {
|
|
|
564
644
|
type: "object",
|
|
565
645
|
properties,
|
|
566
646
|
required: ["id"]
|
|
567
|
-
}, ref(insertSchemaName)],
|
|
647
|
+
}, documentFieldsSchema ?? ref(insertSchemaName)],
|
|
568
648
|
description: `${name} document`
|
|
569
649
|
};
|
|
570
650
|
}
|
|
571
651
|
function toPascalCase$1(str) {
|
|
572
652
|
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
|
|
573
653
|
}
|
|
574
|
-
function buildSchemaFromFieldDefinitions(fieldDefinitions) {
|
|
575
|
-
if (!fieldDefinitions || typeof fieldDefinitions !== "object") return null;
|
|
576
|
-
const shape = {};
|
|
577
|
-
for (const [fieldName, fieldDefinition] of Object.entries(fieldDefinitions)) {
|
|
578
|
-
const fd = fieldDefinition;
|
|
579
|
-
if (typeof fd.toZodSchema !== "function") continue;
|
|
580
|
-
try {
|
|
581
|
-
const schema = fd.toZodSchema();
|
|
582
|
-
if (schema && typeof schema === "object" && "_def" in schema) shape[fieldName] = schema;
|
|
583
|
-
} catch {}
|
|
584
|
-
}
|
|
585
|
-
if (Object.keys(shape).length === 0) return null;
|
|
586
|
-
const insertSchema = z.object(shape);
|
|
587
|
-
const updateSchema = insertSchema.partial();
|
|
588
|
-
return {
|
|
589
|
-
insert: z.toJSONSchema(insertSchema, { unrepresentable: "any" }),
|
|
590
|
-
update: z.toJSONSchema(updateSchema, { unrepresentable: "any" })
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
654
|
|
|
594
655
|
//#endregion
|
|
595
656
|
//#region src/generator/globals.ts
|
|
@@ -615,16 +676,18 @@ function generateGlobalPaths(app, config) {
|
|
|
615
676
|
const pascalName = toPascalCase(name);
|
|
616
677
|
const valueSchemaName = `${pascalName}Global`;
|
|
617
678
|
const updateSchemaName = `${pascalName}GlobalUpdate`;
|
|
618
|
-
const fieldDefinitionSchema =
|
|
679
|
+
const fieldDefinitionSchema = buildFieldDefinitionSchemas(state.fieldDefinitions);
|
|
619
680
|
if (state.validation?.updateSchema) try {
|
|
620
|
-
|
|
681
|
+
const updateSchema = z.toJSONSchema(state.validation.updateSchema, { unrepresentable: "any" });
|
|
682
|
+
applyRequestFieldFlags(updateSchema, state.fieldDefinitions);
|
|
683
|
+
schemas[updateSchemaName] = updateSchema;
|
|
621
684
|
} catch {
|
|
622
685
|
schemas[updateSchemaName] = {
|
|
623
686
|
type: "object",
|
|
624
687
|
description: `Update schema for ${name} global`
|
|
625
688
|
};
|
|
626
689
|
}
|
|
627
|
-
else if (fieldDefinitionSchema != null) schemas[updateSchemaName] = fieldDefinitionSchema;
|
|
690
|
+
else if (fieldDefinitionSchema != null) schemas[updateSchemaName] = fieldDefinitionSchema.update;
|
|
628
691
|
else schemas[updateSchemaName] = {
|
|
629
692
|
type: "object",
|
|
630
693
|
description: `Update schema for ${name} global`
|
|
@@ -645,7 +708,7 @@ function generateGlobalPaths(app, config) {
|
|
|
645
708
|
type: "object",
|
|
646
709
|
properties,
|
|
647
710
|
required: ["id"]
|
|
648
|
-
}, ref(updateSchemaName)],
|
|
711
|
+
}, fieldDefinitionSchema?.response ?? ref(updateSchemaName)],
|
|
649
712
|
description: `${name} global value`
|
|
650
713
|
};
|
|
651
714
|
const prefix = `${basePath}/globals/${name}`;
|
|
@@ -762,20 +825,6 @@ function generateGlobalPaths(app, config) {
|
|
|
762
825
|
function toPascalCase(str) {
|
|
763
826
|
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
|
|
764
827
|
}
|
|
765
|
-
function buildGlobalSchemaFromFieldDefinitions(fieldDefinitions) {
|
|
766
|
-
if (!fieldDefinitions || typeof fieldDefinitions !== "object") return null;
|
|
767
|
-
const shape = {};
|
|
768
|
-
for (const [fieldName, fieldDefinition] of Object.entries(fieldDefinitions)) {
|
|
769
|
-
const fd = fieldDefinition;
|
|
770
|
-
if (typeof fd.toZodSchema !== "function") continue;
|
|
771
|
-
try {
|
|
772
|
-
const schema = fd.toZodSchema();
|
|
773
|
-
if (schema && typeof schema === "object" && "_def" in schema) shape[fieldName] = schema;
|
|
774
|
-
} catch {}
|
|
775
|
-
}
|
|
776
|
-
if (Object.keys(shape).length === 0) return null;
|
|
777
|
-
return z.toJSONSchema(z.object(shape).partial(), { unrepresentable: "any" });
|
|
778
|
-
}
|
|
779
828
|
|
|
780
829
|
//#endregion
|
|
781
830
|
//#region src/generator/routes.ts
|
package/dist/server.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as openApiRoute, c as OpenApiSpec, i as openApiModule, l as ScalarConfig, n as generateOpenApiSpec, o as OpenApiConfig, r as openApiConfig, s as OpenApiModuleConfig, t as docsRoute } from "./server-
|
|
1
|
+
import { a as openApiRoute, c as OpenApiSpec, i as openApiModule, l as ScalarConfig, n as generateOpenApiSpec, o as OpenApiConfig, r as openApiConfig, s as OpenApiModuleConfig, t as docsRoute } from "./server-3xWD7ZeS.mjs";
|
|
2
2
|
export { OpenApiConfig, OpenApiModuleConfig, OpenApiSpec, ScalarConfig, openApiModule as default, openApiModule, docsRoute, generateOpenApiSpec, openApiConfig, openApiRoute };
|
package/dist/server.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as openApiRoute, i as openApiModule, n as generateOpenApiSpec, o as server_default, r as openApiConfig, t as docsRoute } from "./server-
|
|
1
|
+
import { a as openApiRoute, i as openApiModule, n as generateOpenApiSpec, o as server_default, r as openApiConfig, t as docsRoute } from "./server-IiX4cD55.mjs";
|
|
2
2
|
|
|
3
3
|
export { server_default as default, docsRoute, generateOpenApiSpec, openApiConfig, openApiModule, openApiRoute };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@questpie/openapi",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.26",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/questpie/questpie.git",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"check-types": "tsc --noEmit"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"questpie": "^3.5.
|
|
69
|
+
"questpie": "^3.5.4",
|
|
70
70
|
"zod": "^4.2.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|