Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Fix form-urlencoded request body code generation#6

Merged
mromaszewicz merged 1 commit intomainfrom
fix/issue-2-form-urlencoded-body
Feb 8, 2026
Merged

Fix form-urlencoded request body code generation#6
mromaszewicz merged 1 commit intomainfrom
fix/issue-2-form-urlencoded-body

Conversation

@mromaszewicz
Copy link
Copy Markdown
Member

Operations with application/x-www-form-urlencoded request bodies produced uncompilable code: the SimpleClient referenced undefined typed body structs and methods because the code generator only recognized application/json content types.

This change introduces a config-driven ContentTypeMatcher that determines which content types get typed request body methods, replacing the hard-coded IsJSON checks. form-urlencoded is now included in the default content-type list alongside JSON.

For form-encoded bodies, serialization uses a new marshalForm helper (reflection-based, using json struct tags) instead of json.Marshal, avoiding a JSON round-trip that would produce incorrect form encoding.

Key changes:

  • Replace RequestBodyDescriptor.IsJSON with GenerateTyped (config-driven) and IsFormEncoded (content-type flag)
  • Add ContentTypeMatcher to operationGatherer and all Gather*Operations call sites
  • Add DefaultTypedBody/HasTypedBody to OperationDescriptor so the SimpleClient template picks the correct typed body
  • Add marshalForm/marshalFormImpl helper template for struct-to-url.Values serialization
  • Update client, initiator, and simple-client templates to branch on IsFormEncoded vs JSON for body serialization

Closes #2

Operations with application/x-www-form-urlencoded request bodies
produced uncompilable code: the SimpleClient referenced undefined
typed body structs and methods because the code generator only
recognized application/json content types.

This change introduces a config-driven ContentTypeMatcher that
determines which content types get typed request body methods,
replacing the hard-coded IsJSON checks. form-urlencoded is now
included in the default content-type list alongside JSON.

For form-encoded bodies, serialization uses a new marshalForm
helper (reflection-based, using json struct tags) instead of
json.Marshal, avoiding a JSON round-trip that would produce
incorrect form encoding.

Key changes:
- Replace RequestBodyDescriptor.IsJSON with GenerateTyped (config-driven)
  and IsFormEncoded (content-type flag)
- Add ContentTypeMatcher to operationGatherer and all Gather*Operations
  call sites
- Add DefaultTypedBody/HasTypedBody to OperationDescriptor so the
  SimpleClient template picks the correct typed body
- Add marshalForm/marshalFormImpl helper template for struct-to-url.Values
  serialization
- Update client, initiator, and simple-client templates to branch on
  IsFormEncoded vs JSON for body serialization

Closes #2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mromaszewicz mromaszewicz merged commit 32c2089 into main Feb 8, 2026
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI 3.1 simple-client generation application/x-www-form-urlencoded request body error

1 participant