adorn-api 1.0.15 → 1.0.17

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.
@@ -3,4 +3,6 @@
3
3
  */
4
4
  export { typeToJsonSchema, createSchemaContext } from './typeToJsonSchema.js';
5
5
  export type { JsonSchema, SchemaContext } from './types.js';
6
+ export { partitionSchemas, SchemaPartitioner, type PartitionStrategy, type SchemaGroup, type PartitioningResult, type SchemaComplexity, calculateSchemaComplexity, } from './partitioner.js';
7
+ export { generateModularOpenAPI, generateLazyOpenAPI, type SplitOpenAPIConfig, type SplitOpenAPIResult, } from './splitOpenapi.js';
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compiler/schema/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compiler/schema/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Smart OpenAPI Schema Partitioner
3
+ * Automatically partitions schemas into optimal groups based on heuristics
4
+ */
5
+ import type { Graph } from "../graph/types.js";
6
+ import type { SchemaGraph } from "../graph/schemaGraph.js";
7
+ import type { JsonSchema } from "./types.js";
8
+ /**
9
+ * Partitioning strategy options
10
+ */
11
+ export type PartitionStrategy = 'auto' | 'none' | 'controller' | 'dependency' | 'size';
12
+ /**
13
+ * Schema complexity metrics
14
+ */
15
+ export interface SchemaComplexity {
16
+ propertyCount: number;
17
+ nestedDepth: number;
18
+ refCount: number;
19
+ hasUnion: boolean;
20
+ hasIntersection: boolean;
21
+ hasEnum: boolean;
22
+ jsonSize: number;
23
+ }
24
+ /**
25
+ * A group of schemas for partitioning
26
+ */
27
+ export interface SchemaGroup {
28
+ name: string;
29
+ schemas: Map<string, JsonSchema>;
30
+ complexity: number;
31
+ dependencies: string[];
32
+ }
33
+ /**
34
+ * Partitioning result with metadata
35
+ */
36
+ export interface PartitioningResult {
37
+ shouldSplit: boolean;
38
+ strategy: PartitionStrategy;
39
+ groups: SchemaGroup[];
40
+ recommendation: string;
41
+ metrics: {
42
+ totalSchemas: number;
43
+ averageComplexity: number;
44
+ avgDependencyDensity: number;
45
+ controllerGroups: number;
46
+ };
47
+ }
48
+ /**
49
+ * Configuration for partitioning
50
+ */
51
+ export interface PartitionerConfig {
52
+ strategy?: PartitionStrategy;
53
+ threshold?: number;
54
+ maxGroupSize?: number;
55
+ complexityThreshold?: number;
56
+ verbose?: boolean;
57
+ }
58
+ /**
59
+ * Calculate complexity metrics for a schema
60
+ */
61
+ export declare function calculateSchemaComplexity(schema: JsonSchema): SchemaComplexity;
62
+ /**
63
+ * Main partitioning function with smart auto-detection
64
+ */
65
+ export declare function partitionSchemas(schemas: Map<string, JsonSchema>, graph: Graph, schemaGraph: SchemaGraph, config?: PartitionerConfig): PartitioningResult;
66
+ /**
67
+ * Export partitioner class for advanced use cases
68
+ */
69
+ export declare class SchemaPartitioner {
70
+ private config;
71
+ constructor(config?: PartitionerConfig);
72
+ /**
73
+ * Partition schemas with the configured strategy
74
+ */
75
+ partition(schemas: Map<string, JsonSchema>, graph: Graph, schemaGraph: SchemaGraph): PartitioningResult;
76
+ /**
77
+ * Set the partitioning strategy
78
+ */
79
+ setStrategy(strategy: PartitionStrategy): void;
80
+ /**
81
+ * Get current configuration
82
+ */
83
+ getConfig(): Readonly<Required<PartitionerConfig>>;
84
+ }
85
+ //# sourceMappingURL=partitioner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitioner.d.ts","sourceRoot":"","sources":["../../../src/compiler/schema/partitioner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,GACN,YAAY,GACZ,YAAY,GACZ,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE;QACP,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,oBAAoB,EAAE,MAAM,CAAC;QAC7B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAaD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,GAAG,gBAAgB,CAqD9E;AAiTD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAChC,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,iBAAsB,GAC7B,kBAAkB,CA4EpB;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAA8B;gBAEhC,MAAM,GAAE,iBAAsB;IAI1C;;OAEG;IACH,SAAS,CACP,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAChC,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,GACvB,kBAAkB;IAIrB;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAI9C;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;CAGnD"}
@@ -0,0 +1,39 @@
1
+ import type { OpenAPI31 } from "./openapi.js";
2
+ import type { PartitioningResult } from "./partitioner.js";
3
+ /**
4
+ * Configuration for modular OpenAPI generation
5
+ */
6
+ export interface SplitOpenAPIConfig {
7
+ outputDir: string;
8
+ schemasDir?: string;
9
+ createIndexFile?: boolean;
10
+ prettyPrint?: boolean;
11
+ }
12
+ /**
13
+ * Result of modular OpenAPI generation
14
+ */
15
+ export interface SplitOpenAPIResult {
16
+ mainSpec: string;
17
+ schemaFiles: string[];
18
+ indexFile?: string;
19
+ totalSize: number;
20
+ splitEnabled: boolean;
21
+ }
22
+ /**
23
+ * Generate modular OpenAPI specification with split schema files
24
+ */
25
+ export declare function generateModularOpenAPI(openapi: OpenAPI31, partitioning: PartitioningResult, config: SplitOpenAPIConfig): SplitOpenAPIResult;
26
+ /**
27
+ * Generate a lightweight OpenAPI spec that references external files
28
+ * This is useful for Swagger UI lazy loading
29
+ */
30
+ export declare function generateLazyOpenAPI(openapi: OpenAPI31, partitioning: PartitioningResult): OpenAPI31;
31
+ /**
32
+ * Get the file path for a schema group
33
+ */
34
+ export declare function getSchemaFilePath(groupName: string, outputDir: string, schemasDir?: string): string;
35
+ /**
36
+ * Check if a schema exists in a specific file
37
+ */
38
+ export declare function schemaExistsInFile(schemaName: string, outputDir: string, groupName: string): boolean;
39
+ //# sourceMappingURL=splitOpenapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitOpenapi.d.ts","sourceRoot":"","sources":["../../../src/compiler/schema/splitOpenapi.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,kBAAkB,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;CACvB;AAsHD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,SAAS,EAClB,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,kBAAkB,GACzB,kBAAkB,CA0EpB;AA0CD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,EAClB,YAAY,EAAE,kBAAkB,GAC/B,SAAS,CAuBX;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,MAAkB,GAC7B,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAaT"}
package/dist/express.cjs CHANGED
@@ -970,25 +970,78 @@ var import_express2 = require("express");
970
970
  var import_node_fs2 = require("fs");
