elysia-openapi-codegen 0.1.9 → 0.2.0

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -43,7 +43,8 @@ ${props.join(`
43
43
  }`;
44
44
  }
45
45
  if (schema.anyOf || schema.oneOf) {
46
- return (schema.anyOf || schema.oneOf || []).map(resolveType).join(" | ");
46
+ const members = [...new Set((schema.anyOf || schema.oneOf || []).map(resolveType))];
47
+ return members.join(" | ");
47
48
  }
48
49
  if (schema.allOf) {
49
50
  return schema.allOf.map(resolveType).join(" & ");
@@ -120,6 +121,7 @@ ${paramProps.join(`
120
121
  for (const p of pathParamsList) {
121
122
  urlPath = urlPath.replace(`{${p.name}}`, `\${params.${p.name}}`);
122
123
  }
124
+ urlPath = urlPath.replace(/\/+$/, "");
123
125
  const qsLines = (indent) => queryParamsList.map((p) => `${indent}if (params?.${p.name} !== undefined) _qs.set('${p.name}', String(params.${p.name}));`).join(`
124
126
  `);
125
127
  if (!hasResponse) {
@@ -137,8 +139,12 @@ ${body}
137
139
  ${qsLines(" ")}
138
140
  const _qstr = _qs.toString();
139
141
  const res = await fetch(\`\${baseUrl}${urlPath}\${_qstr ? '?' + _qstr : ''}\`);` : ` const res = await fetch(\`\${baseUrl}${urlPath}\`);`;
140
- const enabledGuard = pathParamsList.length > 0 ? `
141
- enabled: ${pathParamsList.map((p) => `params.${p.name} != null`).join(" && ")},` : "";
142
+ const guardParams = [
143
+ ...pathParamsList,
144
+ ...queryParamsList.filter((p) => p.required)
145
+ ];
146
+ const enabledGuard = guardParams.length > 0 ? `
147
+ enabled: ${guardParams.map((p) => `params.${p.name} != null`).join(" && ")},` : "";
142
148
  g.hooks.push(`
143
149
  export const use${capitalize(opId)} = (
144
150
  params${hasParams ? "" : "?"}: ${paramsType},
@@ -164,6 +170,7 @@ ${fetchStatement}
164
170
  for (const p of pathParamsList) {
165
171
  urlPath = urlPath.replace(`{${p.name}}`, `\${${p.name}}`);
166
172
  }
173
+ urlPath = urlPath.replace(/\/+$/, "");
167
174
  const mutQsCode = hasQueryParams ? `
168
175
  const _qs = new URLSearchParams();
169
176
  ${queryParamsList.map((p) => ` if (${p.name} !== undefined) _qs.set('${p.name}', String(${p.name}));`).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elysia-openapi-codegen",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "author": "Khantamir mkhantamir77@gmail.com",
5
5
  "repository": {
6
6
  "type": "git",