keryx 0.12.0 → 0.12.1

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.
@@ -63,7 +63,20 @@ export class Swagger implements Action {
63
63
 
64
64
  async run() {
65
65
  const paths: Record<string, any> = {};
66
- const components: { schemas: Record<string, any> } = { schemas: {} };
66
+ const components: {
67
+ schemas: Record<string, any>;
68
+ securitySchemes?: Record<string, any>;
69
+ } = {
70
+ schemas: {},
71
+ securitySchemes: {
72
+ sessionCookie: {
73
+ type: "apiKey",
74
+ in: "cookie",
75
+ name: config.session.cookieName,
76
+ description: "Session cookie set by session:create",
77
+ },
78
+ },
79
+ };
67
80
 
68
81
  for (const action of api.actions.actions) {
69
82
  if (!action.web?.route || !action.web?.method) continue;
@@ -81,19 +94,63 @@ export class Swagger implements Action {
81
94
  const description = action.description;
82
95
 
83
96
  // Extract path parameters from the original route
84
- const pathParams: any[] = [];
97
+ const parameters: any[] = [];
85
98
  const pathParamMatches = action.web.route.match(/:\w+/g) || [];
99
+ const pathParamNames = new Set<string>();
100
+
101
+ // Pre-compute Zod JSON Schema for enriching path param types
102
+ let zodProperties: Record<string, any> = {};
103
+ let zodDescriptions: Record<string, string> = {};
104
+ if (action.inputs && typeof action.inputs.parse === "function") {
105
+ const jsonSchema = z.toJSONSchema(action.inputs, {
106
+ io: "input",
107
+ unrepresentable: "any",
108
+ }) as any;
109
+ zodProperties = jsonSchema.properties ?? {};
110
+ for (const [name, propSchema] of Object.entries<any>(zodProperties)) {
111
+ if (propSchema.description) {
112
+ zodDescriptions[name] = propSchema.description;
113
+ }
114
+ }
115
+ }
116
+
86
117
  for (const paramMatch of pathParamMatches) {
87
118
  const paramName = paramMatch.slice(1); // Remove the colon
88
- pathParams.push({
119
+ pathParamNames.add(paramName);
120
+ parameters.push({
89
121
  name: paramName,
90
122
  in: "path",
91
123
  required: true,
92
124
  schema: { type: "string" },
93
- description: `The ${paramName} parameter`,
125
+ description:
126
+ zodDescriptions[paramName] ?? `The ${paramName} parameter`,
94
127
  });
95
128
  }
96
129
 
130
+ // For GET/HEAD, convert remaining Zod inputs into query parameters
131
+ if (
132
+ (method === "get" || method === "head") &&
133
+ Object.keys(zodProperties).length > 0
134
+ ) {
135
+ const fullSchema = z.toJSONSchema(action.inputs!, {
136
+ io: "input",
137
+ unrepresentable: "any",
138
+ }) as any;
139
+ const requiredFields = new Set<string>(fullSchema.required ?? []);
140
+ for (const [name, propSchema] of Object.entries<any>(zodProperties)) {
141
+ if (pathParamNames.has(name)) continue; // already a path param
142
+ parameters.push({
143
+ name,
144
+ in: "query",
145
+ required: requiredFields.has(name),
146
+ schema: propSchema,
147
+ ...(propSchema.description
148
+ ? { description: propSchema.description }
149
+ : {}),
150
+ });
151
+ }
152
+ }
153
+
97
154
  // Build requestBody if Zod inputs exist and method supports body
98
155
  let requestBody: any = undefined;
99
156
  if (
@@ -145,7 +202,7 @@ export class Swagger implements Action {
145
202
  operationId,
146
203
  summary,
147
204
  ...(description ? { description } : {}),
148
- ...(pathParams.length > 0 ? { parameters: pathParams } : {}),
205
+ ...(parameters.length > 0 ? { parameters } : {}),
149
206
  ...(requestBody ? { requestBody } : {}),
150
207
  responses,
151
208
  tags: [tag],
@@ -168,6 +225,7 @@ export class Swagger implements Action {
168
225
  ],
169
226
  paths,
170
227
  components,
228
+ security: [{ sessionCookie: [] }],
171
229
  };
172
230
  return document;
173
231
  }
package/classes/Action.ts CHANGED
@@ -109,7 +109,6 @@ export abstract class Action {
109
109
  frequency?: number;
110
110
  queue: string;
111
111
  };
112
-
113
112
  constructor(args: ActionConstructorInputs) {
114
113
  this.name = args.name;
115
114
  this.description = args.description ?? `An Action: ${this.name}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keryx",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "license": "MIT",