971
971
  var import_node_path3 = require("path");
972
972
  var import_swagger_ui_express = __toESM(require("swagger-ui-express"), 1);
973
+ var DEFAULT_SWAGGER_UI_OPTIONS = {
974
+ docExpansion: "none",
975
+ // Collapse all by default for better performance
976
+ filter: true,
977
+ // Show filter input
978
+ showRequestDuration: true,
979
+ // Show request duration
980
+ displayRequestDuration: true,
981
+ operationsSorter: "alpha",
982
+ // Sort operations alphabetically
983
+ tagsSorter: "alpha",
984
+ // Sort tags alphabetically
985
+ persistAuthorization: true
986
+ // Persist authorization across reloads
987
+ };
988
+ function isSplitMode(openapiPath) {
989
+ const schemasDir = (0, import_node_path3.join)(openapiPath, "..", "schemas");
990
+ return (0, import_node_fs2.existsSync)(schemasDir);
991
+ }
992
+ function createSchemaRouter(artifactsDir) {
993
+ const router = (0, import_express2.Router)();
994
+ const schemasDir = (0, import_node_path3.isAbsolute)(artifactsDir) ? (0, import_node_path3.resolve)(artifactsDir, "schemas") : (0, import_node_path3.resolve)(process.cwd(), artifactsDir, "schemas");
995
+ router.get("/schemas/:filename", (req, res, next) => {
996
+ const { filename } = req.params;
997
+ const filePath = (0, import_node_path3.resolve)(schemasDir, filename);
998
+ if (!(0, import_node_fs2.existsSync)(filePath)) {
999
+ return res.status(404).json({ error: "Schema file not found" });
1000
+ }
1001
+ try {
1002
+ const content = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
1003
+ res.setHeader("Content-Type", "application/json");
1004
+ res.send(content);
1005
+ } catch (error) {
1006
+ next(error);
1007
+ }
1008
+ });
1009
+ return router;
1010
+ }
973
1011
  function setupSwagger(options = {}) {
974
1012
  const {
975
1013
  artifactsDir = ".adorn",
976
1014
  jsonPath = "/docs/openapi.json",
977
1015
  uiPath = "/docs",
978
- swaggerOptions = {}
1016
+ swaggerOptions = {},
1017
+ swaggerUiOptions = {}
979
1018
  } = options;
980
1019
  const router = (0, import_express2.Router)();
1020
+ const openApiPath = (0, import_node_path3.isAbsolute)(artifactsDir) ? (0, import_node_path3.resolve)(artifactsDir, "openapi.json") : (0, import_node_path3.resolve)(process.cwd(), artifactsDir, "openapi.json");
1021
+ const splitMode = isSplitMode(openApiPath);
981
1022
  router.get(jsonPath, (req, res) => {
982
- const openApiPath = (0, import_node_path3.isAbsolute)(artifactsDir) ? (0, import_node_path3.resolve)(artifactsDir, "openapi.json") : (0, import_node_path3.resolve)(process.cwd(), artifactsDir, "openapi.json");
1023
+ if (!(0, import_node_fs2.existsSync)(openApiPath)) {
1024
+ return res.status(404).json({ error: "OpenAPI spec not found" });
1025
+ }
983
1026
  const content = (0, import_node_fs2.readFileSync)(openApiPath, "utf-8");
984
1027
  res.setHeader("Content-Type", "application/json");
985
1028
  res.send(content);
986
1029
  });
1030
+ if (splitMode) {
1031
+ router.use("/schemas", createSchemaRouter(artifactsDir));
1032
+ }
1033
+ const mergedSwaggerOptions = {
1034
+ ...DEFAULT_SWAGGER_UI_OPTIONS,
1035
+ ...swaggerOptions
1036
+ };
987
1037
  router.use(uiPath, import_swagger_ui_express.default.serve, import_swagger_ui_express.default.setup(null, {
988
1038
  swaggerOptions: {
989
1039
  url: jsonPath,
990
- ...swaggerOptions
991
- }
1040
+ ...mergedSwaggerOptions,
1041
+ // Add support for external $ref references in split mode
1042
+ supportedSubmitMethods: ["get", "put", "post", "delete", "options", "head", "patch"]
1043
+ },
1044
+ ...swaggerUiOptions
992
1045
  }));
993
1046
  return router;
994
1047
  }
@@ -1079,8 +1132,10 @@ function bootstrap(options) {
1079
1132
  jsonPath: swaggerJsonPath,
1080
1133
  uiPath: swaggerPath,
1081
1134
  swaggerOptions: {
1082
- servers: [{ url: serverUrl }]
1083
- }
1135
+ servers: [{ url: serverUrl }],
1136
+ ...options.swaggerOptions
1137
+ },
1138
+ swaggerUiOptions: options.swaggerUiOptions
1084
1139
  })
1085
1140
  );
1086
1141
  }