Skip to content

[codegen] Handle @All routes before generating public contracts #668

Description

@kang-heewon

Priority

P1

Problem

Croco exposes an @All REST decorator, but the generated-contract layer does not define how ALL routes should be represented. The HTTP transport registers all routes successfully, openapi-spec rejects ALL, and rpc-codegen would emit method: 'ALL', which is not a concrete request method for generated clients.

Evidence

  • packages/protocols-rest/src/libs/decorators/HttpMethod.ts exports All = createMethodDecorator(HttpMethodEnum.ALL).
  • packages/protocols-rest/src/tests/decorators/Route.spec.ts verifies that @All() registers HttpMethod.ALL.
  • packages/transports-http/src/libs/CrocoRouteRegistrar.ts handles case "all" with this.hono.all(route.path, honoHandler).
  • packages/openapi-spec/src/libs/emitOpenAPI.ts limits methods to get, post, put, delete, patch, head, options, and trace, then throws Unsupported HTTP method: ${method} for anything else.
  • packages/rpc-codegen/src/libs/generate.ts directly emits method: '${route.httpMethod.toUpperCase()}', so an ALL route becomes fetch(..., { method: 'ALL' }).
  • OpenAPI Path Item fixed fields enumerate concrete operations such as get, put, post, delete, options, head, patch, and trace; there is no all operation field: https://spec.openapis.org/oas/v3.1.2.html#path-item-object

Desired outcome

Croco makes @All behavior explicit at codegen boundaries instead of generating invalid clients or failing with a generic unsupported-method error.

Proposed implementation path

  1. Decide the contract for generated surfaces: either exclude @All routes with a clear diagnostic, or expand them into concrete methods where that is safe.
  2. Apply the same policy in openapi-spec and rpc-codegen so generated docs and clients agree.
  3. Add tests covering a controller with @All() for OpenAPI and RPC generation.
  4. If routes are rejected, include controller/method/path in the error so users can resolve it without debugging metadata.

Acceptance criteria

  • emitOpenAPI no longer fails with an unqualified Unsupported HTTP method: ALL for @All routes.
  • rpc-codegen never emits method: 'ALL' in generated fetch clients.
  • The chosen behavior is documented by tests in both generated-contract packages.
  • HTTP runtime @All behavior remains unchanged in transports-http.

Validation

  • pnpm test --filter=@croco/openapi-spec
  • pnpm test --filter=@croco/rpc-codegen
  • pnpm typecheck --filter=@croco/openapi-spec --filter=@croco/rpc-codegen

Scope boundaries

  • This does not require removing the @All decorator.
  • This does not require adding OpenAPI vendor extensions unless the chosen policy needs them.
  • This does not redefine route precedence in the HTTP transport.

Metadata

Metadata

Assignees

Labels

P1Priority 1 issuebugSomething isn't workingtech-debtTechnical debt

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions