@treatwell/moleculer-essentials 1.2.1 → 1.2.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.
package/dist/index.cjs CHANGED
@@ -224,13 +224,21 @@ function createOperationFromAlias(alias, extractor, url) {
224
224
  const responses = {};
225
225
  if (openapi.responses) {
226
226
  for (const [key, val] of Object.entries(openapi.responses)) {
227
- responses[key] = val;
228
- const content = val.content?.["application/json"];
229
- if (content && "zodInstance" in content && typeof content.zodInstance === "function") {
230
- content.schema = index.zodToOpenAPISchema(content.zodInstance(), extractor);
231
- } else if (content?.schema) {
232
- content.schema = extractor.extract(content.schema);
227
+ const res = { ...val };
228
+ if ("content" in res) {
229
+ res.content = { ...res.content };
230
+ let content = res.content["application/json"];
231
+ if (content) {
232
+ res.content["application/json"] = { ...content };
233
+ content = res.content["application/json"];
234
+ }
235
+ if (content && "zodInstance" in content && typeof content.zodInstance === "function") {
236
+ content.schema = index.zodToOpenAPISchema(content.zodInstance(), extractor);
237
+ } else if (content?.schema) {
238
+ content.schema = extractor.extract(content.schema);
239
+ }
233
240
  }
241
+ responses[key] = res;
234
242
  }
235
243
  }
236
244
  return {
@@ -332,8 +340,13 @@ function createOperationFromZodParams(params, pathParams, alias, extractor) {
332
340
  Object.fromEntries(parameters.map((p) => [p.name, true]))
333
341
  );
334
342
  }
335
- if (alias.action.bodySchemaRefName) {
336
- zodBody = zodBody.meta({ id: alias.action.bodySchemaRefName });
343
+ const { bodySchemaRefName } = alias.action;
344
+ if (bodySchemaRefName) {
345
+ if (v4.z.globalRegistry._idmap.has(bodySchemaRefName)) {
346
+ zodBody = v4.z.globalRegistry._idmap.get(bodySchemaRefName);
347
+ } else {
348
+ zodBody = zodBody.meta({ id: bodySchemaRefName });
349
+ }
337
350
  }
338
351
  requestBody = {
339
352
  required: true,
package/dist/index.mjs CHANGED
@@ -224,13 +224,21 @@ function createOperationFromAlias(alias, extractor, url) {
224
224
  const responses = {};
225
225
  if (openapi.responses) {
226
226
  for (const [key, val] of Object.entries(openapi.responses)) {
227
- responses[key] = val;
228
- const content = val.content?.["application/json"];
229
- if (content && "zodInstance" in content && typeof content.zodInstance === "function") {
230
- content.schema = zodToOpenAPISchema(content.zodInstance(), extractor);
231
- } else if (content?.schema) {
232
- content.schema = extractor.extract(content.schema);
227
+ const res = { ...val };
228
+ if ("content" in res) {
229
+ res.content = { ...res.content };
230
+ let content = res.content["application/json"];
231
+ if (content) {
232
+ res.content["application/json"] = { ...content };
233
+ content = res.content["application/json"];
234
+ }
235
+ if (content && "zodInstance" in content && typeof content.zodInstance === "function") {
236
+ content.schema = zodToOpenAPISchema(content.zodInstance(), extractor);
237
+ } else if (content?.schema) {
238
+ content.schema = extractor.extract(content.schema);
239
+ }
233
240
  }
241
+ responses[key] = res;
234
242
  }
235
243
  }
236
244
  return {
@@ -332,8 +340,13 @@ function createOperationFromZodParams(params, pathParams, alias, extractor) {
332
340
  Object.fromEntries(parameters.map((p) => [p.name, true]))
333
341
  );
334
342
  }
335
- if (alias.action.bodySchemaRefName) {
336
- zodBody = zodBody.meta({ id: alias.action.bodySchemaRefName });
343
+ const { bodySchemaRefName } = alias.action;
344
+ if (bodySchemaRefName) {
345
+ if (z.globalRegistry._idmap.has(bodySchemaRefName)) {
346
+ zodBody = z.globalRegistry._idmap.get(bodySchemaRefName);
347
+ } else {
348
+ zodBody = zodBody.meta({ id: bodySchemaRefName });
349
+ }
337
350
  }
338
351
  requestBody = {
339
352
  required: true,
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "type": "git",
7
7
  "url": "https://github.com/treatwell/moleculer-essentials"
8
8
  },
9
- "version": "1.2.1",
9
+ "version": "1.2.2",
10
10
  "main": "./dist/index.cjs",
11
11
  "module": "./dist/index.mjs",
12
12
  "types": "./dist/index.d.cts",