@icib.dev/api-client 1.1.1 → 1.1.2

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.
@@ -92,7 +92,11 @@ function getDefinitions(doc) {
92
92
  function getPaths(doc) {
93
93
  return doc.paths ?? {};
94
94
  }
95
- /** Extract response schema from OpenAPI 2.0 (schema) or OpenAPI 3.0 (content) */
95
+ /**
96
+ * Extract response schema. Compatible with:
97
+ * - OpenAPI 2.0: response.schema
98
+ * - OpenAPI 3.0: response.content['application/json'].schema
99
+ */
96
100
  function getResponseSchema(response) {
97
101
  if (!response || typeof response !== "object")
98
102
  return undefined;
@@ -111,6 +115,23 @@ function getResponseSchema(response) {
111
115
  }
112
116
  return undefined;
113
117
  }
118
+ /**
119
+ * Extract request body schema from OpenAPI 3.0 requestBody.content.
120
+ * OpenAPI 2.0 uses parameters with in: "body" (handled separately in extractOperations).
121
+ */
122
+ function getRequestBodySchema(requestBody) {
123
+ if (!requestBody || typeof requestBody !== "object")
124
+ return undefined;
125
+ const rb = requestBody;
126
+ const content = rb.content;
127
+ if (content) {
128
+ const jsonContent = content["application/json"] ??
129
+ content["*/*"] ??
130
+ Object.values(content)[0];
131
+ return jsonContent?.schema;
132
+ }
133
+ return undefined;
134
+ }
114
135
  function schemaToTsType(schema, definitions, refsSeen = new Set()) {
115
136
  if (!schema)
116
137
  return "unknown";
@@ -269,6 +290,29 @@ function extractOperations(paths, definitions) {
269
290
  };
270
291
  }
271
292
  }
293
+ // OpenAPI 3.0: body in requestBody (OAS 2.0 uses parameters in: "body" above)
294
+ if (!bodyParam && op.requestBody) {
295
+ const bodySchema = getRequestBodySchema(op.requestBody);
296
+ if (bodySchema) {
297
+ const propertyDescriptions = {};
298
+ if (bodySchema.properties) {
299
+ for (const [propName, propSchema] of Object.entries(bodySchema.properties)) {
300
+ const desc = propSchema
301
+ .description ??
302
+ propSchema.title;
303
+ if (desc)
304
+ propertyDescriptions[propName] = desc;
305
+ }
306
+ }
307
+ bodyParam = {
308
+ name: "data",
309
+ schema: bodySchema,
310
+ propertyDescriptions: Object.keys(propertyDescriptions).length > 0
311
+ ? propertyDescriptions
312
+ : undefined,
313
+ };
314
+ }
315
+ }
272
316
  const successResponse = op.responses?.["200"] ?? op.responses?.["201"];
273
317
  const respSchema = getResponseSchema(successResponse);
274
318
  const respDesc = successResponse?.description ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icib.dev/api-client",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Generator for strictly-typed TypeScript API clients from OpenAPI specs",
5
5
  "type": "module",
6
6
  "bin": {