[PR #2652] fix: invalid openapi spec due to duplicate parameters #10392

Closed
opened 2026-02-16 18:15:01 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2652

State: closed
Merged: No


Issues resolved:

  1. opencode generate outputs an openapi spec with duplicated "directory" parameters on request bodies. I've added code to de-duplicate request parameters.
  2. the use of positive() in zod schemas leads to a spec that can't be used by code generation designed for openapi 3.0. I'd have left it alone but the one-line change from .positive() to .min(1) just felt so semantically equivalent that I thought I'd propose it for now until oapi-codegen is ready for openapi 3.1.

Discussion

1. Duplicate Parameter Definitions

When PR #2360 added support for multiple opencode instances via a global directory query parameter, it inadvertently caused duplicate parameter
definitions in the OpenAPI spec. The hono-openapi library duplicates global middleware validators - once for the base route and once more for each
additional validator on that route.

Solution: Added post-processing to remove ALL duplicate parameters (same name + location), not just directory. This ensures OpenAPI spec compliance
since the spec explicitly forbids duplicate parameters.

2. OpenAPI 3.0 Compatibility

The Zod schema .positive() generates "exclusiveMinimum": 0 which is valid in OpenAPI 3.1 (uses JSON Schema 2020-12) but incompatible with OpenAPI 3.0
tools that expect exclusiveMinimum to be a boolean.

Solution: Changed z.number().int().positive() to z.number().int().min(1) which generates "minimum": 1 instead. Semantically equivalent for integers
but compatible with both OpenAPI 3.0 and 3.1.

Changes

  1. packages/opencode/src/server/server.ts: Added generic parameter deduplication in OpenAPI generation
  2. packages/opencode/src/config/config.ts: Changed .positive() to .min(1) for OpenAPI 3.0 compatibility

Testing

TypeScript compilation passes
All existing tests maintain same pass/fail status (no regressions)
Generated OpenAPI spec validates with 0 errors using vacuum lint
No duplicate parameters in generated spec
Compatible with oapi-codegen and other OpenAPI 3.0 tools

References

• hono-openapi issue: https://github.com/rhinobase/hono-openapi/issues/71
• Original PR that added global directory parameter: #2360

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2652 **State:** closed **Merged:** No --- Issues resolved: 1. `opencode generate` outputs an openapi spec with duplicated "directory" parameters on request bodies. I've added code to de-duplicate request parameters. 2. the use of `positive()` in zod schemas leads to a spec that can't be used by code generation designed for openapi 3.0. I'd have left it alone but the one-line change from `.positive()` to `.min(1)` just felt so semantically equivalent that I thought I'd propose it for now until `oapi-codegen` is ready for openapi 3.1. ## Discussion ### 1. Duplicate Parameter Definitions When PR #2360 added support for multiple opencode instances via a global directory query parameter, it inadvertently caused duplicate parameter definitions in the OpenAPI spec. The hono-openapi library duplicates global middleware validators - once for the base route and once more for each additional validator on that route. Solution: Added post-processing to remove ALL duplicate parameters (same name + location), not just directory. This ensures OpenAPI spec compliance since the spec explicitly forbids duplicate parameters. ### 2. OpenAPI 3.0 Compatibility The Zod schema .positive() generates "exclusiveMinimum": 0 which is valid in OpenAPI 3.1 (uses JSON Schema 2020-12) but incompatible with OpenAPI 3.0 tools that expect exclusiveMinimum to be a boolean. Solution: Changed z.number().int().positive() to z.number().int().min(1) which generates "minimum": 1 instead. Semantically equivalent for integers but compatible with both OpenAPI 3.0 and 3.1. ## Changes 1. packages/opencode/src/server/server.ts: Added generic parameter deduplication in OpenAPI generation 2. packages/opencode/src/config/config.ts: Changed .positive() to .min(1) for OpenAPI 3.0 compatibility ## Testing • ✅ TypeScript compilation passes • ✅ All existing tests maintain same pass/fail status (no regressions) • ✅ Generated OpenAPI spec validates with 0 errors using vacuum lint • ✅ No duplicate parameters in generated spec • ✅ Compatible with oapi-codegen and other OpenAPI 3.0 tools ## References • hono-openapi issue: https://github.com/rhinobase/hono-openapi/issues/71 • Original PR that added global directory parameter: #2360
yindo added the pull-request label 2026-02-16 18:15:01 -05:00
yindo closed this issue 2026-02-16 18:15:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10392