feat(openapi): interface output + fetch-client profiles#422
Open
ALagoni97 wants to merge 1 commit into
Open
Conversation
Let OpenAPI generate plain `interface` types and an optional fetch client through two high-level profiles (`types`, `client`), the idiomatic shape for REST consumers — without forking Modelina and without changing AsyncAPI or any broker-protocol output (class mode stays the default everywhere). Engine: - payloads: `modelType: 'class' | 'interface'` (default class). Interface mode drops the marshalling + validation presets and sets Modelina interface mode. - parameters: same `modelType`. Interface mode emits a plain interface plus standalone serializers (serialize<Name>QueryParameters/PathParameters/Url), reusing the exact style/explode logic from the class path. Exposed via a new `parameterFunctions` map on the render type. HTTP client (interface mode): JSON.stringify body, response cast to the interface, URL via serialize<Name>Url, plain-interface `parameters` field, and interface + serializer imports. Broker protocols untouched. Profiles: `profile: 'types' | 'client'` on the OpenAPI config, expanded in realizeConfiguration() before validation. Distinct from the `types` preset. Tests/docs/assets: interface-mode + profile-expansion unit tests, regenerated schemas + docs, new docs/generators/profiles.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The CLI is built on Modelina, which emits class-based models with
marshal()/unmarshal()/validate()— idiomatic for the AsyncAPI/broker world, but the wrong shape for OpenAPI REST consumers, who expect plaininterfacetypes + a thin fetch client (the bar set byopenapi-typescript,orval,kubb,heyapi). Today a consumer writesnew GetV2TransactionsParameters({...})andresp.data.items[0].marshal()— non-idiomatic ceremony that makes the tool hard to pick for REST.This PR lets OpenAPI generate pure interfaces + an optional fetch client, exposed through two profiles (
types,client), without forking the engine and without changing AsyncAPI or any broker-protocol output. Class mode stays the default everywhere (fully backward compatible).How it works
types→ interface payloads + interface parameters (with standalone serializers) + headers. No channels/client.client→ everything intypesplus the HTTP fetch client.Engine
modelType: 'class' | 'interface'(defaultclass). Interface mode drops theTS_COMMON_PRESET { marshalling }+ validation presets and sets ModelinamodelType: 'interface'.modelType. Interface mode emits a plaininterface+ free functionsserialize<Name>QueryParameters/serialize<Name>PathParameters/serialize<Name>Url(replacing the classgetChannelWithParameters), reusing the exact style/explode logic from the class path. Surfaced via a newparameterFunctionsmap (mirroringheaderFunctions).HTTP client (interface mode)
JSON.stringify(payload)body, response cast to the interface, URL viaserialize<Name>Url(...), plain-interfaceparametersfield, interface + serializer imports. Broker protocols are untouched.Profiles
profile: 'types' | 'client'on the OpenAPI config, expanded inrealizeConfiguration()before validation. Distinct from the existingtypespreset (simple type aliases) — documented indocs/generators/profiles.md.Testing
schemas/*.json+ docs from Zod; addeddocs/generators/profiles.md.npm run build,npm run lint(max-warnings 0),npm test(657 tests) all green.codegen generatefor both profiles against the runtime OpenAPI spec — output type-checks undertsc --strict.Not included (with reasons)
tsc --stricton generated output instead.iterate: require Docker brokers / the platform checkout. The runtimecodegen-openapi.mjsstill uses class mode (unchanged, so broker regression gates pass); promoting hand-written interface output to a runtime check is the natural follow-up.Note for reviewers
Profiles currently prepend their generators and treat explicitly-listed
generatorsas appended overrides. If you'd prefer profiles be all-or-nothing (reject stray generators), that's a small change.🤖 Generated with Claude Code