Skip to content

feat(openapi): convert parameter models to plain objects with serialize/parse functions#409

Open
ALagoni97 wants to merge 6 commits into
mainfrom
feat/plain-object-openapi-parameters
Open

feat(openapi): convert parameter models to plain objects with serialize/parse functions#409
ALagoni97 wants to merge 6 commits into
mainfrom
feat/plain-object-openapi-parameters

Conversation

@ALagoni97

Copy link
Copy Markdown
Contributor

Summary

  • OpenAPI parameter models are now generated as TypeScript interfaces instead of classes, with two accompanying standalone functions per model: serializeXxxUrl(parameters, basePath): string and parseXxxFromUrl(url, basePath): XxxType
  • buildUrlWithParameters in http/common-types.ts now accepts a serializeFn callback instead of a generic with a structural constraint, decoupling the URL builder from the parameter shape
  • Import statements for parameter-bearing channels are updated to include the serialize/parse function names alongside the interface
  • All OpenAPI runtime test files and snapshots updated to match the new output

Why plain objects?

Class instances carry runtime overhead (prototype chain, new keyword, instanceof checks) that is unnecessary for parameter objects which are pure data bags. Interfaces + standalone functions are:

  • Tree-shakeable: bundlers can drop unused serialize/parse functions; a class always pulls its methods in
  • Simpler to construct: callers pass a plain object literal — no new FindPetsByStatusAndCategoryParameters(...) required
  • Easier to test: no need to instantiate; just pass { status: 'available' } directly

Possibility of extending to AsyncAPI

AsyncAPI parameters currently remain class-based (getChannelWithParameters, createFromChannel static methods). The same refactor could be applied there:

  • Each AsyncAPI parameter class would become an interface + serializeXxxChannel(parameters): string / parseXxxFromChannel(channel): XxxType pair
  • The NATS/AMQP/Kafka/MQTT/WebSocket/EventSource channel renderers in src/codegen/generators/typescript/channels/protocols/ each have their own addParametersToDependencies wiring that would need updating (analogous to what was done for HTTP here)
  • The AsyncAPI runtime test suite (test/runtime/typescript/test/parameters.spec.ts, AsyncAPI section) would need the class-based assertions replaced with interface + function assertions

The main reason it was left out of this PR was scope — the HTTP path was self-contained and testable in isolation. The AsyncAPI side touches more protocol renderers and would be a good follow-up PR.

Test plan

  • npm test — 646/647 tests pass (1 pre-existing skip), all 78 snapshots clean
  • npm run build — TypeScript compilation succeeds
  • npm run generate:assets — asset generation succeeds
  • npm run runtime:typescript:generate — runtime code regenerated and matches committed files

🤖 Generated with Claude Code

… with standalone serialize/parse functions

OpenAPI parameters are now generated as TypeScript interfaces with `serializeXxxUrl`/`parseXxxFromUrl`
standalone functions instead of class instances, enabling tree-shaking and simpler usage at call sites.
AsyncAPI parameters remain class-based (out of scope).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ALagoni97 ALagoni97 requested a review from jonaslagoni as a code owner July 14, 2026 11:54
@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-codegen-project Ready Ready Preview, Comment Jul 14, 2026 4:17pm
the-codegen-project-mcp Ready Ready Preview, Comment Jul 14, 2026 4:17pm

…satisfy sonar complexity

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lient

OpenAPI parameters export a standalone serializeXUrl function; AsyncAPI
parameters use the class-based getChannelWithParameters method. Add
hasSerializeUrl flag to RenderHttpParameters so the channel generator
emits the right call at each site, and regenerate the affected fixture.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…erateFunctionImplementation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant