@pikku/openapi-parser 0.12.7 → 0.12.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pikku/openapi-parser
2
2
 
3
+ ## 0.12.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 94ceecd: Fix duplicate property error in generated code when body and path/query/header params share the same name. Skips the body property with a warning.
8
+
3
9
  ## 0.12.7
4
10
 
5
11
  ### Patch Changes
package/dist/codegen.js CHANGED
@@ -179,11 +179,21 @@ function buildInputSchema(parsed, ctx) {
179
179
  }
180
180
  if (parsed.requestBody) {
181
181
  if (parsed.requestBody.properties) {
182
+ const paramNames = new Set([
183
+ ...parsed.pathParams.map((p) => p.name),
184
+ ...parsed.queryParams.map((p) => p.name),
185
+ ...parsed.headerParams.map((p) => p.name),
186
+ ]);
182
187
  const requiredSet = new Set(parsed.requestBody.required ?? []);
183
188
  for (const [key, propSchema] of Object.entries(parsed.requestBody.properties)) {
184
189
  // Skip readOnly properties from input
185
190
  if (propSchema.readOnly)
186
191
  continue;
192
+ // Skip body properties that collide with path/query/header params
193
+ if (paramNames.has(key)) {
194
+ console.warn(`[openapi] Skipping body property '${key}' — collides with path/query/header param`);
195
+ continue;
196
+ }
187
197
  const isOptional = !requiredSet.has(key);
188
198
  const zodCode = schemaToZod(propSchema, ctx, { optional: isOptional });
189
199
  props.push(` ${safeKey(key)}: ${zodCode},`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/openapi-parser",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "description": "OpenAPI spec parser and code generator for Pikku",
5
5
  "author": "yasser.fadl@gmail.com",
6
6
  "license": "MIT",
package/src/codegen.ts CHANGED
@@ -297,12 +297,24 @@ function buildInputSchema(
297
297
 
298
298
  if (parsed.requestBody) {
299
299
  if (parsed.requestBody.properties) {
300
+ const paramNames = new Set([
301
+ ...parsed.pathParams.map((p) => p.name),
302
+ ...parsed.queryParams.map((p) => p.name),
303
+ ...parsed.headerParams.map((p) => p.name),
304
+ ])
300
305
  const requiredSet = new Set(parsed.requestBody.required ?? [])
301
306
  for (const [key, propSchema] of Object.entries(
302
307
  parsed.requestBody.properties
303
308
  )) {
304
309
  // Skip readOnly properties from input
305
310
  if (propSchema.readOnly) continue
311
+ // Skip body properties that collide with path/query/header params
312
+ if (paramNames.has(key)) {
313
+ console.warn(
314
+ `[openapi] Skipping body property '${key}' — collides with path/query/header param`
315
+ )
316
+ continue
317
+ }
306
318
  const isOptional = !requiredSet.has(key)
307
319
  const zodCode = schemaToZod(propSchema, ctx, { optional: isOptional })
308
320
  props.push(` ${safeKey(key)}: ${zodCode},`)